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