1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VasilDakov\Speedy\Model; |
6
|
|
|
|
7
|
|
|
use JMS\Serializer\Annotation as Serializer; |
8
|
|
|
use VasilDakov\Speedy\Exception\InvalidArgumentException; |
9
|
|
|
use VasilDakov\Speedy\Service\Shipment\ShipmentDiscountCardId; |
10
|
|
|
use VasilDakov\Speedy\Traits\ToArray; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Payment. |
14
|
|
|
* |
15
|
|
|
* @Serializer\AccessType("public_method") |
16
|
|
|
* |
17
|
|
|
* @author Vasil Dakov <[email protected]> |
18
|
|
|
* @copyright 2009-2022 Neutrino.bg |
19
|
|
|
* |
20
|
|
|
* @version 1.0 |
21
|
|
|
*/ |
22
|
|
|
class Payment |
23
|
|
|
{ |
24
|
|
|
use ToArray; |
|
|
|
|
25
|
|
|
|
26
|
|
|
public const SENDER = 'SENDER'; |
27
|
|
|
public const RECIPIENT = 'RECIPIENT'; |
28
|
|
|
public const THIRD_PARTY = 'THIRD_PARTY'; |
29
|
|
|
|
30
|
|
|
public const PAYER_OPTIONS = [ |
31
|
|
|
self::SENDER, |
32
|
|
|
self::RECIPIENT, |
33
|
|
|
self::THIRD_PARTY, |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @Serializer\Type("string") |
38
|
|
|
*/ |
39
|
|
|
private ?string $courierServicePayer = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @Serializer\Type("string") |
43
|
|
|
*/ |
44
|
|
|
private ?string $declaredValuePayer = null; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @Serializer\Type("string") |
48
|
|
|
*/ |
49
|
|
|
private ?string $packagePayer = null; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @Serializer\Type("int") |
53
|
|
|
*/ |
54
|
|
|
private ?int $thirdPartyClientId = null; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Serializer\Type("VasilDakov\Speedy\Service\Shipment\ShipmentDiscountCardId") |
58
|
|
|
*/ |
59
|
|
|
private ?ShipmentDiscountCardId $discountCardId = null; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Serializer\Type("VasilDakov\Speedy\Model\CODPayment") |
63
|
|
|
*/ |
64
|
|
|
private ?CODPayment $codPayment = null; |
65
|
|
|
|
66
|
1 |
|
public function getCourierServicePayer(): ?string |
67
|
|
|
{ |
68
|
1 |
|
return $this->courierServicePayer; |
69
|
|
|
} |
70
|
|
|
|
71
|
3 |
|
public function setCourierServicePayer(string $courierServicePayer): void |
72
|
|
|
{ |
73
|
3 |
|
if (! $this->isValidPayer($courierServicePayer)) { |
74
|
1 |
|
throw new InvalidArgumentException(); |
75
|
|
|
} |
76
|
2 |
|
$this->courierServicePayer = $courierServicePayer; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
public function getDeclaredValuePayer(): ?string |
80
|
|
|
{ |
81
|
1 |
|
return $this->declaredValuePayer; |
82
|
|
|
} |
83
|
|
|
|
84
|
3 |
|
public function setDeclaredValuePayer(string $declaredValuePayer): void |
85
|
|
|
{ |
86
|
3 |
|
if (! $this->isValidPayer($declaredValuePayer)) { |
87
|
1 |
|
throw new InvalidArgumentException(); |
88
|
|
|
} |
89
|
2 |
|
$this->declaredValuePayer = $declaredValuePayer; |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
public function getPackagePayer(): ?string |
93
|
|
|
{ |
94
|
1 |
|
return $this->packagePayer; |
95
|
|
|
} |
96
|
|
|
|
97
|
3 |
|
public function setPackagePayer(string $packagePayer): void |
98
|
|
|
{ |
99
|
3 |
|
if (! $this->isValidPayer($packagePayer)) { |
100
|
1 |
|
throw new InvalidArgumentException(); |
101
|
|
|
} |
102
|
2 |
|
$this->packagePayer = $packagePayer; |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
public function getThirdPartyClientId(): ?int |
106
|
|
|
{ |
107
|
1 |
|
return $this->thirdPartyClientId; |
108
|
|
|
} |
109
|
|
|
|
110
|
2 |
|
public function setThirdPartyClientId(int $thirdPartyClientId): void |
111
|
|
|
{ |
112
|
2 |
|
$this->thirdPartyClientId = $thirdPartyClientId; |
113
|
|
|
} |
114
|
|
|
|
115
|
1 |
|
public function getDiscountCardId(): ?ShipmentDiscountCardId |
116
|
|
|
{ |
117
|
1 |
|
return $this->discountCardId; |
118
|
|
|
} |
119
|
|
|
|
120
|
2 |
|
public function setDiscountCardId(ShipmentDiscountCardId $discountCardId): void |
121
|
|
|
{ |
122
|
2 |
|
$this->discountCardId = $discountCardId; |
123
|
|
|
} |
124
|
|
|
|
125
|
1 |
|
public function getCodPayment(): ?CODPayment |
126
|
|
|
{ |
127
|
1 |
|
return $this->codPayment; |
128
|
|
|
} |
129
|
|
|
|
130
|
2 |
|
public function setCodPayment(CODPayment $codPayment): void |
131
|
|
|
{ |
132
|
2 |
|
$this->codPayment = $codPayment; |
133
|
|
|
} |
134
|
|
|
|
135
|
5 |
|
private function isValidPayer(string $payer): bool |
136
|
|
|
{ |
137
|
5 |
|
if (\in_array($payer, self::PAYER_OPTIONS)) { |
138
|
2 |
|
return true; |
139
|
|
|
} |
140
|
|
|
|
141
|
3 |
|
return false; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|