1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* RoboKassa driver for Omnipay PHP payment library. |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/omnipay-robokassa |
6
|
|
|
* @package omnipay-robokassa |
7
|
|
|
* @license MIT |
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Omnipay\RoboKassa\Message; |
12
|
|
|
|
13
|
|
|
class PurchaseRequest extends AbstractRequest |
14
|
|
|
{ |
15
|
|
|
public function getData() |
16
|
|
|
{ |
17
|
|
|
$this->validate( |
18
|
|
|
'purse', 'amount', 'currency', 'description' |
19
|
|
|
); |
20
|
|
|
|
21
|
|
|
return [ |
22
|
|
|
'InvId' => $this->getInvId(), |
23
|
|
|
'MerchantLogin' => $this->getPurse(), |
24
|
|
|
'OutSum' => $this->getAmount(), |
25
|
|
|
'Description' => $this->getDescription(), |
26
|
|
|
'IncCurrLabel' => $this->getCurrencyLabel(), |
27
|
|
|
'OutSumCurrency' => $this->getCurrency(), |
28
|
|
|
'SignatureValue' => $this->generateSignature(), |
29
|
|
|
'IsTest' => (int) $this->getTestMode(), |
30
|
|
|
'Receipt' => $this->getReceipt(), |
31
|
|
|
] + $this->getCustomFields(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function generateSignature() |
35
|
|
|
{ |
36
|
|
|
$params = [ |
37
|
|
|
$this->getPurse(), |
38
|
|
|
$this->getAmount(), |
39
|
|
|
$this->getInvId() |
40
|
|
|
]; |
41
|
|
|
if ($this->getCurrency()) { |
42
|
|
|
$params[] = $this->getCurrency(); |
43
|
|
|
} |
44
|
|
|
if ($this->getReceipt()) { |
45
|
|
|
$params[] = $this->getReceipt(); |
46
|
|
|
} |
47
|
|
|
$params[] = $this->getSecretKey(); |
48
|
|
|
|
49
|
|
|
foreach ($this->getCustomFields() as $field => $value) { |
50
|
|
|
$params[] = "$field=$value"; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return md5(implode(':', $params)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getCustomFields() |
57
|
|
|
{ |
58
|
|
|
$fields = array_filter([ |
59
|
|
|
'Shp_TransactionId' => $this->getTransactionId(), |
60
|
|
|
'Shp_Client' => $this->getClient() |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
ksort($fields); |
64
|
|
|
|
65
|
|
|
return $fields; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function sendData($data) |
69
|
|
|
{ |
70
|
|
|
return $this->response = new PurchaseResponse($this, $data); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|