1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Orders\Entites; |
6
|
|
|
|
7
|
|
|
use Appwilio\RussianPostSDK\Core\ArrayOf; |
8
|
|
|
use Appwilio\RussianPostSDK\Dispatching\DataAware; |
9
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Enum\MailRank; |
10
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Enum\MailType; |
11
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Enum\MailCategory; |
12
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Enum\PaymentMethodType; |
13
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Instantiator; |
14
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Entities\Tariff; |
15
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Entities\Address; |
16
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Entities\DeliveryTime; |
17
|
|
|
|
18
|
|
|
final class Order |
19
|
|
|
{ |
20
|
|
|
use DataAware; |
21
|
|
|
|
22
|
|
|
public function getId(): string |
23
|
|
|
{ |
24
|
|
|
return (string) $this->get('id'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getNumber(): string |
28
|
|
|
{ |
29
|
|
|
return $this->get('order-num'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getWeight(): int |
33
|
|
|
{ |
34
|
|
|
return $this->get('mass'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getTrackingNumber(): string |
38
|
|
|
{ |
39
|
|
|
return $this->get('barcode'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getPaymentMethod(): PaymentMethodType |
43
|
|
|
{ |
44
|
|
|
return new PaymentMethodType($this->get('payment-method')); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getVersion(): int |
48
|
|
|
{ |
49
|
|
|
return (int) $this->get('version'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getMailType(): MailType |
53
|
|
|
{ |
54
|
|
|
return new MailType($this->get('mail-type')); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getMailCategory(): MailCategory |
58
|
|
|
{ |
59
|
|
|
return new MailCategory($this->get('mail-category')); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getMailRank(): MailRank |
63
|
|
|
{ |
64
|
|
|
return new MailRank($this->get('mail-rank')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function hasCustomsDeclaration(): bool |
68
|
|
|
{ |
69
|
|
|
return (bool) $this->get('customs-declaration'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getCustomsDeclaration(): ?CustomsDeclaration |
73
|
|
|
{ |
74
|
|
|
return Instantiator::instantiate(CustomsDeclaration::class, $this->get('customs-declaration')); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return OrderItem[]|null |
79
|
|
|
*/ |
80
|
|
|
public function getItems() |
81
|
|
|
{ |
82
|
|
|
return Instantiator::instantiate(new ArrayOf(OrderItem::class), $this->get('goods')); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getAddress(): Address |
86
|
|
|
{ |
87
|
|
|
return Instantiator::instantiate(Address::class, [ |
88
|
|
|
'address-type-to' => $this->get('address-type-to'), |
89
|
|
|
'area-to' => $this->get('area-to'), |
90
|
|
|
'building-to' => $this->get('building-to'), |
91
|
|
|
'corpus-to' => $this->get('corpus-to'), |
92
|
|
|
'hotel-to' => $this->get('hotel-to'), |
93
|
|
|
'house-to' => $this->get('house-to'), |
94
|
|
|
'letter-to' => $this->get('letter-to'), |
95
|
|
|
'location-to' => $this->get('location-to'), |
96
|
|
|
'office-to' => $this->get('office-to'), |
97
|
|
|
'place-to' => $this->get('place-to'), |
98
|
|
|
'region-to' => $this->get('region-to'), |
99
|
|
|
'room-to' => $this->get('room-to'), |
100
|
|
|
'slash-to' => $this->get('slash-to'), |
101
|
|
|
'street-to' => $this->get('street-to'), |
102
|
|
|
'mail-direct' => $this->get('mail-direct'), |
103
|
|
|
'num-address-type-to' => $this->get('num-address-type-to'), |
104
|
|
|
'index-to' => $this->data['index-to'] ?? $this->data['str-index-to'], |
105
|
|
|
]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getRecipient(): Recipient |
109
|
|
|
{ |
110
|
|
|
return Instantiator::instantiate(Recipient::class, [ |
111
|
|
|
'given-name' => $this->get('given-name'), |
112
|
|
|
'middle-name' => $this->get('middle-name'), |
113
|
|
|
'surname' => $this->get('surname'), |
114
|
|
|
'tel-address' => $this->get('tel-address'), |
115
|
|
|
'recipient-name' => $this->get('recipient-name'), |
116
|
|
|
]); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getDeliveryTime(): ?DeliveryTime |
120
|
|
|
{ |
121
|
|
|
return Instantiator::instantiate(DeliveryTime::class, $this->get('delivery-time')); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function getGroundRate(): Tariff |
125
|
|
|
{ |
126
|
|
|
return Instantiator::instantiate(Tariff::class, [ |
127
|
|
|
'rate' => $this->get('ground-rate-wo-vat'), |
128
|
|
|
'vat' => $this->get('ground-vat'), |
129
|
|
|
]); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getInsuranceRate(): Tariff |
133
|
|
|
{ |
134
|
|
|
return Instantiator::instantiate(Tariff::class, [ |
135
|
|
|
'rate' => $this->get('insr-rate-wo-vat'), |
136
|
|
|
'vat' => $this->get('insr-rate-with-vat') - $this->get('insr-rate-wo-vat'), |
137
|
|
|
]); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function getTotalRate(): Tariff |
141
|
|
|
{ |
142
|
|
|
return Instantiator::instantiate(Tariff::class, [ |
143
|
|
|
'rate' => $this->get('total-rate-wo-vat'), |
144
|
|
|
'vat' => $this->get('total-vat'), |
145
|
|
|
]); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getEcomData(): ?EcomData |
149
|
|
|
{ |
150
|
|
|
return Instantiator::instantiate(EcomData::class, $this->get('ecom-data')); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function getFiscalData(): ?FiscalData |
154
|
|
|
{ |
155
|
|
|
return Instantiator::instantiate(FiscalData::class, $this->get('fiscal-data')); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|