Completed
Branch master (eebe0d)
by Gregorio
02:31 queued 50s
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

Importance

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