Gateway::setContractProfileId()   A
last analyzed

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