Passed
Push — refactor-icepaypayments ( e2af7d...78b375 )
by Kiet
01:51
created

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