forked from joni-jones/yii2-2checkout
/
TwoCheckout.php
117 lines (104 loc) · 3.13 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
<?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 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 \yii\di\ServiceLocator $locator */
private $locator = null;
/**
* @inheritdoc
*/
public function init()
{
$this->locator = new ServiceLocator();
\Twocheckout::sellerId($this->sellerId);
if (!$this->secretWord) {
throw new InvalidConfigException('Invalid secret word was specified');
}
}
/**
* 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');
}
}