|
1
|
|
|
<?php |
|
2
|
|
|
namespace Omnipay\ZipPay\Message; |
|
3
|
|
|
|
|
4
|
|
|
use Omnipay\ZipPay\ItemInterface; |
|
5
|
|
|
use Omnipay\ZipPay\ItemTypeInterface; |
|
6
|
|
|
use Omnipay\ZipPay\Message\RestAuthorizeResponse; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Authorize Request |
|
10
|
|
|
* |
|
11
|
|
|
* @method Response send() |
|
12
|
|
|
*/ |
|
13
|
|
|
class RestAuthorizeRequest extends AbstractRequest |
|
14
|
6 |
|
{ |
|
15
|
|
|
public function getEndpoint() |
|
16
|
6 |
|
{ |
|
17
|
|
|
return parent::getEndpoint() . '/checkouts'; |
|
18
|
|
|
} |
|
19
|
6 |
|
|
|
20
|
|
|
public function getHttpMethod() |
|
21
|
6 |
|
{ |
|
22
|
|
|
return 'POST'; |
|
23
|
|
|
} |
|
24
|
6 |
|
|
|
25
|
|
|
public function getFirstName() |
|
26
|
6 |
|
{ |
|
27
|
|
|
return $this->getCard()->getFirstName(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function setFirstName($value) |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->getCard()->setFirstName($value); |
|
33
|
|
|
} |
|
34
|
6 |
|
|
|
35
|
|
|
public function getLastName() |
|
36
|
6 |
|
{ |
|
37
|
|
|
return $this->getCard()->getLastName(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function setLastName($value) |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->getCard()->setLastName($value); |
|
43
|
|
|
} |
|
44
|
6 |
|
|
|
45
|
|
|
public function getEmail() |
|
46
|
6 |
|
{ |
|
47
|
|
|
return $this->getCard()->getEmail(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function setEmail($value) |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->getCard()->setEmail($value); |
|
53
|
|
|
} |
|
54
|
6 |
|
|
|
55
|
|
|
public function getReference() |
|
56
|
6 |
|
{ |
|
57
|
|
|
return $this->getParameter('reference'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function setReference($value) |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->setParameter('reference', $value); |
|
63
|
|
|
} |
|
64
|
6 |
|
|
|
65
|
|
|
public function getMeta() |
|
66
|
6 |
|
{ |
|
67
|
|
|
return $this->getParameter('meta'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function setMeta($value) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->setParameter('meta', $value); |
|
73
|
|
|
} |
|
74
|
6 |
|
|
|
75
|
|
|
public function hasMetaData() |
|
76
|
6 |
|
{ |
|
77
|
|
|
return !empty($this->getMeta()); |
|
78
|
|
|
} |
|
79
|
6 |
|
|
|
80
|
|
|
public function getHasShippingAddress() |
|
81
|
6 |
|
{ |
|
82
|
6 |
|
return $this->getParameter('hasShippingAddress'); |
|
83
|
6 |
|
} |
|
84
|
4 |
|
|
|
85
|
2 |
|
public function setHasShippingAddress($value) |
|
86
|
|
|
{ |
|
87
|
6 |
|
return $this->setParameter('hasShippingAddress', $value); |
|
88
|
|
|
} |
|
89
|
6 |
|
|
|
90
|
6 |
|
public function getData() |
|
91
|
6 |
|
{ |
|
92
|
6 |
|
$this->validate( |
|
93
|
6 |
|
'amount', |
|
94
|
6 |
|
'currency', |
|
95
|
|
|
'returnUrl' |
|
96
|
6 |
|
); |
|
97
|
|
|
|
|
98
|
|
|
$data = $this->getBaseData(); |
|
99
|
|
|
|
|
100
|
6 |
|
$data['shopper']['first_name'] = $this->getFirstName(); |
|
101
|
|
|
$data['shopper']['last_name'] = $this->getLastName(); |
|
102
|
|
|
$data['shopper']['email'] = $this->getEmail(); |
|
103
|
6 |
|
$data['shopper']['billing_address'] = $this->getBillingAddress(); |
|
104
|
|
|
$data['order'] = $this->getOrder(); |
|
105
|
|
|
$data['config'] = $this->getConfig(); |
|
106
|
6 |
|
|
|
107
|
6 |
|
if ($this->hasMetaData()) { |
|
108
|
6 |
|
$data['metadata'] = $this->getMetaData(); |
|
109
|
6 |
|
} |
|
110
|
6 |
|
|
|
111
|
6 |
|
return $data; |
|
112
|
6 |
|
} |
|
113
|
2 |
|
|
|
114
|
|
|
public function getBillingAddress() |
|
115
|
|
|
{ |
|
116
|
6 |
|
return [ |
|
117
|
|
|
'line1' => $this->getBillingAddressLine1(), |
|
118
|
|
|
'city' => $this->getBillingAddressCity(), |
|
119
|
6 |
|
'state' => $this->getBillingAddressState(), |
|
120
|
6 |
|
'postal_code' => $this->getBillingAddressPostalCode(), |
|
121
|
6 |
|
'country' => $this->getBillingAddressCountry(), |
|
122
|
6 |
|
'first_name' => $this->getBillingAddressFirstName(), |
|
123
|
6 |
|
'last_name' => $this->getBillingAddressLastName(), |
|
124
|
2 |
|
]; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
6 |
|
public function getOrder() |
|
128
|
|
|
{ |
|
129
|
6 |
|
return [ |
|
130
|
6 |
|
'reference' => $this->getReference(), |
|
131
|
|
|
'amount' => $this->getAmount(), |
|
132
|
6 |
|
'currency' => $this->getCurrency(), |
|
133
|
|
|
'shipping' => $this->getOrderShippingDetails(), |
|
134
|
|
|
'items' => $this->getOrderItems(), |
|
135
|
|
|
]; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
6 |
|
public function getOrderItems() |
|
139
|
|
|
{ |
|
140
|
|
|
$data = []; |
|
141
|
|
|
$items = $this->getItems(); |
|
142
|
|
|
|
|
143
|
|
|
if ($items) { |
|
144
|
|
|
foreach ($items as $item) { |
|
145
|
|
|
$data[] = $this->convertItemToItemData($item); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
return $data; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
protected function convertItemToItemData(ItemInterface $item) |
|
153
|
6 |
|
{ |
|
154
|
|
|
return [ |
|
155
|
|
|
'name' => $item->getName(), |
|
156
|
6 |
|
'amount' => $this->formatCurrency($item->getPrice()), |
|
157
|
2 |
|
'quantity' => $item->getQuantity(), |
|
158
|
|
|
'type' => $item instanceof ItemTypeInterface ? $item->getType() : 'sku', |
|
159
|
|
|
'reference' => $item->getReference(), |
|
160
|
6 |
|
'image_uri' => $item->getImageUri(), |
|
161
|
|
|
]; |
|
162
|
|
|
} |
|
163
|
6 |
|
|
|
164
|
2 |
|
public function getOrderShippingDetails() |
|
165
|
|
|
{ |
|
166
|
|
|
$shippingDetails = [ |
|
167
|
|
|
'pickup' => true, |
|
168
|
|
|
]; |
|
169
|
|
|
// Check if a shipping address has supposedly been supplied and, if so, set pickup |
|
170
|
|
|
// to `false` and add the address details. |
|
171
|
|
|
if ($this->getHasShippingAddress()) { |
|
172
|
6 |
|
$shippingDetails = [ |
|
173
|
|
|
'pickup' => false, |
|
174
|
6 |
|
'address' => [ |
|
175
|
|
|
'line1' => $this->getShippingAddressLine1(), |
|
176
|
|
|
'line2' => $this->getShippingAddressLine2(), |
|
177
|
6 |
|
'city' => $this->getShippingAddressCity(), |
|
178
|
|
|
'state' => $this->getShippingAddressState(), |
|
179
|
6 |
|
'postal_code' => $this->getShippingAddressPostalCode(), |
|
180
|
|
|
'country' => $this->getShippingAddressCountry(), |
|
181
|
|
|
], |
|
182
|
6 |
|
]; |
|
183
|
|
|
} |
|
184
|
6 |
|
return $shippingDetails; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
6 |
|
public function getConfig() |
|
188
|
|
|
{ |
|
189
|
6 |
|
return [ |
|
190
|
|
|
'redirect_uri' => $this->getReturnUrl(), |
|
191
|
|
|
]; |
|
192
|
6 |
|
} |
|
193
|
|
|
|
|
194
|
6 |
|
public function getMetaData() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->getMeta(); |
|
197
|
6 |
|
} |
|
198
|
|
|
|
|
199
|
6 |
|
public function getBillingAddressLine1() |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->getCard()->getBillingAddress1(); |
|
202
|
6 |
|
} |
|
203
|
|
|
|
|
204
|
6 |
|
public function getBillingAddressCity() |
|
205
|
|
|
{ |
|
206
|
|
|
return $this->getCard()->getBillingCity(); |
|
207
|
6 |
|
} |
|
208
|
|
|
|
|
209
|
6 |
|
public function getBillingAddressState() |
|
210
|
|
|
{ |
|
211
|
|
|
return $this->getCard()->getBillingState(); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
public function getBillingAddressPostalCode() |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->getCard()->getBillingPostcode(); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
public function getBillingAddressCountry() |
|
220
|
|
|
{ |
|
221
|
|
|
return $this->getCard()->getBillingCountry(); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
public function getBillingAddressFirstName() |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->getCard()->getBillingFirstName(); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
public function getBillingAddressLastName() |
|
230
|
|
|
{ |
|
231
|
|
|
return $this->getCard()->getBillingLastName(); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
public function getShippingAddressLine1() |
|
235
|
|
|
{ |
|
236
|
|
|
return $this->getCard()->getShippingAddress1(); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
public function getShippingAddressLine2() |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->getCard()->getShippingAddress2(); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
public function getShippingAddressCity() |
|
245
|
|
|
{ |
|
246
|
|
|
return $this->getCard()->getShippingCity(); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
public function getShippingAddressState() |
|
250
|
|
|
{ |
|
251
|
|
|
return $this->getCard()->getShippingState(); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
public function getShippingAddressPostalCode() |
|
255
|
|
|
{ |
|
256
|
|
|
return $this->getCard()->getShippingPostcode(); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
public function getShippingAddressCountry() |
|
260
|
|
|
{ |
|
261
|
|
|
return $this->getCard()->getShippingCountry(); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
protected function createResponse($data, $headers = [], $status = 404) |
|
265
|
|
|
{ |
|
266
|
|
|
return $this->response = new RestAuthorizeResponse($this, $data, $headers, $status); |
|
267
|
|
|
} |
|
268
|
|
|
} |
|
269
|
|
|
|