1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Services\Requests; |
6
|
|
|
|
7
|
|
|
use Appwilio\RussianPostSDK\Dispatching\DataAware; |
8
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Enum\MailType; |
9
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable; |
10
|
|
|
|
11
|
|
|
final class CalculationRequest implements Arrayable |
12
|
|
|
{ |
13
|
|
|
use DataAware; |
14
|
|
|
|
15
|
1 |
|
public static function create(string $to, int $weight): self |
16
|
|
|
{ |
17
|
1 |
|
return new self(...\func_get_args()); |
18
|
|
|
} |
19
|
|
|
|
20
|
1 |
|
public function __construct(string $to, int $weight) |
21
|
|
|
{ |
22
|
1 |
|
$this->data = [ |
23
|
1 |
|
'index-to' => $to, |
24
|
1 |
|
'mass' => $weight, |
25
|
|
|
]; |
26
|
1 |
|
} |
27
|
|
|
|
28
|
|
|
public function ofEntriesType(string $entriesType) |
29
|
|
|
{ |
30
|
|
|
$this->data['entries-type'] = $entriesType; |
31
|
|
|
|
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function ofMailCategory(string $mailCategory) |
36
|
|
|
{ |
37
|
|
|
$this->data['mail-category'] = $mailCategory; |
38
|
|
|
|
39
|
|
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function ofMailType(string $mailType) |
43
|
|
|
{ |
44
|
1 |
|
$this->data['mail-type'] = $mailType; |
45
|
|
|
|
46
|
1 |
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function transport(string $value) |
50
|
|
|
{ |
51
|
|
|
$this->data['transport-type'] = $value; |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
public function dimensions(int $height, int $width, int $length) |
57
|
|
|
{ |
58
|
1 |
|
$this->data['dimension'] = \compact('height', 'width', 'length'); |
59
|
|
|
|
60
|
1 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
public function fragile(bool $value = true) |
64
|
|
|
{ |
65
|
1 |
|
$this->data['fragile'] = $value; |
66
|
|
|
|
67
|
1 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
public function viaCourier(bool $value = true) |
71
|
|
|
{ |
72
|
1 |
|
$this->data['courier'] = $value; |
73
|
|
|
|
74
|
1 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function withDeclaredValue(int $value) |
78
|
|
|
{ |
79
|
|
|
$this->data['declared-value'] = $value; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
public function withCompletenessChecking(bool $value = true) |
85
|
|
|
{ |
86
|
1 |
|
$this->data['completeness-checking'] = $value; |
87
|
|
|
|
88
|
1 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
public function withContentChecking(bool $value = true) |
92
|
|
|
{ |
93
|
1 |
|
$this->data['contents-checking'] = $value; |
94
|
|
|
|
95
|
1 |
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
public function withInventory(bool $value = true) |
99
|
|
|
{ |
100
|
1 |
|
$this->data['inventory'] = $value; |
101
|
|
|
|
102
|
1 |
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
public function withElectronicNotice(bool $value = true) |
106
|
|
|
{ |
107
|
1 |
|
$this->data['with-electronic-notice'] = $value; |
108
|
|
|
|
109
|
1 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
1 |
|
public function withFitting(bool $value = true) |
113
|
|
|
{ |
114
|
1 |
|
$this->data['with-fitting'] = $value; |
115
|
|
|
|
116
|
1 |
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
public function withSimpleNotice(bool $value = true) |
120
|
|
|
{ |
121
|
1 |
|
$this->data['with-simple-notice'] = $value; |
122
|
|
|
|
123
|
1 |
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
1 |
|
public function withRegisteredNotice(bool $value = true) |
127
|
|
|
{ |
128
|
1 |
|
$this->data['with-order-of-notice'] = $value; |
129
|
|
|
|
130
|
1 |
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
1 |
|
public function withSmsNotice(bool $value = true) |
134
|
|
|
{ |
135
|
1 |
|
$this->data['sms-notice-recipient'] = $value; |
136
|
|
|
|
137
|
1 |
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
1 |
|
public function toArray(): array |
141
|
|
|
{ |
142
|
1 |
|
if ($this->data['mail-type'] === MailType::ECOM) { |
143
|
1 |
|
$this->data['delivery-point-index'] = $this->data['index-to']; |
144
|
|
|
|
145
|
1 |
|
unset($this->data['index-to']); |
146
|
|
|
} |
147
|
|
|
|
148
|
1 |
|
return $this->data; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
} |
152
|
|
|
|