Passed
Push — master ( ac91b4...b7af7c )
by Kiet
03:22 queued 10s
created

Gateway::fetchTransaction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
    public function getName(): string
43
    {
44
        return 'Icepay Payments';
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 7
    public function getDefaultParameters(): array
51
    {
52
        return array(
53 7
            'contractProfileId' => '',
54
            'secretKey' => '',
55
            'testMode' => false,
56
        );
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 7
    public function initialize(array $parameters = array()): self
63
    {
64 7
        parent::initialize($parameters);
65
66 7
        $baseUrl = self::API_BASE_URL;
67 7
        if ($this->getTestMode()) {
68 1
            $baseUrl = self::TEST_API_BASE_URL;
69
        }
70
71 7
        $this->setBaseUrl($baseUrl);
72
73 7
        return $this;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 5
    protected function createRequest($class, array $parameters)
80
    {
81 5
        $parameters['timestamp'] = new DateTime();
82
83 5
        return parent::createRequest($class, $parameters); // TODO: Change the autogenerated stub
84
    }
85
86
    /**
87
     * Create an authorize request.
88
     * This is not an 'authorisation function' as icepay puts it, but a 'transaction function'.
89
     *
90
     * @param array $parameters Data to be sent to icepay
91
     *
92
     * @return RequestInterface
93
     */
94 1
    public function authorize(array $parameters = []): RequestInterface
95
    {
96 1
        return $this->createRequest(CreateTransactionRequest::class, $parameters);
97
    }
98
99
    /**
100
     * Create completeAuthorize request.
101
     * This is not an 'authorisation function' as icepay puts it, but a 'transaction function'.
102
     *
103
     * @param array $parameters Data to be sent to icepay
104
     *
105
     * @return RequestInterface
106
     */
107 1
    public function completeAuthorize(array $parameters = []): RequestInterface
108
    {
109 1
        return $this->fetchTransaction($parameters);
110
    }
111
112
    /**
113
     * Get the status of the transaction.
114
     *
115
     * @param array $options Data to be sent to Icepay
116
     *
117
     * @return RequestInterface
118
     */
119 3
    public function fetchTransaction(array $options = []): RequestInterface
120
    {
121 3
        return $this->createRequest(TransactionStatusRequest::class, $options);
122
    }
123
124
    /**
125
     * Refund transaction.
126
     *
127
     * @param array $parameters Data to be sent to icepay
128
     *
129
     * @return RequestInterface
130
     */
131 1
    public function refund(array $parameters = []): RequestInterface
132
    {
133 1
        return $this->createRequest(RefundRequest::class, $parameters);
134
    }
135
136
    /**
137
     * Create a capture request.
138
     *
139
     * @param array $parameters Data to be sent to Icepay
140
     *
141
     * @return RequestInterface
142
     */
143 1
    public function capture(array $parameters = []): RequestInterface
144
    {
145 1
        return $this->fetchTransaction($parameters);
146
    }
147
148
    /**
149
     * Returns the base URL of the API.
150
     *
151
     * @return string
152
     */
153 2
    public function getBaseUrl(): string
154
    {
155 2
        return $this->getParameter('baseUrl');
156
    }
157
158
    /**
159
     * Sets the base URL of the API.
160
     *
161
     * @param string $baseUrl
162
     *
163
     * @return self
164
     */
165 7
    public function setBaseUrl(string $baseUrl): self
166
    {
167 7
        return $this->setParameter('baseUrl', $baseUrl);
168
    }
169
170
    /**
171
     * Get Contract Profile Id (also known as the user id).
172
     *
173
     * Use the Contract Profile Id assigned by Allied wallet.
174
     *
175
     * @return string
176
     */
177 1
    public function getContractProfileId(): string
178
    {
179 1
        return $this->getParameter('contractProfileId');
180
    }
181
182
    /**
183
     * Set Contract Profile Id (also known as the user id).
184
     *
185
     * @param string $contractProfileId
186
     *
187
     * @return self
188
     */
189 1
    public function setContractProfileId(string $contractProfileId): self
190
    {
191 1
        return $this->setParameter('contractProfileId', $contractProfileId);
192
    }
193
194
    /**
195
     * Get Secret Key.
196
     *
197
     * @return string
198
     */
199 1
    public function getSecretKey(): string
200
    {
201 1
        return $this->getParameter('secretKey');
202
    }
203
204
    /**
205
     * Set Secret Key.
206
     *
207
     * @param string $secretKey
208
     *
209
     * @return self
210
     */
211 1
    public function setSecretKey($secretKey): self
212
    {
213 1
        return $this->setParameter('secretKey', $secretKey);
214
    }
215
}
216