-
Notifications
You must be signed in to change notification settings - Fork 32
/
Request.php
187 lines (157 loc) · 3.81 KB
/
Request.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
namespace baibaratsky\WebMoney\Api\ATM;
use baibaratsky\WebMoney\Request\XmlRequest;
abstract class Request extends XmlRequest
{
const AUTH_CLASSIC = 'classic';
const AUTH_LIGHT = 'light';
const AUTH_SHA256 = 'sha256';
const AUTH_MD5 = 'md5';
const AUTH_SECRET_KEY = 'secret_key';
const AUTH_SIGN_TYPE_CLASSIC = 1;
const AUTH_SIGN_TYPE_LIGHT = 2;
const CURRENCY_EUR = 'EUR';
const CURRENCY_USD = 'USD';
const CURRENCY_RUB = 'RUB';
/** @var string request/@lang */
protected $lang;
/** @var string */
protected $authType;
/** @var string */
protected $authTypeNum;
/** @var string reqn */
protected $requestNumber;
/** @var string wmid */
protected $signerWmid;
/** @var string Light auth cert file name (PEM) */
protected $lightCertificate;
/** @var string Light auth key file name (PEM) */
protected $lightKey;
/** @var string Light auth key password */
protected $lightPassword;
/**
* @param string $authType
* @param string $lang [en|ru]
*/
public function __construct($authType = self::AUTH_CLASSIC, $lang = 'en')
{
$this->authType = $authType;
$this->requestNumber = $this->generateRequestNumber();
if (self::AUTH_CLASSIC == $authType) {
$this->authTypeNum = self::AUTH_SIGN_TYPE_CLASSIC;
} elseif (self::AUTH_LIGHT == $authType) {
$this->authTypeNum = self::AUTH_SIGN_TYPE_LIGHT;
}
$this->setLang($lang);
}
/**
* @param string $certificate Light auth certificate file name (PEM)
* @param string $key Light auth key file name (PEM)
* @param string $keyPassword Light auth key password
*/
public function lightAuth($certificate, $key, $keyPassword = '')
{
$this->lightCertificate = $certificate;
$this->lightKey = $key;
$this->lightPassword = $keyPassword;
}
/**
* @param $data
*/
public function setSignature($data)
{
$this->signature = $data;
}
/**
* @return string
*/
public function getAuthType()
{
return $this->authType;
}
/**
* @return string
*/
public function getLightCertificate()
{
return $this->lightCertificate;
}
/**
* @return string
*/
public function getLightKey()
{
return $this->lightKey;
}
/**
* @return string
*/
public function getLightPassword()
{
return $this->lightPassword;
}
/**
* @return int
*/
public function getRequestNumber()
{
return $this->requestNumber;
}
/**
* @param int $requestNumber must be greater than a previous request number
*/
public function setRequestNumber($requestNumber)
{
$this->requestNumber = (int)$requestNumber;
}
/**
* @return string
*/
public function getSignerWmid()
{
return $this->signerWmid;
}
/**
* @param string $signerWmid
*/
public function setSignerWmid($signerWmid)
{
$this->signerWmid = (string)$signerWmid;
}
/**
* @return string
*/
protected function generateRequestNumber()
{
list($msec, $sec) = explode(' ', substr(microtime(), 2));
return $sec . substr($msec, 0, 5);
}
/**
* @param int $authTypeNum
*/
public function setAuthTypeNum($authTypeNum)
{
$this->authTypeNum = $authTypeNum;
}
/**
* @return int|string
*/
public function getAuthTypeNum()
{
return $this->authTypeNum;
}
/**
* @param string $lang
*/
public function setLang($lang)
{
$this->lang = $lang;
}
/**
* @return string
*/
public function getLang()
{
return $this->lang;
}
}