1
|
|
|
<?php |
2
|
|
|
namespace Omnipay\ZipPay\Message; |
3
|
|
|
|
4
|
|
|
use Omnipay\ZipPay\ItemInterface; |
5
|
|
|
use Omnipay\ZipPay\Message\RestAuthorizeResponse; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Authorize Request |
9
|
|
|
* |
10
|
|
|
* @method Response send() |
11
|
|
|
*/ |
12
|
|
|
class RestAuthorizeRequest extends AbstractRequest |
13
|
|
|
{ |
14
|
6 |
|
public function getEndpoint() |
15
|
|
|
{ |
16
|
6 |
|
return parent::getEndpoint() . '/checkouts'; |
17
|
|
|
} |
18
|
|
|
|
19
|
6 |
|
public function getHttpMethod() |
20
|
|
|
{ |
21
|
6 |
|
return 'POST'; |
22
|
|
|
} |
23
|
|
|
|
24
|
6 |
|
public function getFirstName() |
25
|
|
|
{ |
26
|
6 |
|
return $this->getCard()->getFirstName(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function setFirstName($value) |
30
|
|
|
{ |
31
|
|
|
return $this->getCard()->setFirstName($value); |
32
|
|
|
} |
33
|
|
|
|
34
|
6 |
|
public function getLastName() |
35
|
|
|
{ |
36
|
6 |
|
return $this->getCard()->getLastName(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function setLastName($value) |
40
|
|
|
{ |
41
|
|
|
return $this->getCard()->setLastName($value); |
42
|
|
|
} |
43
|
|
|
|
44
|
6 |
|
public function getEmail() |
45
|
|
|
{ |
46
|
6 |
|
return $this->getCard()->getEmail(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setEmail($value) |
50
|
|
|
{ |
51
|
|
|
return $this->getCard()->setEmail($value); |
52
|
|
|
} |
53
|
|
|
|
54
|
6 |
|
public function getReference() |
55
|
|
|
{ |
56
|
6 |
|
return $this->getParameter('reference'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setReference($value) |
60
|
|
|
{ |
61
|
|
|
return $this->setParameter('reference', $value); |
62
|
|
|
} |
63
|
|
|
|
64
|
6 |
|
public function getMeta() |
65
|
|
|
{ |
66
|
6 |
|
return $this->getParameter('meta'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function setMeta($value) |
70
|
|
|
{ |
71
|
|
|
return $this->setParameter('meta', $value); |
72
|
|
|
} |
73
|
|
|
|
74
|
6 |
|
public function hasMetaData() |
75
|
|
|
{ |
76
|
6 |
|
return !empty($this->getMeta()); |
77
|
|
|
} |
78
|
|
|
|
79
|
6 |
|
public function getData() |
80
|
|
|
{ |
81
|
6 |
|
$this->validate( |
82
|
6 |
|
'amount', |
83
|
6 |
|
'currency', |
84
|
4 |
|
'returnUrl' |
85
|
2 |
|
); |
86
|
|
|
|
87
|
6 |
|
$data = $this->getBaseData(); |
88
|
|
|
|
89
|
6 |
|
$data['shopper']['first_name'] = $this->getFirstName(); |
90
|
6 |
|
$data['shopper']['last_name'] = $this->getLastName(); |
91
|
6 |
|
$data['shopper']['email'] = $this->getEmail(); |
92
|
6 |
|
$data['shopper']['billing_address'] = $this->getBillingAddress(); |
93
|
6 |
|
$data['order'] = $this->getOrder(); |
94
|
6 |
|
$data['config'] = $this->getConfig(); |
95
|
|
|
|
96
|
6 |
|
if ($this->hasMetaData()) { |
97
|
|
|
$data['metadata'] = $this->getMetaData(); |
98
|
|
|
} |
99
|
|
|
|
100
|
6 |
|
return $data; |
101
|
|
|
} |
102
|
|
|
|
103
|
6 |
|
public function getBillingAddress() |
104
|
|
|
{ |
105
|
|
|
return [ |
106
|
6 |
|
'line1' => $this->getBillingAddressLine1(), |
107
|
6 |
|
'city' => $this->getBillingAddressCity(), |
108
|
6 |
|
'state' => $this->getBillingAddressState(), |
109
|
6 |
|
'postal_code' => $this->getBillingAddressPostalCode(), |
110
|
6 |
|
'country' => $this->getBillingAddressCountry(), |
111
|
6 |
|
'first_name' => $this->getBillingAddressFirstName(), |
112
|
6 |
|
'last_name' => $this->getBillingAddressLastName(), |
113
|
2 |
|
]; |
114
|
|
|
} |
115
|
|
|
|
116
|
6 |
|
public function getOrder() |
117
|
|
|
{ |
118
|
|
|
return [ |
119
|
6 |
|
'reference' => $this->getReference(), |
120
|
6 |
|
'amount' => $this->getAmount(), |
121
|
6 |
|
'currency' => $this->getCurrency(), |
122
|
6 |
|
'shipping' => $this->getOrderShippingDetails(), |
123
|
6 |
|
'items' => $this->getOrderItems(), |
124
|
2 |
|
]; |
125
|
|
|
} |
126
|
|
|
|
127
|
6 |
|
public function getOrderItems() |
128
|
|
|
{ |
129
|
6 |
|
$data = []; |
130
|
6 |
|
$items = $this->getItems(); |
131
|
|
|
|
132
|
6 |
|
if ($items) { |
133
|
|
|
foreach ($items as $item) { |
134
|
|
|
$data[] = $this->convertItemToItemData($item); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
6 |
|
return $data; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
protected function convertItemToItemData(ItemInterface $item) |
142
|
|
|
{ |
143
|
|
|
return [ |
144
|
|
|
'name' => $item->getName(), |
145
|
|
|
'amount' => $item->getQuantity() * $this->formatCurrency($item->getPrice()), |
146
|
|
|
'quantity' => $item->getQuantity(), |
147
|
|
|
'type' => 'sku', |
148
|
|
|
'reference' => $item->getReference(), |
149
|
|
|
'image_uri' => $item->getImageUri(), |
150
|
|
|
]; |
151
|
|
|
} |
152
|
|
|
|
153
|
6 |
|
public function getOrderShippingDetails() |
154
|
|
|
{ |
155
|
|
|
return [ |
156
|
6 |
|
'pickup' => true, |
157
|
2 |
|
]; |
158
|
|
|
} |
159
|
|
|
|
160
|
6 |
|
public function getConfig() |
161
|
|
|
{ |
162
|
|
|
return [ |
163
|
6 |
|
'redirect_uri' => $this->getReturnUrl(), |
164
|
2 |
|
]; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function getMetaData() |
168
|
|
|
{ |
169
|
|
|
return $this->getMeta(); |
170
|
|
|
} |
171
|
|
|
|
172
|
6 |
|
public function getBillingAddressLine1() |
173
|
|
|
{ |
174
|
6 |
|
return $this->getCard()->getBillingAddress1(); |
175
|
|
|
} |
176
|
|
|
|
177
|
6 |
|
public function getBillingAddressCity() |
178
|
|
|
{ |
179
|
6 |
|
return $this->getCard()->getBillingCity(); |
180
|
|
|
} |
181
|
|
|
|
182
|
6 |
|
public function getBillingAddressState() |
183
|
|
|
{ |
184
|
6 |
|
return $this->getCard()->getBillingState(); |
185
|
|
|
} |
186
|
|
|
|
187
|
6 |
|
public function getBillingAddressPostalCode() |
188
|
|
|
{ |
189
|
6 |
|
return $this->getCard()->getBillingPostcode(); |
190
|
|
|
} |
191
|
|
|
|
192
|
6 |
|
public function getBillingAddressCountry() |
193
|
|
|
{ |
194
|
6 |
|
return $this->getCard()->getBillingCountry(); |
195
|
|
|
} |
196
|
|
|
|
197
|
6 |
|
public function getBillingAddressFirstName() |
198
|
|
|
{ |
199
|
6 |
|
return $this->getCard()->getBillingFirstName(); |
200
|
|
|
} |
201
|
|
|
|
202
|
6 |
|
public function getBillingAddressLastName() |
203
|
|
|
{ |
204
|
6 |
|
return $this->getCard()->getBillingLastName(); |
205
|
|
|
} |
206
|
|
|
|
207
|
6 |
|
protected function createResponse($data, $headers = [], $status = 404) |
208
|
|
|
{ |
209
|
6 |
|
return $this->response = new RestAuthorizeResponse($this, $data, $headers, $status); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|