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
|
|
|
private const MODEL_NAME = 'InternetDocument'; |
23
|
|
|
private Connection $connection; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Connection $connection |
27
|
|
|
*/ |
28
|
|
|
public function __construct(Connection $connection) |
29
|
|
|
{ |
30
|
|
|
$this->connection = $connection; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a91f115b-8512-11ec-8ced-005056b2dbe1 |
35
|
|
|
* @see \SergeyNezbritskiy\NovaPoshta\Tests\Integration\Models\InternetDocument\GetDocumentPriceTest for more cases |
36
|
|
|
* @param array $params |
37
|
|
|
* $params = [ |
38
|
|
|
* 'CitySender' => (string) City ref. Required |
39
|
|
|
* 'CityRecipient' => (string) City ref. Required |
40
|
|
|
* 'Weight' => (string) Minimal value - 0.1. Required |
41
|
|
|
* 'ServiceTYpe' => (string) Optional |
42
|
|
|
* 'Cost' => (float) Optional, default - 300.00 |
43
|
|
|
* 'CargoType' => (string) Cargo type. see self::CARGO_TYPE_* constants, Optional |
44
|
|
|
* 'CargoDetails' => [ |
45
|
|
|
* [ |
46
|
|
|
* 'CargoDescription' => (string), |
47
|
|
|
* 'Amount' => (float) |
48
|
|
|
* ], |
49
|
|
|
* ... |
50
|
|
|
* ] |
51
|
|
|
* 'RedeliveryCalculate' => [ Back delivery. Optional |
52
|
|
|
* [ |
53
|
|
|
* 'CargoType' => (string), e.g. Money |
54
|
|
|
* 'Amount' => (float) |
55
|
|
|
* ], |
56
|
|
|
* ... |
57
|
|
|
* ], |
58
|
|
|
* 'OptionsSeat' => [ |
59
|
|
|
* 'weight' => (float), Required. |
60
|
|
|
* 'volumetricWidth' => (float), Required. |
61
|
|
|
* 'volumetricLength' => (float), Required. |
62
|
|
|
* 'volumetricHeight' => (float), Required. |
63
|
|
|
* 'packRef' => (string), Optional. |
64
|
|
|
* ], |
65
|
|
|
* 'SeatsAmount' => (int) Optional |
66
|
|
|
* 'PackCount' => (int) Optional |
67
|
|
|
* 'CargoDescription' => (string) Cargo type. see self::CARGO_TYPE_* constants, Optional |
68
|
|
|
* 'PackCount' => (string) The amount of packing, Optional |
69
|
|
|
* 'PackRef' => (string) Packing identifier (REF). Optional |
70
|
|
|
* 'Amount' => (int) Amount of back delivery. Optional |
71
|
|
|
* ] |
72
|
|
|
* @return array |
73
|
|
|
* @throws NovaPoshtaApiException |
74
|
|
|
*/ |
75
|
|
|
public function getDocumentPrice(array $params): array |
76
|
|
|
{ |
77
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'getDocumentPrice', $params); |
78
|
|
|
return array_shift($result); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a941c714-8512-11ec-8ced-005056b2dbe1 |
83
|
|
|
* @see \SergeyNezbritskiy\NovaPoshta\Tests\Integration\Models\InternetDocument\GetDocumentDeliveryDateTest |
84
|
|
|
* @param array $params |
85
|
|
|
* $params = [ |
86
|
|
|
* 'DateTime' => (string), Document creation date, format `d.m.Y`. Optional. |
87
|
|
|
* 'ServiceType' => (string), Required. |
88
|
|
|
* 'CitySender' => (string), city ref. Required. |
89
|
|
|
* 'CityRecipient' => (string), city ref. Required. |
90
|
|
|
* ]; |
91
|
|
|
* @return array |
92
|
|
|
* @throws NovaPoshtaApiException |
93
|
|
|
*/ |
94
|
|
|
public function getDocumentDeliveryDate(array $params): array |
95
|
|
|
{ |
96
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'getDocumentDeliveryDate', $params); |
97
|
|
|
return array_shift($result)['DeliveryDate']; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a9d22b34-8512-11ec-8ced-005056b2dbe1 |
102
|
|
|
* @param string $dateFrom |
103
|
|
|
* @param string $dateTo |
104
|
|
|
* @param bool $fullList |
105
|
|
|
* @param string|null $date |
106
|
|
|
* @param int|null $page |
107
|
|
|
* @return array |
108
|
|
|
* @throws NovaPoshtaApiException |
109
|
|
|
*/ |
110
|
|
|
public function getDocumentList(array $params, int $page = null): array |
111
|
|
|
{ |
112
|
|
|
if ($page) { |
|
|
|
|
113
|
|
|
$params['Page'] = $page; |
114
|
|
|
} |
115
|
|
|
return $this->connection->post(self::MODEL_NAME, 'getDocumentList', $params); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a965630e-8512-11ec-8ced-005056b2dbe1 |
120
|
|
|
* @param array $params |
121
|
|
|
* @return array |
122
|
|
|
* @throws NovaPoshtaApiException |
123
|
|
|
*/ |
124
|
|
|
public function save(array $params): array |
125
|
|
|
{ |
126
|
|
|
$result = $this->connection->post(self::MODEL_NAME, 'save', $params); |
127
|
|
|
return array_shift($result); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a965630e-8512-11ec-8ced-005056b2dbe1 |
132
|
|
|
* @param string $documentRef |
133
|
|
|
* @return void |
134
|
|
|
* @throws NovaPoshtaApiException |
135
|
|
|
*/ |
136
|
|
|
public function delete(string $documentRef): void |
137
|
|
|
{ |
138
|
|
|
$this->connection->post(self::MODEL_NAME, 'delete', ['DocumentRefs' => $documentRef]); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: