-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTwoCheckout.php
146 lines (130 loc) · 4.15 KB
/
TwoCheckout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace yii\twocheckout;
use yii\base\InvalidConfigException;
use yii\base\Object;
use yii\di\ServiceLocator;
/**
* Class TwoCheckout
* @package yii\twocheckout
*
* @property \yii\twocheckout\TwoCheckoutCharge $charge
* @property \yii\twocheckout\TwoCheckoutMessage $message
* @property \yii\twocheckout\TwoCheckoutNotification $notification
* @property \yii\twocheckout\TwoCheckoutReturn $return
*/
class TwoCheckout extends Object
{
/** @var string API private key */
public $privateKey = '';
/** @var string seller id */
public $sellerId = '';
/** @var string used to check payment requests */
public $secretWord = '';
/** @var string demo mode config. Available values 'Y' and 'N' */
public $demo = 'Y';
/** @var string Admin API username */
public $username = '';
/** @var string Admin API password */
public $password = '';
/** @var bool check SSL */
public $verifySSL = false;
/** @var bool API requests mode */
public $sandbox = false;
/** @var string API response format */
public $format = 'array';
/** @var \yii\di\ServiceLocator $locator */
private $locator = null;
/**
* @inheritdoc
*/
public function init()
{
$this->locator = new ServiceLocator();
if ($this->username && $this->password) {
\Twocheckout::username($this->username);
\Twocheckout::password($this->password);
}
if (!$this->privateKey) {
throw new InvalidConfigException('Invalid private key was specified');
}
\Twocheckout::privateKey($this->privateKey);
if (!$this->sellerId) {
throw new InvalidConfigException('Invalid seller id was specified');
}
\Twocheckout::sellerId($this->sellerId);
if (!$this->secretWord) {
throw new InvalidConfigException('Invalid secret word was specified');
}
\TwoCheckout::verifySSL($this->verifySSL);
\Twocheckout::sandbox($this->sandbox);
\Twocheckout::format($this->format);
}
/**
* Get twocheckout charge class instance
*
* @access public
* @return \yii\twocheckout\TwoCheckoutCharge
*/
public function getCharge()
{
if (!$this->locator->has('change')) {
$this->locator->set('charge', '\yii\twocheckout\TwoCheckoutCharge');
}
return $this->locator->get('charge');
}
/**
* Get twocheckout message class instance
*
* @access public
* @return \yii\twocheckout\TwoCheckoutMessage
*/
public function getMessage()
{
if (!$this->locator->has('message')) {
$this->locator->set('message', '\yii\twocheckout\TwoCheckoutMessage');
}
return $this->locator->get('message');
}
/**
* Get twocheckout notification class instance
*
* @access public
* @return \yii\twocheckout\TwoCheckoutNotification
*/
public function getNotification()
{
if (!$this->locator->has('notification')) {
$this->locator->set('notification', '\yii\twocheckout\TwoCheckoutNotification');
}
return $this->locator->get('notification');
}
/**
* Get twocheckout return class instance
*
* @access public
* @return \yii\twocheckout\TwoCheckoutReturn
*/
public function getReturn()
{
if (!$this->locator->has('return')) {
$this->locator->set('return', '\yii\twocheckout\TwoCheckoutReturn');
}
return $this->locator->get('return');
}
/**
* Check payment status
*
* @access public
* @param array $params
* @return bool
*/
public function approve(array $params)
{
//if demo mode enable order number must be always '1'
if (!empty($params['demo']) && $params['demo'] == 'Y') {
$params['order_number'] = 1;
}
$passback = $this->return->check($params, $this->secretWord, 'array');
return ($passback['response_code'] == 'Success');
}
}