Completed
Push — master ( 870c10...157197 )
by Dmitry
05:26
created

Gateway   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 193
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 19
lcom 2
cbo 1
dl 0
loc 193
ccs 36
cts 40
cp 0.9
rs 10
c 0
b 0
f 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getDefaultParameters() 0 10 1
A getPurse() 0 4 1
A setPurse() 0 4 1
A getSecret() 0 4 1
A setSecret() 0 4 1
A getCheckoutId() 0 4 1
A setCheckoutId() 0 4 1
A getSignAlgorithm() 0 4 1
A setSignAlgorithm() 0 4 1
A getSignKey() 0 4 1
A setSignKey() 0 4 1
A getTestKey() 0 4 1
A setTestKey() 0 4 1
A purchase() 0 10 2
A completePurchase() 0 10 2
A isOldApi() 0 4 1
1
<?php
2
/**
3
 * InterKassa driver for the Omnipay PHP payment processing library
4
 *
5
 * @link      https://github.com/hiqdev/omnipay-interkassa
6
 * @package   omnipay-interkassa
7
 * @license   MIT
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace Omnipay\InterKassa;
12
13
use Omnipay\Common\AbstractGateway;
14
use Omnipay\InterKassa\Message\OldPurchaseRequest;
15
use Omnipay\InterKassa\Message\PurchaseRequest;
16
use Omnipay\InterKassa\Message\OldCompletePurchaseRequest;
17
use Omnipay\InterKassa\Message\CompletePurchaseRequest;
18
19
/**
20
 * Gateway for InterKassa Shop Cart Interface.
21
 * http://interkassa.com/.
22
 */
23
class Gateway extends AbstractGateway
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 2
    public function getName()
29
    {
30 2
        return 'InterKassa';
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 42
    public function getDefaultParameters()
37
    {
38
        return [
39 42
            'checkoutId'    => '',
40
            'signAlgorithm' => 'md5',
41
            'signKey'       => '',
42
            'testKey'       => '',
43
            'testMode'      => false,
44
        ];
45
    }
46
47
    /**
48
     * Get the unified purse.
49
     *
50
     * @return string merchant purse
51
     */
52 14
    public function getPurse()
53
    {
54 14
        return $this->getCheckoutId();
55
    }
56
57
    /**
58
     * Set the unified purse.
59
     *
60
     * @param $value
61
     * @return self
62
     */
63 42
    public function setPurse($value)
64
    {
65 42
        return $this->setCheckoutId($value);
66
    }
67
68
    /**
69
     * Get the unified secret.
70
     * @return string merchant secret - sign key
71
     */
72
    public function getSecret()
73
    {
74
        return $this->getSignKey();
75
    }
76
77
    /**
78
     * Set the unified secret.
79
     * @param string $value merchant secret - sign key
80
     * @return self
81
     */
82
    public function setSecret($value)
83
    {
84
        return $this->setSignKey($value);
85
    }
86
87
    /**
88
     * Get the merchant purse.
89
     *
90
     * @return string merchant purse
91
     */
92 16
    public function getCheckoutId()
93
    {
94 16
        return $this->getParameter('checkoutId');
95
    }
96
97
    /**
98
     * Set the merchant purse.
99
     *
100
     * @param string $value merchant purse
101
     *
102
     * @return self
103
     */
104 42
    public function setCheckoutId($value)
105
    {
106 42
        return $this->setParameter('checkoutId', $value);
107
    }
108
109
    /**
110
     * Get the sign algorithm.
111
     *
112
     * @return string sign algorithm
113
     */
114 2
    public function getSignAlgorithm()
115
    {
116 2
        return $this->getParameter('signAlgorithm');
117
    }
118
119
    /**
120
     * Set the sign algorithm.
121
     *
122
     * @param string $value sign algorithm
123
     *
124
     * @return self
125
     */
126 6
    public function setSignAlgorithm($value)
127
    {
128 6
        return $this->setParameter('signAlgorithm', $value);
129
    }
130
131
    /**
132
     * Get the sign key.
133
     *
134
     * @return string sign key
135
     */
136 4
    public function getSignKey()
137
    {
138 4
        return $this->getParameter('signKey');
139
    }
140
141
    /**
142
     * Set the sign key.
143
     *
144
     * @param string $value sign key
145
     *
146
     * @return self
147
     */
148 42
    public function setSignKey($value)
149
    {
150 42
        return $this->setParameter('signKey', $value);
151
    }
152
153
    /**
154
     * Get the test key.
155
     *
156
     * @return string test key
157
     */
158 4
    public function getTestKey()
159
    {
160 4
        return $this->getParameter('testKey');
161
    }
162
163
    /**
164
     * Set the test key.
165
     *
166
     * @param string $value test key
167
     *
168
     * @return self
169
     */
170 42
    public function setTestKey($value)
171
    {
172 42
        return $this->setParameter('testKey', $value);
173
    }
174
175
    /**
176
     * @param array $parameters
177
     *
178
     * @return \Omnipay\InterKassa\Message\PurchaseRequest|\Omnipay\InterKassa\Message\OldPurchaseRequest
179
     */
180 6
    public function purchase(array $parameters = [])
181
    {
182 6
        if ($this->isOldApi()) {
183 2
            $requestClass = OldPurchaseRequest::class;
184
        } else {
185 4
            $requestClass = PurchaseRequest::class;
186
        }
187
188 6
        return $this->createRequest($requestClass, $parameters);
189
    }
190
191
    /**
192
     * @param array $parameters
193
     *
194
     * @return \Omnipay\InterKassa\Message\CompletePurchaseRequest|\Omnipay\InterKassa\Message\OldCompletePurchaseRequest
195
     */
196 6
    public function completePurchase(array $parameters = [])
197
    {
198 6
        if ($this->isOldApi()) {
199 2
            $requestClass = OldCompletePurchaseRequest::class;
200
        } else {
201 4
            $requestClass = CompletePurchaseRequest::class;
202
        }
203
204 6
        return $this->createRequest($requestClass, $parameters);
205
    }
206
207
    /**
208
     * Whether the request is designed for API v2.
209
     * @return boolean
210
     */
211 12
    public function isOldApi()
212
    {
213 12
        return strpos($this->getPurse(), '-') !== false;
214
    }
215
}
216