1
|
|
|
<?php |
2
|
|
|
namespace Loevgaard\AltaPay\Payload; |
3
|
|
|
|
4
|
|
|
use Assert\Assert; |
5
|
|
|
|
6
|
|
|
class RefundCapturedReservation extends Payload implements RefundCapturedReservationInterface |
7
|
|
|
{ |
8
|
|
|
use OrderLineArrayTrait; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private $transactionId; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var float |
17
|
|
|
*/ |
18
|
|
|
private $amount; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $reconciliationIdentifier; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var boolean |
27
|
|
|
*/ |
28
|
|
|
private $allowOverRefund; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $invoiceNumber; |
34
|
|
|
|
35
|
|
|
public function __construct(string $transactionId) |
36
|
|
|
{ |
37
|
|
|
$this->transactionId = $transactionId; |
38
|
|
|
$this->orderLines = []; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function getPayload() : array |
45
|
|
|
{ |
46
|
|
|
$payload = [ |
47
|
|
|
'transaction_id' => $this->transactionId, |
48
|
|
|
'amount' => $this->amount, |
49
|
|
|
'reconciliation_identifier' => $this->reconciliationIdentifier, |
50
|
|
|
'allow_over_refund' => is_bool($this->allowOverRefund) ? intval($this->allowOverRefund) : null, |
51
|
|
|
'invoice_number' => $this->invoiceNumber, |
52
|
|
|
'orderLines' => $this->orderLines, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
$this->validate(); |
56
|
|
|
|
57
|
|
|
return static::simplePayload($payload); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function validate() |
61
|
|
|
{ |
62
|
|
|
Assert::that($this->transactionId)->string(); |
63
|
|
|
Assert::thatNullOr($this->amount)->float(); |
64
|
|
|
Assert::thatNullOr($this->reconciliationIdentifier)->string(); |
65
|
|
|
Assert::thatNullOr($this->allowOverRefund)->boolean(); |
66
|
|
|
Assert::thatNullOr($this->invoiceNumber)->string(); |
67
|
|
|
Assert::thatNullOr($this->orderLines)->isArray(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getTransactionId(): string |
74
|
|
|
{ |
75
|
|
|
return $this->transactionId; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $transactionId |
80
|
|
|
* @return RefundCapturedReservation |
81
|
|
|
*/ |
82
|
|
|
public function setTransactionId(string $transactionId) : self |
83
|
|
|
{ |
84
|
|
|
$this->transactionId = $transactionId; |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return float |
90
|
|
|
*/ |
91
|
|
|
public function getAmount(): ?float |
92
|
|
|
{ |
93
|
|
|
return $this->amount; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param float $amount |
98
|
|
|
* @return RefundCapturedReservation |
99
|
|
|
*/ |
100
|
|
|
public function setAmount(float $amount) : self |
101
|
|
|
{ |
102
|
|
|
$this->amount = $amount; |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getReconciliationIdentifier(): ?string |
110
|
|
|
{ |
111
|
|
|
return $this->reconciliationIdentifier; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $reconciliationIdentifier |
116
|
|
|
* @return RefundCapturedReservation |
117
|
|
|
*/ |
118
|
|
|
public function setReconciliationIdentifier(string $reconciliationIdentifier) : self |
119
|
|
|
{ |
120
|
|
|
$this->reconciliationIdentifier = $reconciliationIdentifier; |
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return bool |
126
|
|
|
*/ |
127
|
|
|
public function isAllowOverRefund(): ?bool |
128
|
|
|
{ |
129
|
|
|
return $this->allowOverRefund; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param bool $allowOverRefund |
134
|
|
|
* @return RefundCapturedReservation |
135
|
|
|
*/ |
136
|
|
|
public function setAllowOverRefund(bool $allowOverRefund) : self |
137
|
|
|
{ |
138
|
|
|
$this->allowOverRefund = $allowOverRefund; |
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getInvoiceNumber(): ?string |
146
|
|
|
{ |
147
|
|
|
return $this->invoiceNumber; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $invoiceNumber |
152
|
|
|
* @return RefundCapturedReservation |
153
|
|
|
*/ |
154
|
|
|
public function setInvoiceNumber(string $invoiceNumber) : self |
155
|
|
|
{ |
156
|
|
|
$this->invoiceNumber = $invoiceNumber; |
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|