-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathShipmentOptions.php
More file actions
161 lines (135 loc) · 4.12 KB
/
ShipmentOptions.php
File metadata and controls
161 lines (135 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
namespace Mvdnbrk\DhlParcel\Resources;
use Mvdnbrk\DhlParcel\Support\Str;
class ShipmentOptions extends BaseResource
{
/** @var string */
protected $delivery_type;
/** @var string */
protected $service_point_id;
/** @var int|float */
protected $cash_on_delivery;
/** @var string */
public $label_description;
/** @var bool */
public $only_recipient;
/** @var bool */
public $extra_assurance;
/** @var bool */
public $evening_delivery;
/** @var bool */
public $signature;
/** @var int|float */
protected $insured;
public function __construct(array $attributes = [])
{
$this->setDefaultOptions();
parent::__construct($attributes);
}
public function setDefaultOptions(): self
{
$this->delivery_type = 'DOOR';
$this->signature = false;
$this->only_recipient = false;
$this->extra_assurance = false;
$this->evening_delivery = false;
return $this;
}
public function getDescriptionAttribute(): string
{
return $this->label_description;
}
public function setLabelDescriptionAttribute(string $value): void
{
$this->label_description = Str::limit(trim($value), 15, '');
}
public function setDescriptionAttribute(string $value): void
{
$this->setLabelDescriptionAttribute($value);
}
public function setMailboxPackage(): void
{
$this->setDefaultOptions();
$this->delivery_type = 'BP';
}
public function setServicePointIdAttribute(string $value): void
{
$this->setDefaultOptions();
$this->delivery_type = 'PS';
$this->service_point_id = $value;
}
/**
* Set the amount for "Cash On Delivery" in EUR.
*
* @param int|float $value
* @return void
*/
public function setCashOnDelivery($value): void
{
$this->cash_on_delivery = $value;
}
/**
* Set the amount for the option "INS" in EUR.
*
* @param int|float $value
* @return void
*/
public function setInsured($value): void
{
$this->insured = $value;
}
public function toArray(): array
{
return collect()
->when($this->delivery_type !== 'PS', function ($collection) {
return $collection->push([
'key' => $this->delivery_type,
]);
})
->when($this->delivery_type === 'PS', function ($collection) {
return $collection->push([
'key' => $this->delivery_type,
'input' => $this->service_point_id,
]);
})
->when(! empty($this->cash_on_delivery), function ($collection) {
return $collection->push([
'key' => 'COD_CASH',
'input' => $this->cash_on_delivery,
]);
})
->when(! empty($this->label_description), function ($collection) {
return $collection->push([
'key' => 'REFERENCE',
'input' => $this->label_description,
]);
})
->when($this->signature, function ($collection) {
return $collection->push([
'key' => 'HANDT',
]);
})
->when($this->only_recipient, function ($collection) {
return $collection->push([
'key' => 'NBB',
]);
})
->when($this->extra_assurance, function ($collection) {
return $collection->push([
'key' => 'EA',
]);
})
->when($this->evening_delivery, function ($collection) {
return $collection->push([
'key' => 'EVE',
]);
})
->when($this->insured, function ($collection) {
return $collection->push([
'key' => 'INS',
'input' => $this->insured,
]);
})
->all();
}
}