1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\Spreedly; |
4
|
|
|
|
5
|
|
|
use Omnipay\Common\AbstractGateway; |
6
|
|
|
use Omnipay\Spreedly\Concerns\HasSpreedlyConfig; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Spreedly Gateway |
10
|
|
|
*/ |
11
|
|
|
class Gateway extends AbstractGateway |
12
|
|
|
{ |
13
|
|
|
use HasSpreedlyConfig; |
14
|
|
|
|
15
|
2 |
|
public function getName() |
16
|
|
|
{ |
17
|
2 |
|
return 'Spreedly'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param array $options |
22
|
|
|
* @return Message\AuthorizeRequest |
23
|
|
|
*/ |
24
|
8 |
|
public function authorize(array $options = array()) |
25
|
|
|
{ |
26
|
8 |
|
return $this->createRequest('Omnipay\Spreedly\Message\AuthorizeRequest', $options); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param array $options |
31
|
|
|
* @return Message\CaptureRequest |
32
|
|
|
*/ |
33
|
8 |
|
public function capture(array $options = array()) |
34
|
|
|
{ |
35
|
8 |
|
return $this->createRequest('Omnipay\Spreedly\Message\CaptureRequest', $options); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param array $options |
40
|
|
|
* @return Message\PurchaseRequest |
41
|
|
|
*/ |
42
|
8 |
|
public function purchase(array $options = array()) |
43
|
|
|
{ |
44
|
8 |
|
return $this->createRequest('Omnipay\Spreedly\Message\PurchaseRequest', $options); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param array $options |
49
|
|
|
* @return Message\RefundRequest |
50
|
|
|
*/ |
51
|
8 |
|
public function refund(array $options = array()) |
52
|
|
|
{ |
53
|
8 |
|
return $this->createRequest('Omnipay\Spreedly\Message\RefundRequest', $options); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param array $options |
58
|
|
|
* @return Message\VoidRequest |
59
|
|
|
*/ |
60
|
10 |
|
public function void(array $options = array()) |
61
|
|
|
{ |
62
|
10 |
|
return $this->createRequest('Omnipay\Spreedly\Message\VoidRequest', $options); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param array $options |
67
|
|
|
* @return Message\CreatePaymentMethodRequest |
68
|
|
|
*/ |
69
|
8 |
|
public function createCard(array $options = array()) |
70
|
|
|
{ |
71
|
8 |
|
return $this->createRequest('Omnipay\Spreedly\Message\CreatePaymentMethodRequest', $options); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param array $options |
76
|
|
|
* @return Message\UpdatePaymentMethodRequest |
77
|
|
|
*/ |
78
|
8 |
|
public function updateCard(array $options = array()) |
79
|
|
|
{ |
80
|
8 |
|
return $this->createRequest('Omnipay\Spreedly\Message\UpdatePaymentMethodRequest', $options); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param array $options |
85
|
|
|
* @return Message\RetainPaymentMethodRequest |
86
|
|
|
*/ |
87
|
4 |
|
public function retainCard(array $options = array()) |
88
|
|
|
{ |
89
|
4 |
|
return $this->createRequest('Omnipay\Spreedly\Message\RetainPaymentMethodRequest', $options); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param array $options |
94
|
|
|
* @return Message\StorePaymentMethodRequest |
95
|
|
|
*/ |
96
|
2 |
|
public function storeCard(array $options = array()) |
97
|
|
|
{ |
98
|
2 |
|
return $this->createRequest('Omnipay\Spreedly\Message\StorePaymentMethodRequest', $options); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param array $options |
103
|
|
|
* @return Message\DeletePaymentMethodRequest |
104
|
|
|
*/ |
105
|
8 |
|
public function deleteCard(array $options = array()) |
106
|
|
|
{ |
107
|
8 |
|
return $this->createRequest('Omnipay\Spreedly\Message\DeletePaymentMethodRequest', $options); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param array $options |
112
|
|
|
* @return Message\FetchPaymentMethodRequest |
113
|
|
|
*/ |
114
|
4 |
|
public function fetchCard(array $options = array()) |
115
|
|
|
{ |
116
|
4 |
|
return $this->createRequest('Omnipay\Spreedly\Message\FetchPaymentMethodRequest', $options); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param array $options |
121
|
|
|
* @return Message\ListPaymentMethodsRequest |
122
|
|
|
*/ |
123
|
4 |
|
public function listCards(array $options = array()) |
124
|
|
|
{ |
125
|
4 |
|
return $this->createRequest('Omnipay\Spreedly\Message\ListPaymentMethodsRequest', $options); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param array $options |
130
|
|
|
* @return Message\CreatePaymentMethodRequest |
131
|
|
|
*/ |
132
|
4 |
|
public function createPaymentMethod(array $options = array()) |
133
|
|
|
{ |
134
|
4 |
|
return $this->createRequest('Omnipay\Spreedly\Message\CreatePaymentMethodRequest', $options); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param array $options |
139
|
|
|
* @return Message\UpdatePaymentMethodRequest |
140
|
|
|
*/ |
141
|
4 |
|
public function updatePaymentMethod(array $options = array()) |
142
|
|
|
{ |
143
|
4 |
|
return $this->createRequest('Omnipay\Spreedly\Message\UpdatePaymentMethodRequest', $options); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param array $options |
148
|
|
|
* @return Message\RetainPaymentMethodRequest |
149
|
|
|
*/ |
150
|
4 |
|
public function retainPaymentMethod(array $options = array()) |
151
|
|
|
{ |
152
|
4 |
|
return $this->createRequest('Omnipay\Spreedly\Message\RetainPaymentMethodRequest', $options); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param array $options |
157
|
|
|
* @return Message\StorePaymentMethodRequest |
158
|
|
|
*/ |
159
|
2 |
|
public function storePaymentMethod(array $options = array()) |
160
|
|
|
{ |
161
|
2 |
|
return $this->createRequest('Omnipay\Spreedly\Message\StorePaymentMethodRequest', $options); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param array $options |
166
|
|
|
* @return Message\DeletePaymentMethodRequest |
167
|
|
|
*/ |
168
|
4 |
|
public function deletePaymentMethod(array $options = array()) |
169
|
|
|
{ |
170
|
4 |
|
return $this->createRequest('Omnipay\Spreedly\Message\DeletePaymentMethodRequest', $options); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param array $options |
175
|
|
|
* @return Message\FetchPaymentMethodRequest |
176
|
|
|
*/ |
177
|
4 |
|
public function fetchPaymentMethod(array $options = array()) |
178
|
|
|
{ |
179
|
4 |
|
return $this->createRequest('Omnipay\Spreedly\Message\FetchPaymentMethodRequest', $options); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param array $options |
184
|
|
|
* @return Message\ListPaymentMethodsRequest |
185
|
|
|
*/ |
186
|
4 |
|
public function listPaymentMethods(array $options = array()) |
187
|
|
|
{ |
188
|
4 |
|
return $this->createRequest('Omnipay\Spreedly\Message\ListPaymentMethodsRequest', $options); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param array $options |
193
|
|
|
* @return Message\ListGatewaysRequest |
194
|
|
|
*/ |
195
|
8 |
|
public function listGateways(array $options = array()) |
196
|
|
|
{ |
197
|
8 |
|
return $this->createRequest('Omnipay\Spreedly\Message\ListGatewaysRequest', $options); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param array $options |
202
|
|
|
* @return Message\CreateGatewayRequest |
203
|
|
|
*/ |
204
|
6 |
|
public function createGateway(array $options = array()) |
205
|
|
|
{ |
206
|
6 |
|
return $this->createRequest('Omnipay\Spreedly\Message\CreateGatewayRequest', $options); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param array $gatewayToken |
211
|
|
|
* @return $this |
212
|
|
|
*/ |
213
|
4 |
|
public function addGatewayToken($gatewayToken) |
214
|
|
|
{ |
215
|
4 |
|
$tokens = $this->getGatewaysTokens(); |
216
|
|
|
|
217
|
4 |
|
$tokens[] = $gatewayToken; |
218
|
|
|
|
219
|
4 |
|
return $this->setGatewaysTokens($tokens); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @param array $options |
224
|
|
|
* @return array|null |
225
|
|
|
*/ |
226
|
2 |
|
public function addGateway(array $options = array()) |
227
|
|
|
{ |
228
|
|
|
/** @var Message\CreateGatewayRequest $request */ |
229
|
2 |
|
$request = $this->createGateway($options); |
230
|
|
|
|
231
|
|
|
/** @var Message\Response $response */ |
232
|
2 |
|
$response = $request->send(); |
233
|
|
|
|
234
|
2 |
|
if ($response->isSuccessful()) { |
235
|
2 |
|
$data = $response->getData(); |
236
|
|
|
|
237
|
|
|
$gatewayToken = array( |
238
|
2 |
|
'type' => $data['gateway_type'], |
239
|
2 |
|
'token' => $data['token'], |
240
|
2 |
|
); |
241
|
|
|
|
242
|
2 |
|
$this->addGatewayToken($gatewayToken); |
243
|
|
|
|
244
|
2 |
|
return $gatewayToken; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return null; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Load previously created gateways |
252
|
|
|
*/ |
253
|
2 |
|
public function loadGateways() |
254
|
|
|
{ |
255
|
2 |
|
$response = $this->listGateways()->send(); |
256
|
|
|
|
257
|
2 |
|
if ($response->isSuccessful()) { |
258
|
2 |
|
foreach ($response->getData() as $gateway) { |
259
|
2 |
|
$this->addGatewayToken(array( |
260
|
2 |
|
'type' => $gateway['gateway_type'], |
261
|
2 |
|
'token' => $gateway['token'], |
262
|
2 |
|
)); |
263
|
2 |
|
} |
264
|
2 |
|
} |
265
|
|
|
|
266
|
2 |
|
return $this; |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
|