forked from yii-cms/yii2-robokassa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMerchant.php
79 lines (62 loc) · 2.15 KB
/
Merchant.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
<?php
namespace robokassa;
use Yii;
use yii\base\Object;
class Merchant extends Object
{
public $sMerchantLogin;
public $sMerchantPass1;
public $sMerchantPass2;
public $isTest = false;
public $baseUrl = 'https://auth.robokassa.ru/Merchant/Index.aspx';
public $hashAlgo = 'md5';
public function payment($nOutSum, $nInvId, $sInvDesc = null, $sIncCurrLabel=null, $sEmail = null, $sCulture = null, $shp = [], $returnLink = false)
{
$url = $this->baseUrl;
$signature = "{$this->sMerchantLogin}:{$nOutSum}:{$nInvId}:{$this->sMerchantPass1}";
if (!empty($shp)) {
$signature .= ':' . $this->implodeShp($shp);
}
$sSignatureValue = $this->encryptSignature($signature);
$url .= '?' . http_build_query([
'MrchLogin' => $this->sMerchantLogin,
'OutSum' => $nOutSum,
'InvId' => $nInvId,
'Desc' => $sInvDesc,
'SignatureValue' => $sSignatureValue,
'IncCurrLabel' => $sIncCurrLabel,
'Email' => $sEmail,
'Culture' => $sCulture,
'IsTest' => (int)$this->isTest,
]);
if (!empty($shp) && ($query = http_build_query($shp)) !== '') {
$url .= '&' . $query;
}
if ( !$returnLink ){
Yii::$app->user->setReturnUrl(Yii::$app->request->getUrl());
return Yii::$app->response->redirect($url);
} else {
return $url;
}
}
private function implodeShp($shp)
{
ksort($shp);
foreach($shp as $key => $value) {
$shp[$key] = $key . '=' . $value;
}
return implode(':', $shp);
}
public function checkSignature($sSignatureValue, $nOutSum, $nInvId, $sMerchantPass, $shp)
{
$signature = "{$nOutSum}:{$nInvId}:{$sMerchantPass}";
if (!empty($shp)) {
$signature .= ':' . $this->implodeShp($shp);
}
return strtolower($this->encryptSignature($signature)) === strtolower($sSignatureValue);
}
private function encryptSignature($signature)
{
return hash($this->hashAlgo, $signature);
}
}