Completed
Push — master ( 4a03fb...09659a )
by Gregorio
03:13
created

Gateway::emulateVerifyPaymentMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 10
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2.032
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 10
    public function authorize(array $options = array())
25
    {
26 10
        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 12
    public function void(array $options = array())
61
    {
62 12
        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->createPaymentMethod($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->updatePaymentMethod($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->retainPaymentMethod($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->storePaymentMethod($options);
99
    }
100
101
    /**
102
     * @param array $options
103
     * @return Message\VerifyPaymentMethodRequest
104
     */
105 2
    public function verifyCard(array $options = array())
106
    {
107 2
        return $this->verifyPaymentMethod($options);
108
    }
109
110
    /**
111
     * @param array $options
112
     * @return Message\Response
113
     */
114
    public function emulateVerifyCard(array $options = array())
115
    {
116
        return $this->emulateVerifyPaymentMethod($options);
117
    }
118
119
    /**
120
     * @param array $options
121
     * @return Message\DeletePaymentMethodRequest
122
     */
123 8
    public function deleteCard(array $options = array())
124
    {
125 8
        return $this->deletePaymentMethod($options);
126
    }
127
128
    /**
129
     * @param array $options
130
     * @return Message\FetchPaymentMethodRequest
131
     */
132 4
    public function fetchCard(array $options = array())
133
    {
134 4
        return $this->fetchPaymentMethod($options);
135
    }
136
137
    /**
138
     * @param array $options
139
     * @return Message\ListPaymentMethodsRequest
140
     */
141 4
    public function listCards(array $options = array())
142
    {
143 4
        return $this->listPaymentMethods($options);
144
    }
145
146
    /**
147
     * @param array $options
148
     * @return Message\CreatePaymentMethodRequest
149
     */
150 10
    public function createPaymentMethod(array $options = array())
151
    {
152 10
        return $this->createRequest('Omnipay\Spreedly\Message\CreatePaymentMethodRequest', $options);
153
    }
154
155
    /**
156
     * @param array $options
157
     * @return Message\UpdatePaymentMethodRequest
158
     */
159 10
    public function updatePaymentMethod(array $options = array())
160
    {
161 10
        return $this->createRequest('Omnipay\Spreedly\Message\UpdatePaymentMethodRequest', $options);
162
    }
163
164
    /**
165
     * @param array $options
166
     * @return Message\RetainPaymentMethodRequest
167
     */
168 6
    public function retainPaymentMethod(array $options = array())
169
    {
170 6
        return $this->createRequest('Omnipay\Spreedly\Message\RetainPaymentMethodRequest', $options);
171
    }
172
173
    /**
174
     * @param array $options
175
     * @return Message\StorePaymentMethodRequest
176
     */
177 2
    public function storePaymentMethod(array $options = array())
178
    {
179 2
        return $this->createRequest('Omnipay\Spreedly\Message\StorePaymentMethodRequest', $options);
180
    }
181
182
    /**
183
     * @param array $options
184
     * @return Message\VerifyPaymentMethodRequest
185
     */
186 2
    public function verifyPaymentMethod(array $options = array())
187
    {
188 2
        return $this->createRequest('Omnipay\Spreedly\Message\VerifyPaymentMethodRequest', $options);
189
    }
190
191
    /**
192
     * @param array $options
193
     * @return Message\Response
194
     */
195 2
    public function emulateVerifyPaymentMethod(array $options = array())
196
    {
197 2
        $authorizeResponse = $this->authorize($options)->send();
198
199 2
        if ($authorizeResponse->isSuccessful()) {
200 2
            $this->void([
201 2
                'transactionReference' => $authorizeResponse->getTransactionReference(),
202 2
            ]);
203 2
        }
204
205 2
        return $authorizeResponse;
206
    }
207
208
    /**
209
     * @param array $options
210
     * @return Message\DeletePaymentMethodRequest
211
     */
212 10
    public function deletePaymentMethod(array $options = array())
213
    {
214 10
        return $this->createRequest('Omnipay\Spreedly\Message\DeletePaymentMethodRequest', $options);
215
    }
216
217
    /**
218
     * @param array $options
219
     * @return Message\FetchPaymentMethodRequest
220
     */
221 6
    public function fetchPaymentMethod(array $options = array())
222
    {
223 6
        return $this->createRequest('Omnipay\Spreedly\Message\FetchPaymentMethodRequest', $options);
224
    }
225
226
    /**
227
     * @param array $options
228
     * @return Message\ListPaymentMethodsRequest
229
     */
230 6
    public function listPaymentMethods(array $options = array())
231
    {
232 6
        return $this->createRequest('Omnipay\Spreedly\Message\ListPaymentMethodsRequest', $options);
233
    }
234
235
    /**
236
     * @param array $options
237
     * @return Message\ListGatewaysRequest
238
     */
239 8
    public function listGateways(array $options = array())
240
    {
241 8
        return $this->createRequest('Omnipay\Spreedly\Message\ListGatewaysRequest', $options);
242
    }
243
244
    /**
245
     * @param array $options
246
     * @return Message\CreateGatewayRequest
247
     */
248 6
    public function createGateway(array $options = array())
249
    {
250 6
        return $this->createRequest('Omnipay\Spreedly\Message\CreateGatewayRequest', $options);
251
    }
252
253
    /**
254
     * @param array $gatewayToken
255
     * @return $this
256
     */
257 4
    public function addGatewayToken($gatewayToken)
258
    {
259 4
        $tokens = $this->getGatewaysTokens();
260
261 4
        $tokens[] = $gatewayToken;
262
263 4
        return $this->setGatewaysTokens($tokens);
264
    }
265
266
    /**
267
     * @param array $options
268
     * @return array|null
269
     */
270 2
    public function addGateway(array $options = array())
271
    {
272
        /** @var Message\CreateGatewayRequest $request */
273 2
        $request = $this->createGateway($options);
274
275
        /** @var Message\Response $response */
276 2
        $response = $request->send();
277
278 2
        if ($response->isSuccessful()) {
279 2
            $data = $response->getData();
280
281
            $gatewayToken = array(
282 2
                'type' => $data['gateway_type'],
283 2
                'token' => $data['token'],
284 2
            );
285
286 2
            $this->addGatewayToken($gatewayToken);
287
288 2
            return $gatewayToken;
289
        }
290
291
        return null;
292
    }
293
294
    /**
295
     * Load previously created gateways
296
     */
297 2
    public function loadGateways()
298
    {
299 2
        $response = $this->listGateways()->send();
300
301 2
        if ($response->isSuccessful()) {
302 2
            foreach ($response->getData() as $gateway) {
303 2
                $this->addGatewayToken(array(
304 2
                    'type' => $gateway['gateway_type'],
305 2
                    'token' => $gateway['token'],
306 2
                ));
307 2
            }
308 2
        }
309
310 2
        return $this;
311
    }
312
}
313