-
Notifications
You must be signed in to change notification settings - Fork 1
/
Api.php
124 lines (106 loc) · 3.26 KB
/
Api.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
<?php
namespace Fullpipe\Payum\Flexidengi;
class Api
{
const PAYMENT_METHOD_WEBMONEY_WMR = 38; // WebMoney WMR
const PAYMENT_METHOD_QIWI = 44; // QIWI
const PAYMENT_METHOD_TEST = 45; // Тестовый(возвращает произвольный статус оплаты, не передается в реестрах)
const PAYMENT_METHOD_MOBILE = 60; // Мобильная коммерция
const PAYMENT_METHOD_CREDIT_CARDS = 61; // Банковские карты VISA / VISA Electron / MasterCard / Maestro
const PAYMENT_STATUS_PROCESSED = 'PROCESSED';
const PAYMENT_STATUS_FAILED = 'FAILED';
const ORDER_ID_PARAM_NAME = 'order_id';
/**
* @var array
*/
private $config;
/**
* Constructor.
*
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
}
public function getPaymentPageUrl()
{
return 'https://pay.flexidengi.ru/';
}
public function getServiceId()
{
return $this->config['service_id'];
}
public function getPaymentMethodId()
{
return $this->config['payment_method_id'];
}
public function getProductId()
{
return $this->config['product_id'];
}
private function getSecret()
{
return $this->config['secret'];
}
public function isSandbox()
{
return $this->config['sandbox'];
}
/**
* Build order signature from order details.
* md5(service_id+customer_id+order_id+product_id+ summ+currency+count+payment_method_id+ secret_key).
*
* @param array $params
*
* @return string
*/
public function sing(array $params)
{
$singParams = array(
'service_id' => $this->getServiceId(),
'customer_id' => null,
'order_id' => null,
'product_id' => null,
'summ' => null,
'currency' => null,
'count' => null,
'payment_method_id' => $this->getPaymentMethodId(),
'secret_key' => $this->getSecret(),
);
$params = array_intersect_key($params, $singParams);
$singParams = array_merge($singParams, $params);
return md5(implode('', $singParams));
}
/**
* Validate notification signature.
*
* @param array $params
*
* @return boolean
*/
public function validateNotificationSignature(array $params)
{
$hash = $params['hash'];
$signatureParams = array(
'service_id' => null,
'transaction_id' => null,
'customer_id' => null,
'order_id' => null,
'processing_status' => null,
'price' => null,
'price_rub' => null,
'currency' => null,
'share' => null,
'share_rub' => null,
'transaction_date' => null,
'payment_method_id' => $this->getPaymentMethodId(),
'product_id' => null,
'secret_key' => $this->getSecret(),
);
$params = array_intersect_key($params, $signatureParams);
$signatureParams = array_merge($signatureParams, $params);
$signature = md5(implode('', $signatureParams));
return $signature == $hash;
}
}