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\Enum\MailCategory; |
10
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Enum\MailEntryType; |
11
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable; |
12
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Entities\CommonOrder; |
13
|
|
|
|
14
|
|
|
final class CalculationRequest implements Arrayable |
15
|
|
|
{ |
16
|
|
|
use DataAware; |
17
|
|
|
use CommonOrder; |
18
|
|
|
|
19
|
1 |
|
public static function create(string $to, int $weight): self |
20
|
|
|
{ |
21
|
1 |
|
return new self(...\func_get_args()); |
22
|
|
|
} |
23
|
|
|
|
24
|
1 |
|
public function __construct(string $to, int $weight) |
25
|
|
|
{ |
26
|
1 |
|
$this->data = [ |
27
|
1 |
|
'index-to' => $to, |
28
|
1 |
|
'mass' => $weight, |
29
|
|
|
]; |
30
|
1 |
|
} |
31
|
|
|
|
32
|
|
|
public function ofEntriesType(MailEntryType $entriesType) |
33
|
|
|
{ |
34
|
|
|
$this->data['entries-type'] = $entriesType; |
35
|
|
|
|
36
|
|
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function ofMailCategory(MailCategory $mailCategory) |
40
|
|
|
{ |
41
|
|
|
$this->data['mail-category'] = $mailCategory; |
42
|
|
|
|
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
public function ofMailType(MailType $mailType) |
47
|
|
|
{ |
48
|
1 |
|
$this->data['mail-type'] = $mailType; |
49
|
|
|
|
50
|
1 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function withDeclaredValue(int $value) |
54
|
|
|
{ |
55
|
|
|
$this->data['declared-value'] = $value; |
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
public function withContentChecking(bool $value = true) |
61
|
|
|
{ |
62
|
1 |
|
$this->data['contents-checking'] = $value; |
63
|
|
|
|
64
|
1 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
public function withFitting(bool $value = true) |
68
|
|
|
{ |
69
|
1 |
|
$this->data['with-fitting'] = $value; |
70
|
|
|
|
71
|
1 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
public function toArray(): array |
75
|
|
|
{ |
76
|
1 |
|
if ($this->data['mail-type']->equals(MailType::ECOM())) { |
77
|
1 |
|
$this->data['delivery-point-index'] = $this->data['index-to']; |
78
|
|
|
|
79
|
1 |
|
unset($this->data['index-to']); |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
return $this->data; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|