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