1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VasilDakov\Speedy\Model; |
6
|
|
|
|
7
|
|
|
use VasilDakov\Speedy\Exception\InvalidArgumentException; |
8
|
|
|
use VasilDakov\Speedy\Shipment\ShipmentDiscountCardId; |
9
|
|
|
use JMS\Serializer\Annotation as Serializer; |
10
|
|
|
use VasilDakov\Speedy\ToArray; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Payment |
14
|
|
|
* |
15
|
|
|
* @Serializer\AccessType("public_method") |
16
|
|
|
* @author Vasil Dakov <[email protected]> |
17
|
|
|
* @copyright 2009-2022 Neutrino.bg |
18
|
|
|
* @version 1.0 |
19
|
|
|
*/ |
20
|
|
|
class Payment |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
use ToArray; |
24
|
|
|
|
25
|
|
|
public const SENDER = 'SENDER'; |
26
|
|
|
public const RECIPIENT = 'RECIPIENT'; |
27
|
|
|
public const THIRD_PARTY = 'THIRD_PARTY'; |
28
|
|
|
|
29
|
|
|
public const PAYER_OPTIONS = [ |
30
|
|
|
self::SENDER, |
31
|
|
|
self::RECIPIENT, |
32
|
|
|
self::THIRD_PARTY |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string|null |
37
|
|
|
* @Serializer\Type("string") |
38
|
|
|
*/ |
39
|
|
|
private ?string $courierServicePayer = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string|null |
43
|
|
|
* @Serializer\Type("string") |
44
|
|
|
*/ |
45
|
|
|
private ?string $declaredValuePayer = null; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string|null |
49
|
|
|
* @Serializer\Type("string") |
50
|
|
|
*/ |
51
|
|
|
private ?string $packagePayer = null; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var int|null |
55
|
|
|
* @Serializer\Type("int") |
56
|
|
|
*/ |
57
|
|
|
private ?int $thirdPartyClientId = null; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var ShipmentDiscountCardId|null |
61
|
|
|
* @Serializer\Type("VasilDakov\Speedy\Shipment\ShipmentDiscountCardId") |
62
|
|
|
*/ |
63
|
|
|
private ?ShipmentDiscountCardId $discountCardId = null; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var CODPayment|null |
67
|
|
|
* @Serializer\Type("VasilDakov\Speedy\Model\CODPayment") |
68
|
|
|
*/ |
69
|
|
|
private ?CODPayment $codPayment = null; |
70
|
|
|
|
71
|
|
|
/** |
72
|
2 |
|
* @return string|null |
73
|
|
|
*/ |
74
|
2 |
|
public function getCourierServicePayer(): ?string |
75
|
|
|
{ |
76
|
|
|
return $this->courierServicePayer; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
2 |
|
* @param string $courierServicePayer |
81
|
|
|
*/ |
82
|
2 |
|
public function setCourierServicePayer(string $courierServicePayer): void |
83
|
1 |
|
{ |
84
|
|
|
if (! $this->isValidPayer($courierServicePayer)) { |
85
|
1 |
|
throw new InvalidArgumentException(); |
86
|
|
|
} |
87
|
|
|
$this->courierServicePayer = $courierServicePayer; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
2 |
|
* @return string|null |
92
|
|
|
*/ |
93
|
2 |
|
public function getDeclaredValuePayer(): ?string |
94
|
|
|
{ |
95
|
|
|
return $this->declaredValuePayer; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
2 |
|
* @param string $declaredValuePayer |
100
|
|
|
*/ |
101
|
2 |
|
public function setDeclaredValuePayer(string $declaredValuePayer): void |
102
|
1 |
|
{ |
103
|
|
|
if (! $this->isValidPayer($declaredValuePayer)) { |
104
|
1 |
|
throw new InvalidArgumentException(); |
105
|
|
|
} |
106
|
|
|
$this->declaredValuePayer = $declaredValuePayer; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
2 |
|
* @return string|null |
111
|
|
|
*/ |
112
|
2 |
|
public function getPackagePayer(): ?string |
113
|
|
|
{ |
114
|
|
|
return $this->packagePayer; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
2 |
|
* @param string $packagePayer |
119
|
|
|
*/ |
120
|
2 |
|
public function setPackagePayer(string $packagePayer): void |
121
|
1 |
|
{ |
122
|
|
|
if (! $this->isValidPayer($packagePayer)) { |
123
|
1 |
|
throw new InvalidArgumentException(); |
124
|
|
|
} |
125
|
|
|
$this->packagePayer = $packagePayer; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
2 |
|
* @return int|null |
130
|
|
|
*/ |
131
|
2 |
|
public function getThirdPartyClientId(): ?int |
132
|
|
|
{ |
133
|
|
|
return $this->thirdPartyClientId; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
1 |
|
* @param int $thirdPartyClientId |
138
|
|
|
*/ |
139
|
1 |
|
public function setThirdPartyClientId(int $thirdPartyClientId): void |
140
|
|
|
{ |
141
|
|
|
$this->thirdPartyClientId = $thirdPartyClientId; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
2 |
|
* @return ShipmentDiscountCardId|null |
146
|
|
|
*/ |
147
|
2 |
|
public function getDiscountCardId(): ?ShipmentDiscountCardId |
148
|
|
|
{ |
149
|
|
|
return $this->discountCardId; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
1 |
|
* @param ShipmentDiscountCardId $discountCardId |
154
|
|
|
*/ |
155
|
1 |
|
public function setDiscountCardId(ShipmentDiscountCardId $discountCardId): void |
156
|
|
|
{ |
157
|
|
|
$this->discountCardId = $discountCardId; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
2 |
|
* @return CODPayment|null |
162
|
|
|
*/ |
163
|
2 |
|
public function getCodPayment(): ?CODPayment |
164
|
|
|
{ |
165
|
|
|
return $this->codPayment; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
1 |
|
* @param CODPayment $codPayment |
170
|
|
|
*/ |
171
|
1 |
|
public function setCodPayment(CODPayment $codPayment): void |
172
|
|
|
{ |
173
|
|
|
$this->codPayment = $codPayment; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param string $payer |
178
|
4 |
|
* @return bool |
179
|
|
|
*/ |
180
|
4 |
|
private function isValidPayer(string $payer): bool |
181
|
1 |
|
{ |
182
|
|
|
if (\in_array($payer, self::PAYER_OPTIONS)) { |
183
|
3 |
|
return true; |
184
|
|
|
} |
185
|
|
|
return false; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
1 |
|
* @return array |
190
|
|
|
*/ |
191
|
1 |
|
/*public function toArray(): array |
192
|
1 |
|
{ |
193
|
1 |
|
$array = [ |
194
|
1 |
|
'courierServicePayer' => $this->getCourierServicePayer(), |
195
|
1 |
|
'declaredValuePayer' => $this->getDeclaredValuePayer(), |
196
|
1 |
|
'packagePayer' => $this->getPackagePayer(), |
197
|
|
|
'thirdPartyClientId' => $this->getThirdPartyClientId(), |
198
|
1 |
|
]; |
199
|
|
|
|
200
|
|
|
if ($this->discountCardId instanceof ShipmentDiscountCardId) { |
201
|
|
|
$array['discountCardId'] = $this->discountCardId->toArray(); |
202
|
1 |
|
} |
203
|
|
|
|
204
|
|
|
if ($this->codPayment instanceof CODPayment) { |
205
|
|
|
$array['codPayment'] = $this->codPayment->toArray(); |
206
|
|
|
} |
207
|
|
|
|
208
|
1 |
|
return $array; |
209
|
|
|
}*/ |
210
|
|
|
} |
211
|
|
|
|