|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of RussianPost SDK package. |
|
5
|
|
|
* |
|
6
|
|
|
* © Appwilio (http://appwilio.com), greabock (https://github.com/greabock), JhaoDa (https://github.com/jhaoda) |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Appwilio\RussianPostSDK\Tracking; |
|
15
|
|
|
|
|
16
|
|
|
use Psr\Log\NullLogger; |
|
17
|
|
|
use Psr\Log\LoggerAwareTrait; |
|
18
|
|
|
use Psr\Log\LoggerAwareInterface; |
|
19
|
|
|
use Appwilio\RussianPostSDK\Tracking\Single\TrackingResponse; |
|
20
|
|
|
use Appwilio\RussianPostSDK\Tracking\Single\CashOnDeliveryResponse; |
|
21
|
|
|
use Appwilio\RussianPostSDK\Tracking\Single\CashOnDeliveryEventsInput; |
|
22
|
|
|
use Appwilio\RussianPostSDK\Tracking\Exceptions\SingleAccessException; |
|
23
|
|
|
use Appwilio\RussianPostSDK\Tracking\Single\PostalOrderEventsForMailInput; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
class SingleAccessClient implements LoggerAwareInterface |
|
26
|
|
|
{ |
|
27
|
|
|
use LoggerAwareTrait; |
|
28
|
|
|
|
|
29
|
|
|
public const LANG_ENG = 'ENG'; |
|
30
|
|
|
public const LANG_RUS = 'RUS'; |
|
31
|
|
|
|
|
32
|
|
|
public const HISTORY_OPERATIONS = 0; |
|
33
|
|
|
public const HISTORY_NOTIFICATIONS = 1; |
|
34
|
|
|
|
|
35
|
|
|
protected const LINK_URL = 'https://www.pochta.ru/tracking'; |
|
36
|
|
|
protected const WSDL_URL = 'https://tracking.pochta.ru/tracking-web-static/rtm34_wsdl.xml'; |
|
37
|
|
|
|
|
38
|
|
|
protected const XML_NS_DATA = 'http://russianpost.org/operationhistory/data'; |
|
39
|
|
|
protected const XML_NS_COD_HISTORY = 'http://www.russianpost.org/RTM/DataExchangeESPP/Data'; |
|
40
|
|
|
|
|
41
|
|
|
/** @var \SoapClient */ |
|
42
|
|
|
protected $client; |
|
43
|
|
|
|
|
44
|
|
|
/** @var string */ |
|
45
|
|
|
private $login; |
|
46
|
|
|
|
|
47
|
|
|
/** @var string */ |
|
48
|
|
|
private $password; |
|
49
|
|
|
|
|
50
|
|
|
private $options = [ |
|
51
|
|
|
'soap_version' => SOAP_1_2, |
|
52
|
|
|
'trace' => 1, |
|
53
|
|
|
'classmap' => [ |
|
54
|
|
|
'Rtm02Parameter' => Single\Parameter::class, |
|
55
|
|
|
|
|
56
|
|
|
'getOperationHistoryResponse' => Single\TrackingResponse::class, |
|
57
|
|
|
'OperationHistoryRecord' => Single\TrackingOperation::class, |
|
58
|
|
|
'Address' => Single\TrackingOperationAddress::class, |
|
59
|
|
|
'Country' => Single\TrackingOperationCountry::class, |
|
60
|
|
|
'OperationHistoryData' => Single\TrackingOperationsWrapper::class, |
|
61
|
|
|
'OperationParameters' => Single\TrackingOperationParameters::class, |
|
62
|
|
|
'UserParameters' => Single\TrackingOperationUserParameters::class, |
|
63
|
|
|
'ItemParameters' => Single\TrackingOperationItemParameters::class, |
|
64
|
|
|
'AddressParameters' => Single\TrackingOperationAddressParameters::class, |
|
65
|
|
|
'FinanceParameters' => Single\TrackingOperationFinanceParameters::class, |
|
66
|
|
|
|
|
67
|
|
|
'PostalOrderEvent' => Single\CashOnDeliveryEvent::class, |
|
68
|
|
|
'PostalOrderEventsForMailResponse' => Single\CashOnDeliveryResponse::class, |
|
69
|
|
|
'PostalOrderEventsForMailInput' => Single\CashOnDeliveryEventsInput::class, |
|
70
|
|
|
// Mai – не опечатка |
|
71
|
|
|
'PostalOrderEventsForMaiOutput' => Single\CashOnDeliveryEventsWrapper::class, |
|
72
|
|
|
], |
|
73
|
|
|
]; |
|
74
|
|
|
|
|
75
|
4 |
|
public function __construct(string $login, string $password) |
|
76
|
|
|
{ |
|
77
|
4 |
|
$this->logger = new NullLogger(); |
|
78
|
|
|
|
|
79
|
4 |
|
$this->login = $login; |
|
80
|
4 |
|
$this->password = $password; |
|
81
|
4 |
|
} |
|
82
|
|
|
|
|
83
|
1 |
|
public function getTrackingUrl(string $number): string |
|
84
|
|
|
{ |
|
85
|
1 |
|
return self::LINK_URL."#{$number}"; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
1 |
|
public function getTrackingEvents( |
|
89
|
|
|
string $track, |
|
90
|
|
|
string $language = self::LANG_RUS, |
|
91
|
|
|
int $type = self::HISTORY_OPERATIONS |
|
92
|
|
|
): TrackingResponse { |
|
93
|
1 |
|
return $this->callSoapMethod( |
|
94
|
1 |
|
'getOperationHistory', |
|
95
|
1 |
|
$this->assembleTrackingRequestArguments($track, $language, $type) |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
1 |
|
public function getCashOnDeliveryEvents( |
|
100
|
|
|
string $track, |
|
101
|
|
|
string $language = self::LANG_RUS |
|
102
|
|
|
): CashOnDeliveryResponse { |
|
103
|
1 |
|
return $this->callSoapMethod( |
|
104
|
1 |
|
'PostalOrderEventsForMail', |
|
105
|
1 |
|
$this->assembleCashOnDeliveryRequestArguments($track, $language) |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
2 |
|
protected function getClient(): \SoapClient |
|
110
|
|
|
{ |
|
111
|
2 |
|
if (! $this->client) { |
|
112
|
|
|
$this->client = new \SoapClient(self::WSDL_URL, $this->options); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
2 |
|
return $this->client; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
2 |
|
private function callSoapMethod(string $method, \SoapVar $arguments) |
|
119
|
|
|
{ |
|
120
|
|
|
try { |
|
121
|
2 |
|
return $this->getClient()->__soapCall($method, [$arguments]); |
|
122
|
|
|
} catch (\SoapFault $e) { |
|
123
|
|
|
if (\property_exists($e, 'detail')) { |
|
124
|
|
|
$detail = \get_object_vars($e->{'detail'}); |
|
125
|
|
|
|
|
126
|
|
|
throw new SingleAccessException(\key($detail).': '.\current($detail), $e->getCode(), $e); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
throw new SingleAccessException($e->getMessage(), $e->getCode(), $e); |
|
130
|
|
|
} finally { |
|
131
|
2 |
|
$this->logger->info("pochta.ru Single Tracking request: {$this->getClient()->__getLastRequest()}"); |
|
132
|
2 |
|
$this->logger->info("pochta.ru Single Tracking response: {$this->getClient()->__getLastResponse()}"); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
1 |
|
private function assembleTrackingRequestArguments(string $track, string $language, int $type): \SoapVar |
|
137
|
|
|
{ |
|
138
|
1 |
|
return new \SoapVar([ |
|
139
|
1 |
|
new \SoapVar([ |
|
140
|
1 |
|
new \SoapVar($track, \XSD_STRING, '', '', 'Barcode', self::XML_NS_DATA), |
|
141
|
1 |
|
new \SoapVar($type, \XSD_STRING, '', '', 'MessageType', self::XML_NS_DATA), |
|
142
|
1 |
|
new \SoapVar($language, \XSD_STRING, '', '', 'Language', self::XML_NS_DATA), |
|
143
|
1 |
|
], \SOAP_ENC_OBJECT, '', '', 'OperationHistoryRequest', self::XML_NS_DATA), |
|
144
|
1 |
|
new \SoapVar([ |
|
145
|
1 |
|
new \SoapVar($this->login, XSD_STRING, '', '', 'login', self::XML_NS_DATA), |
|
146
|
1 |
|
new \SoapVar($this->password, XSD_STRING, '', '', 'password', self::XML_NS_DATA), |
|
147
|
1 |
|
], SOAP_ENC_OBJECT, '', '', 'AuthorizationHeader', self::XML_NS_DATA), |
|
148
|
1 |
|
], \SOAP_ENC_OBJECT); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
1 |
|
private function assembleCashOnDeliveryRequestArguments(string $code, string $language): \SoapVar |
|
152
|
|
|
{ |
|
153
|
1 |
|
$input = new CashOnDeliveryEventsInput($code, $language); |
|
154
|
|
|
|
|
155
|
1 |
|
return new \SoapVar([ |
|
156
|
1 |
|
new \SoapVar($input, \SOAP_ENC_OBJECT, '', '', 'PostalOrderEventsForMailInput', self::XML_NS_COD_HISTORY), |
|
157
|
1 |
|
new \SoapVar([ |
|
158
|
1 |
|
new \SoapVar($this->login, XSD_STRING, '', '', 'login', self::XML_NS_DATA), |
|
159
|
1 |
|
new \SoapVar($this->password, XSD_STRING, '', '', 'password', self::XML_NS_DATA), |
|
160
|
1 |
|
], SOAP_ENC_OBJECT, '', '', 'AuthorizationHeader', self::XML_NS_DATA), |
|
161
|
1 |
|
], \SOAP_ENC_OBJECT); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths