-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enot.php
94 lines (78 loc) · 2.51 KB
/
Enot.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
<?php
class Enot
{
const URL = 'https://enot.io/pay';
public $sum = 0;
public $order_id = null;
public $success_url = 0;
public $fail_url = 0;
public $params = 0;
public function __construct($merchant_id, $secret_word, $desecret_word, $currency = 'RUB')
{
$this->merchant_id = $merchant_id;
$this->secret_word = $secret_word;
$this->desecret_word = $desecret_word;
$this->currency = $currency;
}
public function checkError()
{
if (!$this->merchant_id) return ['ok' => false, 'message' => 'merchant_id not declared'];
if (!$this->secret_word) return ['ok' => false, 'message' => 'secret_word not declared'];
if (!$this->desecret_word) return ['ok' => false, 'message' => 'desecret_word not declared'];
if (!$this->order_id) return ['ok' => false, 'message' => 'order_id not declared. Call the setUp function'];
return ['ok' => true, 'message' => 'count errors: 0'];
}
public function getInfo()
{
return json_encode([
'merchantId' => $this->merchant_id,
'secret' => $this->secret_word,
'desecret' => $this->desecret_word,
'currency' => $this->currency,
'sum' => $this->sum,
'orderId' => $this->order_id,
]);
}
public function setUpUrl($array)
{
foreach ($array as $key => $value) {
if ($key == 'success_url') $this->success_url = $value;
if ($key == 'fail_url') $this->fail_url = $value;
if ($key == 'params') {
if (is_array($value)) $this->params = $value;
}
}
}
public function setUpOrder($sum, $order_id)
{
$this->sum = $sum;
$this->order_id = $order_id;
}
public function getSignature()
{
$error = $this->checkError();
if (!$error['ok']) return json_encode($error);
return md5($this->merchant_id . ':' . $this->sum . ':' . $this->secret_word . ':' . $this->order_id);
}
public function getOrderSignature()
{
$error = $this->checkError();
if (!$error['ok']) return json_encode($error);
return md5($this->merchant_id . ':' . $this->sum . ':' . $this->desecret_word . ':' . $this->order_id);
}
public function generateUrlPayment()
{
$error = $this->checkError();
if (!$error['ok']) return json_encode($error);
return self::URL . '?' . http_build_query([
'm' => $this->merchant_id,
'oa' => $this->sum,
'o' => $this->order_id,
's' => $this->getSignature(),
'cr' => $this->currency,
'success_url' => $this->success_url,
'fail_url' => $this->fail_url,
'cf' => $this->params,
]);
}
}