|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SergeyNezbritskiy\NovaPoshta\Models; |
|
6
|
|
|
|
|
7
|
|
|
use SergeyNezbritskiy\NovaPoshta\Connection; |
|
8
|
|
|
use SergeyNezbritskiy\NovaPoshta\ModelInterface; |
|
9
|
|
|
use SergeyNezbritskiy\NovaPoshta\NovaPoshtaApiException; |
|
10
|
|
|
|
|
11
|
|
|
class Counterparty implements ModelInterface |
|
12
|
|
|
{ |
|
13
|
|
|
private const MODEL_NAME = 'Counterparty'; |
|
14
|
|
|
|
|
15
|
|
|
private Connection $connection; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param Connection $connection |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct(Connection $connection) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->connection = $connection; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param array $counterparty Array containing the necessary params. |
|
27
|
|
|
* $counterparty = [ |
|
28
|
|
|
* 'FirstName' => (string) First name. Required. |
|
29
|
|
|
* 'MiddleName' => (string) Middle name. Required. |
|
30
|
|
|
* 'LastName' => (string) Last name. Required. |
|
31
|
|
|
* 'Phone' => (string) Phone number. Required. |
|
32
|
|
|
* 'Email' => (string) Email. Required. |
|
33
|
|
|
* 'CounterpartyType' => (string) Counterparty type. Required. |
|
34
|
|
|
* 'CounterpartyProperty' => (string) Counterparty property. Required. |
|
35
|
|
|
* ] |
|
36
|
|
|
* @return array |
|
37
|
|
|
* @throws NovaPoshtaApiException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function save(array $counterparty): array |
|
40
|
|
|
{ |
|
41
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'save', $counterparty); |
|
42
|
|
|
return array_shift($result); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param string $counterpartyRef |
|
47
|
|
|
* @param string $counterpartyProperty |
|
48
|
|
|
* @return array |
|
49
|
|
|
* @throws NovaPoshtaApiException |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getCounterpartyAddresses(string $counterpartyRef, string $counterpartyProperty): array |
|
52
|
|
|
{ |
|
53
|
|
|
$params = [ |
|
54
|
|
|
'Ref' => $counterpartyRef, |
|
55
|
|
|
'CounterpartyProperty' => $counterpartyProperty, |
|
56
|
|
|
]; |
|
57
|
|
|
return $this->connection->post(self::MODEL_NAME, 'getCounterpartyAddresses', $params); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|