1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** @noinspection PhpUnused */ |
4
|
|
|
|
5
|
|
|
declare(strict_types=1); |
6
|
|
|
|
7
|
|
|
namespace SergeyNezbritskiy\NovaPoshta\Models; |
8
|
|
|
|
9
|
|
|
use SergeyNezbritskiy\NovaPoshta\Connection; |
10
|
|
|
use SergeyNezbritskiy\NovaPoshta\ModelInterface; |
11
|
|
|
use SergeyNezbritskiy\NovaPoshta\NovaPoshtaApiException; |
12
|
|
|
|
13
|
|
|
class Counterparty implements ModelInterface |
14
|
|
|
{ |
15
|
|
|
public const COUNTERPARTY_PROPERTY_SENDER = 'Sender'; |
16
|
|
|
public const COUNTERPARTY_PROPERTY_RECIPIENT = 'Recipient'; |
17
|
|
|
public const COUNTERPARTY_PROPERTY_THIRD_PERSON = 'ThirdPerson'; |
18
|
|
|
|
19
|
|
|
private const MODEL_NAME = 'Counterparty'; |
20
|
|
|
|
21
|
|
|
private Connection $connection; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param Connection $connection |
25
|
|
|
*/ |
26
|
|
|
public function __construct(Connection $connection) |
27
|
|
|
{ |
28
|
|
|
$this->connection = $connection; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @see https://developers.novaposhta.ua/view/model/a28f4b04-8512-11ec-8ced-005056b2dbe1/method/0ae5dd75-8a5f-11ec-8ced-005056b2dbe1 |
33
|
|
|
* @param array $counterparty Array containing the necessary params. |
34
|
|
|
* $counterparty = [ |
35
|
|
|
* 'FirstName' => (string) First name. Required. |
36
|
|
|
* 'MiddleName' => (string) Middle name. Required. |
37
|
|
|
* 'LastName' => (string) Last name. Required. |
38
|
|
|
* 'Phone' => (string) Phone number. Required. |
39
|
|
|
* 'Email' => (string) Email. Required. |
40
|
|
|
* 'CounterpartyProperty' => (string) Counterparty property. Required. |
41
|
|
|
* ] |
42
|
|
|
* @return array |
43
|
|
|
* @throws NovaPoshtaApiException |
44
|
|
|
*/ |
45
|
|
|
public function savePrivatePerson(array $counterparty): array |
46
|
|
|
{ |
47
|
|
|
$counterparty['CounterpartyType'] = 'PrivatePerson'; |
48
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'save', $counterparty); |
49
|
|
|
return array_shift($result); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* https://developers.novaposhta.ua/view/model/a28f4b04-8512-11ec-8ced-005056b2dbe1/method/bc3c44c7-8a8a-11ec-8ced-005056b2dbe1 |
54
|
|
|
* @param array $counterparty Array containing the necessary params. |
55
|
|
|
* $counterparty = [ |
56
|
|
|
* 'EDRPOU' => (string) EDRPOU. Required. |
57
|
|
|
* 'CounterpartyProperty' => (string) Counterparty property. Optional. |
58
|
|
|
* ] |
59
|
|
|
* @return array |
60
|
|
|
* @throws NovaPoshtaApiException |
61
|
|
|
*/ |
62
|
|
|
public function saveOrganisation(array $counterparty): array |
63
|
|
|
{ |
64
|
|
|
$counterparty['CounterpartyType'] = 'Organization'; |
65
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'save', $counterparty); |
66
|
|
|
return array_shift($result); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @see https://developers.novaposhta.ua/view/model/a28f4b04-8512-11ec-8ced-005056b2dbe1/method/0ae5dd75-8a5f-11ec-8ced-005056b2dbe1 |
71
|
|
|
* @param array $counterparty Array containing the necessary params. |
72
|
|
|
* $counterparty = [ |
73
|
|
|
* 'Ref' => (string) Identifier. Required. |
74
|
|
|
* 'FirstName' => (string) First name. Required. |
75
|
|
|
* 'MiddleName' => (string) Middle name. Required. |
76
|
|
|
* 'LastName' => (string) Last name. Required. |
77
|
|
|
* 'Phone' => (string) Phone number. Optional. |
78
|
|
|
* 'Email' => (string) Email. Optional. |
79
|
|
|
* 'CounterpartyProperty' => (string) Counterparty property. Required. |
80
|
|
|
* ] |
81
|
|
|
* @return array |
82
|
|
|
* @throws NovaPoshtaApiException |
83
|
|
|
*/ |
84
|
|
|
public function updatePrivatePerson(array $counterparty): array |
85
|
|
|
{ |
86
|
|
|
$counterparty['CounterpartyType'] = 'PrivatePerson'; |
87
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'update', $counterparty); |
88
|
|
|
return array_shift($result); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @see https://developers.novaposhta.ua/view/model/a28f4b04-8512-11ec-8ced-005056b2dbe1/method/a2eb27e8-8512-11ec-8ced-005056b2dbe1 |
93
|
|
|
* @param string $ref |
94
|
|
|
* @return void |
95
|
|
|
* @throws NovaPoshtaApiException |
96
|
|
|
*/ |
97
|
|
|
public function delete(string $ref): void |
98
|
|
|
{ |
99
|
|
|
$this->connection->post(self::MODEL_NAME, 'delete', ['Ref' => $ref]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @see https://developers.novaposhta.ua/view/model/a28f4b04-8512-11ec-8ced-005056b2dbe1/method/a332efbf-8512-11ec-8ced-005056b2dbe1 |
104
|
|
|
* @param string $ref |
105
|
|
|
* @return array |
106
|
|
|
* @throws NovaPoshtaApiException |
107
|
|
|
*/ |
108
|
|
|
public function getCounterpartyOptions(string $ref): array |
109
|
|
|
{ |
110
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'getCounterpartyOptions', ['Ref' => $ref]); |
111
|
|
|
return array_shift($result); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @see https://developers.novaposhta.ua/view/model/a28f4b04-8512-11ec-8ced-005056b2dbe1/method/a3575a67-8512-11ec-8ced-005056b2dbe1 |
116
|
|
|
* @param string $ref |
117
|
|
|
* @param int $page |
118
|
|
|
* @return array |
119
|
|
|
* @throws NovaPoshtaApiException |
120
|
|
|
*/ |
121
|
|
|
public function getCounterpartyContactPersons(string $ref, int $page = 1): array |
122
|
|
|
{ |
123
|
|
|
$params = [ |
124
|
|
|
'Ref' => $ref, |
125
|
|
|
'Page' => $page |
126
|
|
|
]; |
127
|
|
|
return $this->connection->post(self::MODEL_NAME, 'getCounterpartyContactPersons', $params); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @see https://developers.novaposhta.ua/view/model/a28f4b04-8512-11ec-8ced-005056b2dbe1/method/a37a06df-8512-11ec-8ced-005056b2dbe1 |
132
|
|
|
* @param string $counterpartyProperty |
133
|
|
|
* @param string|null $search |
134
|
|
|
* @param int $page |
135
|
|
|
* @return array |
136
|
|
|
* @throws NovaPoshtaApiException |
137
|
|
|
*/ |
138
|
|
|
public function getCounterparties(string $counterpartyProperty, string $search = null, int $page = 1): array |
139
|
|
|
{ |
140
|
|
|
$params = array_filter([ |
141
|
|
|
'CounterpartyProperty' => $counterpartyProperty, |
142
|
|
|
'FindByString' => $search, |
143
|
|
|
'Page' => $page |
144
|
|
|
]); |
145
|
|
|
return $this->connection->post(self::MODEL_NAME, 'getCounterparties', $params); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param string $counterpartyRef |
150
|
|
|
* @param string $counterpartyProperty |
151
|
|
|
* @return array |
152
|
|
|
* @throws NovaPoshtaApiException |
153
|
|
|
*/ |
154
|
|
|
public function getCounterpartyAddresses(string $counterpartyRef, string $counterpartyProperty): array |
155
|
|
|
{ |
156
|
|
|
$params = [ |
157
|
|
|
'Ref' => $counterpartyRef, |
158
|
|
|
'CounterpartyProperty' => $counterpartyProperty, |
159
|
|
|
]; |
160
|
|
|
return $this->connection->post(self::MODEL_NAME, 'getCounterpartyAddresses', $params); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|