forked from yii-cms/yii2-robokassa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerchant.php
More file actions
65 lines (51 loc) · 1.77 KB
/
Copy pathMerchant.php
File metadata and controls
65 lines (51 loc) · 1.77 KB
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
<?php
namespace robokassa;
use Yii;
use yii\base\Object;
class Merchant extends Object
{
public $sMerchantLogin;
public $sMerchantPass1;
public $sMerchantPass2;
public $baseUrl = 'https://auth.robokassa.ru/Merchant/Index.aspx';
public function payment($nOutSum, $nInvId, $sInvDesc = null, $sIncCurrLabel=null, $sEmail = null, $sCulture = null, $shp = [])
{
$url = $this->baseUrl;
$signature = "{$this->sMerchantLogin}:{$nOutSum}:{$nInvId}:{$this->sMerchantPass1}";
if (!empty($shp)) {
$signature .= ':' . $this->implodeShp($shp);
}
$sSignatureValue = md5($signature);
$url .= '?' . http_build_query([
'MrchLogin' => $this->sMerchantLogin,
'OutSum' => $nOutSum,
'InvId' => $nInvId,
'Desc' => $sInvDesc,
'SignatureValue' => $sSignatureValue,
'IncCurrLabel' => $sIncCurrLabel,
'Email' => $sEmail,
'Culture' => $sCulture,
]);
if (!empty($shp) && ($query = http_build_query($shp)) !== '') {
$url .= '&' . $query;
}
Yii::$app->user->setReturnUrl(Yii::$app->request->getUrl());
return Yii::$app->response->redirect($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(md5($signature)) === strtolower($sSignatureValue);
}
}