1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @noinspection PhpUnused |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace SergeyNezbritskiy\NovaPoshta\Models; |
10
|
|
|
|
11
|
|
|
use SergeyNezbritskiy\NovaPoshta\Connection; |
12
|
|
|
use SergeyNezbritskiy\NovaPoshta\ModelInterface; |
13
|
|
|
use SergeyNezbritskiy\NovaPoshta\NovaPoshtaApiException; |
14
|
|
|
|
15
|
|
|
class InternetDocument implements ModelInterface |
16
|
|
|
{ |
17
|
|
|
public const CARGO_TYPE_CARGO = 'Cargo'; |
18
|
|
|
public const CARGO_TYPE_DOCUMENTS = 'Documents'; |
19
|
|
|
public const CARGO_TYPE_TIRES_WHEELS = 'TiresWheels'; |
20
|
|
|
public const CARGO_TYPE_PALLET = 'Pallet'; |
21
|
|
|
|
22
|
|
|
public const SERVICE_TYPE_DOORS_DOORS = 'DoorsDoors'; |
23
|
|
|
public const SERVICE_TYPE_DOORS_WAREHOUSE = 'DoorsWarehouse'; |
24
|
|
|
public const SERVICE_TYPE_WAREHOUSE_DOORS = 'WarehouseDoors'; |
25
|
|
|
public const SERVICE_TYPE_WAREHOUSE_WAREHOUSE = 'WarehouseWarehouse'; |
26
|
|
|
|
27
|
|
|
public const PAYER_TYPE_SENDER = 'Sender'; |
28
|
|
|
public const PAYER_TYPE_RECIPIENT = 'Recipient'; |
29
|
|
|
public const PAYER_TYPE_THIRD_PERSON = 'ThirdPerson'; |
30
|
|
|
|
31
|
|
|
public const PAYMENT_TYPE_CASH = 'Cash'; |
32
|
|
|
public const PAYMENT_TYPE_NON_CASH = 'NonCash'; |
33
|
|
|
|
34
|
|
|
private const MODEL_NAME = 'InternetDocument'; |
35
|
|
|
|
36
|
|
|
private Connection $connection; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param Connection $connection |
40
|
|
|
*/ |
41
|
|
|
public function __construct(Connection $connection) |
42
|
|
|
{ |
43
|
|
|
$this->connection = $connection; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a91f115b-8512-11ec-8ced-005056b2dbe1 |
48
|
|
|
* @see \SergeyNezbritskiy\NovaPoshta\Tests\Integration\Models\InternetDocument\GetDocumentPriceTest for more cases |
49
|
|
|
* @param array $params |
50
|
|
|
* $params = [ |
51
|
|
|
* 'CitySender' => (string) City ref. Required |
52
|
|
|
* 'CityRecipient' => (string) City ref. Required |
53
|
|
|
* 'Weight' => (string) Minimal value - 0.1. Required |
54
|
|
|
* 'ServiceTYpe' => (string) Optional |
55
|
|
|
* 'Cost' => (float) Optional, default - 300.00 |
56
|
|
|
* 'CargoType' => (string) Cargo type. see self::CARGO_TYPE_* constants, Optional |
57
|
|
|
* 'CargoDetails' => [ |
58
|
|
|
* [ |
59
|
|
|
* 'CargoDescription' => (string), |
60
|
|
|
* 'Amount' => (float) |
61
|
|
|
* ], |
62
|
|
|
* ... |
63
|
|
|
* ] |
64
|
|
|
* 'RedeliveryCalculate' => [ Back delivery. Optional |
65
|
|
|
* [ |
66
|
|
|
* 'CargoType' => (string), e.g. Money |
67
|
|
|
* 'Amount' => (float) |
68
|
|
|
* ], |
69
|
|
|
* ... |
70
|
|
|
* ], |
71
|
|
|
* 'OptionsSeat' => [ |
72
|
|
|
* 'weight' => (float), Required. |
73
|
|
|
* 'volumetricWidth' => (float), Required. |
74
|
|
|
* 'volumetricLength' => (float), Required. |
75
|
|
|
* 'volumetricHeight' => (float), Required. |
76
|
|
|
* 'packRef' => (string), Optional. |
77
|
|
|
* ], |
78
|
|
|
* 'SeatsAmount' => (int) Optional |
79
|
|
|
* 'PackCount' => (int) Optional |
80
|
|
|
* 'CargoDescription' => (string) Cargo type. see self::CARGO_TYPE_* constants, Optional |
81
|
|
|
* 'PackCount' => (string) The amount of packing, Optional |
82
|
|
|
* 'PackRef' => (string) Packing identifier (REF). Optional |
83
|
|
|
* 'Amount' => (int) Amount of back delivery. Optional |
84
|
|
|
* ] |
85
|
|
|
* @return array |
86
|
|
|
* @throws NovaPoshtaApiException |
87
|
|
|
*/ |
88
|
|
|
public function getDocumentPrice(array $params): array |
89
|
|
|
{ |
90
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'getDocumentPrice', $params); |
91
|
|
|
return array_shift($result); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a941c714-8512-11ec-8ced-005056b2dbe1 |
96
|
|
|
* @see \SergeyNezbritskiy\NovaPoshta\Tests\Integration\Models\InternetDocument\GetDocumentDeliveryDateTest |
97
|
|
|
* @param array $params |
98
|
|
|
* $params = [ |
99
|
|
|
* 'DateTime' => (string), Document creation date, format `d.m.Y`. Optional. |
100
|
|
|
* 'ServiceType' => (string), Required. |
101
|
|
|
* 'CitySender' => (string), city ref. Required. |
102
|
|
|
* 'CityRecipient' => (string), city ref. Required. |
103
|
|
|
* ]; |
104
|
|
|
* @return array |
105
|
|
|
* @throws NovaPoshtaApiException |
106
|
|
|
*/ |
107
|
|
|
public function getDocumentDeliveryDate(array $params): array |
108
|
|
|
{ |
109
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'getDocumentDeliveryDate', $params); |
110
|
|
|
return array_shift($result)['DeliveryDate']; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a9d22b34-8512-11ec-8ced-005056b2dbe1 |
115
|
|
|
* @param array $params |
116
|
|
|
* @param int|null $page |
117
|
|
|
* @return array |
118
|
|
|
* @throws NovaPoshtaApiException |
119
|
|
|
*/ |
120
|
|
|
public function getDocumentList(array $params, int $page = null): array |
121
|
|
|
{ |
122
|
|
|
if ($page !== null) { |
123
|
|
|
$params['Page'] = $page; |
124
|
|
|
} |
125
|
|
|
return $this->connection->post(self::MODEL_NAME, 'getDocumentList', $params); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a965630e-8512-11ec-8ced-005056b2dbe1 |
130
|
|
|
* @param array $params |
131
|
|
|
* @return array |
132
|
|
|
* @throws NovaPoshtaApiException |
133
|
|
|
*/ |
134
|
|
|
public function save(array $params): array |
135
|
|
|
{ |
136
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'save', $params); |
137
|
|
|
return array_shift($result); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a98a4354-8512-11ec-8ced-005056b2dbe1 |
142
|
|
|
* @param array $params |
143
|
|
|
* @return array |
144
|
|
|
* @throws NovaPoshtaApiException |
145
|
|
|
*/ |
146
|
|
|
public function update(array $params): array |
147
|
|
|
{ |
148
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'update', $params); |
149
|
|
|
return array_shift($result); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a965630e-8512-11ec-8ced-005056b2dbe1 |
154
|
|
|
* @param string $documentRef |
155
|
|
|
* @return void |
156
|
|
|
* @throws NovaPoshtaApiException |
157
|
|
|
*/ |
158
|
|
|
public function delete(string $documentRef): void |
159
|
|
|
{ |
160
|
|
|
$this->connection->post(self::MODEL_NAME, 'delete', ['DocumentRefs' => $documentRef]); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|