Passed
Pull Request — master (#10)
by Sergey
02:19
created

Counterparty::getCounterpartyOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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