Completed
Push — master ( 2d17ac...dc6fd0 )
by Gregorio
02:39
created

Gateway::loadGateways()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0327

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 11
cts 13
cp 0.8462
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 2
nop 0
crap 3.0327
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\DeletePaymentMethodRequest
95
     */
96 8
    public function deleteCard(array $options = array())
97
    {
98 8
        return $this->createRequest('Omnipay\Spreedly\Message\DeletePaymentMethodRequest', $options);
99
    }
100
101
    /**
102
     * @param array $options
103
     * @return Message\FetchPaymentMethodRequest
104
     */
105 4
    public function fetchCard(array $options = array())
106
    {
107 4
        return $this->createRequest('Omnipay\Spreedly\Message\FetchPaymentMethodRequest', $options);
108
    }
109
110
    /**
111
     * @param array $options
112
     * @return Message\ListPaymentMethodsRequest
113
     */
114 4
    public function listCards(array $options = array())
115
    {
116 4
        return $this->createRequest('Omnipay\Spreedly\Message\ListPaymentMethodsRequest', $options);
117
    }
118
119
    /**
120
     * @param array $options
121
     * @return Message\CreatePaymentMethodRequest
122
     */
123 4
    public function createPaymentMethod(array $options = array())
124
    {
125 4
        return $this->createRequest('Omnipay\Spreedly\Message\CreatePaymentMethodRequest', $options);
126
    }
127
128
    /**
129
     * @param array $options
130
     * @return Message\UpdatePaymentMethodRequest
131
     */
132 4
    public function updatePaymentMethod(array $options = array())
133
    {
134 4
        return $this->createRequest('Omnipay\Spreedly\Message\UpdatePaymentMethodRequest', $options);
135
    }
136
137
    /**
138
     * @param array $options
139
     * @return Message\RetainPaymentMethodRequest
140
     */
141 4
    public function retainPaymentMethod(array $options = array())
142
    {
143 4
        return $this->createRequest('Omnipay\Spreedly\Message\RetainPaymentMethodRequest', $options);
144
    }
145
146
    /**
147
     * @param array $options
148
     * @return Message\DeletePaymentMethodRequest
149
     */
150 4
    public function deletePaymentMethod(array $options = array())
151
    {
152 4
        return $this->createRequest('Omnipay\Spreedly\Message\DeletePaymentMethodRequest', $options);
153
    }
154
155
    /**
156
     * @param array $options
157
     * @return Message\FetchPaymentMethodRequest
158
     */
159 4
    public function fetchPaymentMethod(array $options = array())
160
    {
161 4
        return $this->createRequest('Omnipay\Spreedly\Message\FetchPaymentMethodRequest', $options);
162
    }
163
164
    /**
165
     * @param array $options
166
     * @return Message\ListPaymentMethodsRequest
167
     */
168 4
    public function listPaymentMethods(array $options = array())
169
    {
170 4
        return $this->createRequest('Omnipay\Spreedly\Message\ListPaymentMethodsRequest', $options);
171
    }
172
173
    /**
174
     * @param array $options
175
     * @return Message\ListGatewaysRequest
176
     */
177 8
    public function listGateways(array $options = array())
178
    {
179 8
        return $this->createRequest('Omnipay\Spreedly\Message\ListGatewaysRequest', $options);
180
    }
181
182
    /**
183
     * @param array $options
184
     * @return Message\CreateGatewayRequest
185
     */
186 6
    public function createGateway(array $options = array())
187
    {
188 6
        return $this->createRequest('Omnipay\Spreedly\Message\CreateGatewayRequest', $options);
189
    }
190
191
    /**
192
     * @param array $gatewayToken
193
     * @return $this
194
     */
195 4
    public function addGatewayToken($gatewayToken)
196
    {
197 4
        $tokens = $this->getGatewaysTokens();
198
199 4
        $tokens[] = $gatewayToken;
200
201 4
        return $this->setGatewaysTokens($tokens);
202
    }
203
204
    /**
205
     * @param array $options
206
     * @return array|null
207
     */
208 2
    public function addGateway(array $options = array())
209
    {
210
        /** @var Message\CreateGatewayRequest $request */
211 2
        $request = $this->createGateway($options);
212
213
        /** @var Message\Response $response */
214 2
        $response = $request->send();
215
216 2
        if ($response->isSuccessful()) {
217 2
            $data = $response->getData();
218
219
            $gatewayToken = [
220 2
                'type' => $data['gateway_type'],
221 2
                'token' => $data['token'],
222 2
            ];
223
224 2
            $this->addGatewayToken($gatewayToken);
225
226 2
            return $gatewayToken;
227
        }
228
229
        return null;
230
    }
231
232
    /**
233
     * Load previously created gateways
234
     */
235 2
    public function loadGateways()
236
    {
237 2
        $response = $this->listGateways()->send();
238
239 2
        if ($response->isSuccessful()) {
240 2
            foreach ($response->getData() as $gateway) {
241 2
                $this->addGatewayToken([
242 2
                    'type' => $gateway['gateway_type'],
243 2
                    'token' => $gateway['token'],
244 2
                ]);
245 2
            }
246 2
        }
247
248 2
        return $this;
249
    }
250
}
251