-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRobokassa.php
128 lines (102 loc) · 3.27 KB
/
Robokassa.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
<?php
class Robokassa extends CApplicationComponent
{
public $sMerchantLogin;
public $sMerchantPass1;
public $sMerchantPass2;
public $sCulture = 'ru';
public $resultMethod = 'post';
public $sIncCurrLabel = 'QiwiR';
public $orderModel;
public $priceField;
public $isTest = false;
public $params;
protected $_order;
public function pay($nOutSum, $nInvId, $sInvDesc, $sUserEmail)
{
$sign = $this->getPaySign($nOutSum, $nInvId, $sUserEmail);
$url = $this->isTest
? 'http://test.robokassa.ru/Index.aspx?'
: 'https://merchant.roboxchange.com/Index.aspx?';
$url .= "MrchLogin={$this->sMerchantLogin}&";
$url .= "OutSum={$nOutSum}&";
$url .= "InvId={$nInvId}&";
$url .= "Desc={$sInvDesc}&";
$url .= "SignatureValue={$sign}&";
$url .= "IncCurrLabel={$this->sIncCurrLabel}&";
$url .= "Email={$sUserEmail}&";
$url .= "Culture={$this->sCulture}";
Yii::app()->controller->redirect($url);
}
private function getPaySign($nOutSum, $nInvId)
{
$keys = array(
$this->sMerchantLogin,
$nOutSum,
$nInvId,
$this->sMerchantPass1,
);
return md5(implode(':', $keys));
}
public function result()
{
$var = $_GET + $_POST;
extract($var);
$event = new CEvent($this);
$valid = true;
if (!$valid || !isset($OutSum, $InvId, $SignatureValue)) {
$this->params = array('reason' => 'Dont set need value');
$valid = false;
}
if (!$valid || !$this->checkResultSignature($OutSum, $InvId, $SignatureValue)) {
$this->params = array('reason' => 'Signature fail');
$valid = false;
}
if (!$valid || !$this->isOrderExists($InvId)) {
$this->params = array('reason' => 'Order not exists');
$valid = false;
}
if (!$valid || $this->_order->{$this->priceField} != $OutSum) {
$this->params = array('reason' => 'Order price error');
$valid = false;
}
if ($valid) {
if ($this->hasEventHandler('onSuccess')) {
$this->params = array('order' => $this->_order);
$this->onSuccess($event);
}
} else {
if ($this->hasEventHandler('onFail')) {
return $this->onFail($event);
}
}
echo "OK{$InvId}\n";
}
private function isOrderExists($id)
{
$this->_order = CActiveRecord::model($this->orderModel)->findByPk((int)$id);
if ($this->_order)
return true;
return false;
}
public function checkResultSignature($OutSum, $InvId, $SignatureValue, $checkType = 0)
{
$keys = array(
$OutSum,
$InvId,
$checkType ? $this->sMerchantPass1 : $this->sMerchantPass2,
);
$sign = strtoupper(md5(implode(':', $keys)));
if (strtoupper($SignatureValue) == $sign)
return true;
return false;
}
public function onSuccess($event)
{
$this->raiseEvent('onSuccess', $event);
}
public function onFail($event)
{
$this->raiseEvent('onFail', $event);
}
}