Test Failed
Push — refactor-icepaypayments ( 0502bc...2c8cbf )
by Kiet
01:54
created

Gateway   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 6
Bugs 0 Features 2
Metric Value
eloc 28
c 6
b 0
f 2
dl 0
loc 168
ccs 0
cts 71
cp 0
rs 10
wmc 16

15 Methods

Rating   Name   Duplication   Size   Complexity  
A setSecretKey() 0 3 1
A getDefaultParameters() 0 7 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
declare(strict_types=1);
4
5
namespace Omnipay\IcepayPayments;
6
7
use DateTimeImmutable;
8
use Omnipay\Common\AbstractGateway;
9
use Omnipay\Common\Message\RequestInterface;
10
use Omnipay\IcepayPayments\Message\CaptureRequest;
11
use Omnipay\IcepayPayments\Message\CompleteAuthorizeRequest;
12
use Omnipay\IcepayPayments\Message\CreateTransactionRequest;
13
use Omnipay\IcepayPayments\Message\FetchTransactionRequest;
14
use Omnipay\IcepayPayments\Message\RefundRequest;
15
16
class Gateway extends AbstractGateway
17
{
18
    /**
19
     * @var string
20
     */
21
    private const API_BASE_URL = 'https://interconnect.icepay.com';
22
23
    /**
24
     * @var string
25
     */
26
    private const TEST_API_BASE_URL = 'https://acc-interconnect.icepay.com';
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getName(): string
32
    {
33
        return 'Icepay Payments';
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function initialize(array $parameters = []): self
40
    {
41
        parent::initialize($parameters);
42
43
        $baseUrl = self::API_BASE_URL;
44
        if ($this->getTestMode()) {
45
            $baseUrl = self::TEST_API_BASE_URL;
46
        }
47
48
        $this->setBaseUrl($baseUrl);
49
50
        return $this;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function authorize(array $parameters = []): RequestInterface
57
    {
58
        return $this->createRequest(CreateTransactionRequest::class, $parameters);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function completeAuthorize(array $parameters = []): RequestInterface
65
    {
66
        return $this->createRequest(CompleteAuthorizeRequest::class, $parameters);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function capture(array $parameters = []): RequestInterface
73
    {
74
        return $this->createRequest(CaptureRequest::class, $parameters);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function refund(array $parameters = []): RequestInterface
81
    {
82
        return $this->createRequest(RefundRequest::class, $parameters);
83
    }
84
85
    /**
86
     * @param array $parameters
87
     *
88
     * @return RequestInterface
89
     */
90
    public function fetchTransaction(array $parameters = []): RequestInterface
91
    {
92
        return $this->createRequest(FetchTransactionRequest::class, $parameters);
93
    }
94
95
    /**
96
     * Apply the timestamp to the parameters at every request.
97
     *
98
     * {@inheritdoc}
99
     */
100
    protected function createRequest($class, array $parameters): RequestInterface
101
    {
102
        $parameters['timestamp'] = new DateTimeImmutable();
103
104
        return parent::createRequest($class, $parameters);
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function getDefaultParameters(): array
111
    {
112
        return [
113
            'baseUrl' => self::API_BASE_URL,
114
            'testMode' => false,
115
            'contractProfileId' => '',
116
            'secretKey' => '',
117
        ];
118
    }
119
120
    /**
121
     * Get the base URL of the API.
122
     *
123
     * @return string
124
     */
125
    public function getBaseUrl(): string
126
    {
127
        return $this->getParameter('baseUrl');
128
    }
129
130
    /**
131
     * Set the base URL of the API.
132
     *
133
     * @param string $baseUrl
134
     *
135
     * @return self
136
     */
137
    public function setBaseUrl(string $baseUrl): self
138
    {
139
        return $this->setParameter('baseUrl', $baseUrl);
140
    }
141
142
    /**
143
     * Get the ContractProfileId (also known as the UserId).
144
     *
145
     * @return string
146
     */
147
    public function getContractProfileId(): string
148
    {
149
        return $this->getParameter('contractProfileId');
150
    }
151
152
    /**
153
     * Set the ContractProfileId (also known as the UserId).
154
     *
155
     * @param string $contractProfileId
156
     *
157
     * @return self
158
     */
159
    public function setContractProfileId(string $contractProfileId): self
160
    {
161
        return $this->setParameter('contractProfileId', $contractProfileId);
162
    }
163
164
    /**
165
     * Get the secret key.
166
     *
167
     * @return string
168
     */
169
    public function getSecretKey(): string
170
    {
171
        return $this->getParameter('secretKey');
172
    }
173
174
    /**
175
     * Set the secret key.
176
     *
177
     * @param string $secretKey
178
     *
179
     * @return self
180
     */
181
    public function setSecretKey(string $secretKey): self
182
    {
183
        return $this->setParameter('secretKey', $secretKey);
184
    }
185
}
186