Passed
Push — master ( c45c86...c44627 )
by Jelle
02:24 queued 12s
created

Gateway   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 189
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0
wmc 16

15 Methods

Rating   Name   Duplication   Size   Complexity  
A setSecretKey() 0 3 1
A getDefaultParameters() 0 6 1
A completeAuthorize() 0 3 1
A refund() 0 3 1
A getContractProfileId() 0 3 1
A getSecretKey() 0 3 1
A getName() 0 3 1
A capture() 0 3 1
A initialize() 0 12 2
A setBaseUrl() 0 3 1
A fetchTransaction() 0 3 1
A setContractProfileId() 0 3 1
A createRequest() 0 5 1
A authorize() 0 3 1
A getBaseUrl() 0 3 1
1
<?php
2
3
namespace Omnipay\IcepayPayments;
4
5
use DateTime;
6
use Omnipay\Common\AbstractGateway;
7
use Omnipay\Common\Message\RequestInterface;
8
use Omnipay\IcepayPayments\Message\CreateTransactionRequest;
9
use Omnipay\IcepayPayments\Message\RefundRequest;
10
use Omnipay\IcepayPayments\Message\TransactionStatusRequest;
11
12
/**
13
 * Icepay gateway for Omnipay.
14
 *
15
 * ### Settings
16
 * - contractProfileId (required): A string provided by Icepay.
17
 * - secretKey         (required): A string provided by Icepay.
18
 * - testMode          (optional): Changes the API to the test API. By default false.
19
 *
20
 * ### Workflow
21
 * 1. The authorize() method initializes a new payment and returns with a purchase url.
22
 * 2. The customer gets redirected to the provided purchase URL to pay with iDEAL or Bancontact.
23
 * 3. Validate payment by doing a status check.
24
 *
25
 * Class Gateway.
26
 */
27
class Gateway extends AbstractGateway
28
{
29
    /**
30
     * @var string
31
     */
32
    public const API_BASE_URL = 'https://interconnect.icepay.com/api';
33
34
    /**
35
     * @var string
36
     */
37
    public const TEST_API_BASE_URL = 'https://acc-interconnect.icepay.com/api';
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @codeCoverageIgnore
43
     */
44
    public function getName(): string
45
    {
46
        return 'Icepay Payments';
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 7
    public function getDefaultParameters(): array
53
    {
54
        return array(
55 7
            'contractProfileId' => '',
56
            'secretKey' => '',
57
            'testMode' => false,
58
        );
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 7
    public function initialize(array $parameters = array()): self
65
    {
66 7
        parent::initialize($parameters);
67
68 7
        $baseUrl = self::API_BASE_URL;
69 7
        if ($this->getTestMode()) {
70 1
            $baseUrl = self::TEST_API_BASE_URL;
71
        }
72
73 7
        $this->setBaseUrl($baseUrl);
74
75 7
        return $this;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 5
    protected function createRequest($class, array $parameters)
82
    {
83 5
        $parameters['timestamp'] = new DateTime();
84
85 5
        return parent::createRequest($class, $parameters); // TODO: Change the autogenerated stub
86
    }
87
88
    /**
89
     * Create an authorize request.
90
     * This is not an 'authorisation function' as icepay puts it, but a 'transaction function'.
91
     *
92
     * @param array $parameters Data to be sent to icepay
93
     *
94
     * @return RequestInterface
95
     */
96 1
    public function authorize(array $parameters = []): RequestInterface
97
    {
98 1
        return $this->createRequest(CreateTransactionRequest::class, $parameters);
99
    }
100
101
    /**
102
     * Create completeAuthorize request.
103
     * This is not an 'authorisation function' as icepay puts it, but a 'transaction function'.
104
     *
105
     * @param array $parameters Data to be sent to icepay
106
     *
107
     * @return RequestInterface
108
     */
109 1
    public function completeAuthorize(array $parameters = []): RequestInterface
110
    {
111 1
        return $this->fetchTransaction($parameters);
112
    }
113
114
    /**
115
     * Get the status of the transaction.
116
     *
117
     * @param array $options Data to be sent to Icepay
118
     *
119
     * @return RequestInterface
120
     */
121 3
    public function fetchTransaction(array $options = []): RequestInterface
122
    {
123 3
        return $this->createRequest(TransactionStatusRequest::class, $options);
124
    }
125
126
    /**
127
     * Refund transaction.
128
     *
129
     * @param array $parameters Data to be sent to icepay
130
     *
131
     * @return RequestInterface
132
     */
133 1
    public function refund(array $parameters = []): RequestInterface
134
    {
135 1
        return $this->createRequest(RefundRequest::class, $parameters);
136
    }
137
138
    /**
139
     * Create a capture request.
140
     *
141
     * @param array $parameters Data to be sent to Icepay
142
     *
143
     * @return RequestInterface
144
     */
145 1
    public function capture(array $parameters = []): RequestInterface
146
    {
147 1
        return $this->fetchTransaction($parameters);
148
    }
149
150
    /**
151
     * Returns the base URL of the API.
152
     *
153
     * @return string
154
     */
155 2
    public function getBaseUrl(): string
156
    {
157 2
        return $this->getParameter('baseUrl');
158
    }
159
160
    /**
161
     * Sets the base URL of the API.
162
     *
163
     * @param string $baseUrl
164
     *
165
     * @return self
166
     */
167 7
    public function setBaseUrl(string $baseUrl): self
168
    {
169 7
        return $this->setParameter('baseUrl', $baseUrl);
170
    }
171
172
    /**
173
     * Get Contract Profile Id (also known as the user id).
174
     *
175
     * Use the Contract Profile Id assigned by Allied wallet.
176
     *
177
     * @return string
178
     */
179 1
    public function getContractProfileId(): string
180
    {
181 1
        return $this->getParameter('contractProfileId');
182
    }
183
184
    /**
185
     * Set Contract Profile Id (also known as the user id).
186
     *
187
     * @param string $contractProfileId
188
     *
189
     * @return self
190
     */
191 1
    public function setContractProfileId(string $contractProfileId): self
192
    {
193 1
        return $this->setParameter('contractProfileId', $contractProfileId);
194
    }
195
196
    /**
197
     * Get Secret Key.
198
     *
199
     * @return string
200
     */
201 1
    public function getSecretKey(): string
202
    {
203 1
        return $this->getParameter('secretKey');
204
    }
205
206
    /**
207
     * Set Secret Key.
208
     *
209
     * @param string $secretKey
210
     *
211
     * @return self
212
     */
213 1
    public function setSecretKey($secretKey): self
214
    {
215 1
        return $this->setParameter('secretKey', $secretKey);
216
    }
217
}
218