1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* InterKassa driver for the Omnipay PHP payment processing library |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/omnipay-interkassa |
7
|
|
|
* @package omnipay-interkassa |
8
|
|
|
* @license MIT |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Omnipay\InterKassa; |
13
|
|
|
|
14
|
|
|
use Omnipay\Common\AbstractGateway; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Gateway for InterKassa Shop Cart Interface. |
18
|
|
|
* http://interkassa.com/. |
19
|
|
|
*/ |
20
|
|
|
class Gateway extends AbstractGateway |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
2 |
|
public function getName() |
26
|
|
|
{ |
27
|
2 |
|
return 'InterKassa'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
58 |
|
public function getDefaultParameters() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
58 |
|
'purse' => '', |
37
|
58 |
|
'secret' => '', |
38
|
58 |
|
'testMode' => false, |
39
|
58 |
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get the unified purse. |
44
|
|
|
* |
45
|
|
|
* @return string merchant purse |
46
|
|
|
*/ |
47
|
16 |
|
public function getPurse() |
48
|
|
|
{ |
49
|
16 |
|
return $this->getCheckoutId(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Set the unified purse. |
54
|
|
|
* |
55
|
|
|
* @param $value |
56
|
|
|
* @return self |
57
|
|
|
*/ |
58
|
58 |
|
public function setPurse($value) |
59
|
|
|
{ |
60
|
58 |
|
return $this->setCheckoutId($value); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the merchant purse. |
65
|
|
|
* |
66
|
|
|
* @return string merchant purse |
67
|
|
|
*/ |
68
|
16 |
|
public function getCheckoutId() |
69
|
|
|
{ |
70
|
16 |
|
return $this->getParameter('checkoutId'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Set the merchant purse. |
75
|
|
|
* |
76
|
|
|
* @param string $value merchant purse |
77
|
|
|
* |
78
|
|
|
* @return self |
79
|
|
|
*/ |
80
|
58 |
|
public function setCheckoutId($value) |
81
|
|
|
{ |
82
|
58 |
|
return $this->setParameter('checkoutId', $value); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the secret key. |
87
|
|
|
* |
88
|
|
|
* @return string secret |
89
|
|
|
*/ |
90
|
4 |
|
public function getSecret() |
91
|
|
|
{ |
92
|
4 |
|
return $this->getParameter('secret'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Set the secret. |
97
|
|
|
* |
98
|
|
|
* @param string $value secret |
99
|
|
|
* |
100
|
|
|
* @return self |
101
|
|
|
*/ |
102
|
58 |
|
public function setSecret($value) |
103
|
|
|
{ |
104
|
58 |
|
return $this->setParameter('secret', $value); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param array $parameters |
109
|
|
|
* |
110
|
|
|
* @return \Omnipay\InterKassa\Message\PurchaseRequest|\Omnipay\InterKassa\Message\OldPurchaseRequest |
111
|
|
|
*/ |
112
|
6 |
View Code Duplication |
public function purchase(array $parameters = []) |
|
|
|
|
113
|
|
|
{ |
114
|
6 |
|
if ($this->isOldApi()) { |
115
|
2 |
|
$requestClass = '\Omnipay\InterKassa\Message\OldPurchaseRequest'; |
116
|
2 |
|
} else { |
117
|
4 |
|
$requestClass = '\Omnipay\InterKassa\Message\PurchaseRequest'; |
118
|
|
|
} |
119
|
|
|
|
120
|
6 |
|
return $this->createRequest($requestClass, $parameters); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param array $parameters |
125
|
|
|
* |
126
|
|
|
* @return \Omnipay\InterKassa\Message\CompletePurchaseRequest|\Omnipay\InterKassa\Message\OldCompletePurchaseRequest |
127
|
|
|
*/ |
128
|
6 |
View Code Duplication |
public function completePurchase(array $parameters = []) |
|
|
|
|
129
|
|
|
{ |
130
|
6 |
|
if ($this->isOldApi()) { |
131
|
2 |
|
$requestClass = '\Omnipay\InterKassa\Message\OldCompletePurchaseRequest'; |
132
|
2 |
|
} else { |
133
|
4 |
|
$requestClass = '\Omnipay\InterKassa\Message\CompletePurchaseRequest'; |
134
|
|
|
} |
135
|
|
|
|
136
|
6 |
|
return $this->createRequest($requestClass, $parameters); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Whether the request is designed for API v2. |
141
|
|
|
* @return boolean |
142
|
|
|
*/ |
143
|
12 |
|
public function isOldApi() |
144
|
|
|
{ |
145
|
12 |
|
return strpos($this->getPurse(), '-'); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.