|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/phpviet/omnipay-vnpay |
|
4
|
|
|
* @copyright (c) PHP Viet |
|
5
|
|
|
* @license [MIT](http://www.opensource.org/licenses/MIT) |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Omnipay\VNPay\Message; |
|
9
|
|
|
|
|
10
|
|
|
use Omnipay\VNPay\Concerns\Parameters; |
|
11
|
|
|
use Omnipay\Common\Message\AbstractRequest; |
|
12
|
|
|
use Omnipay\VNPay\Concerns\ParametersNormalization; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Vuong Minh <[email protected]> |
|
16
|
|
|
* @since 1.0.0 |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract class AbstractSignatureRequest extends AbstractRequest |
|
19
|
|
|
{ |
|
20
|
|
|
use Parameters; |
|
21
|
|
|
use ParametersNormalization; |
|
22
|
|
|
use Concerns\RequestEndpoint; |
|
23
|
|
|
use Concerns\RequestSignature; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function initialize(array $parameters = []) |
|
29
|
|
|
{ |
|
30
|
|
|
parent::initialize( |
|
31
|
|
|
$this->normalizeParameters($parameters) |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
$this->setVnpIpAddr( |
|
35
|
|
|
$this->getVnpIpAddr() ?? $this->httpRequest->getClientIp() |
|
36
|
|
|
); |
|
37
|
|
|
$this->setVnpCreateDate( |
|
38
|
|
|
$this->getVnpCreateDate() ?? date('Ymdhis') |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
return $this; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getData(): array |
|
48
|
|
|
{ |
|
49
|
|
|
call_user_func_array( |
|
50
|
|
|
[$this, 'validate'], |
|
51
|
|
|
$this->getSignatureParameters() |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$parameters = $this->getParameters(); |
|
55
|
|
|
$parameters['vnp_SecureHash'] = $this->generateSignature( |
|
56
|
|
|
$parameters['vnp_SecureHashType'] = $this->getSecureHashType() ?? 'sha256' |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
unset($parameters['vnp_HashSecret'], $parameters['testMode']); |
|
60
|
|
|
|
|
61
|
|
|
return $parameters; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Trả về mã đơn hàng cần thực thi tác vụ. |
|
66
|
|
|
* Đây là phương thức ánh xạ của [[getTransactionId()]]. |
|
67
|
|
|
* |
|
68
|
|
|
* @return null|string |
|
69
|
|
|
* @see getTransactionId |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getVnpTxnRef(): ?string |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->getTransactionId(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Thiết lập mã đơn hàng cần thực thi tác vụ. |
|
78
|
|
|
* Đây là phương thức ánh xạ của [[setTransactionId()]]. |
|
79
|
|
|
* |
|
80
|
|
|
* @param null|string $ref |
|
81
|
|
|
* |
|
82
|
|
|
* @return $this |
|
83
|
|
|
* @see setTransactionId |
|
84
|
|
|
*/ |
|
85
|
|
|
public function setVnpTxnRef(?string $ref) |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->setTransactionId($ref); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getTransactionId(): ?string |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->getParameter('vnp_TxnRef'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritdoc} |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setTransactionId($value) |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->setParameter('vnp_TxnRef', $value); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Trả về thông tin đơn hàng hay lý do truy vấn đến VNPay. |
|
108
|
|
|
* |
|
109
|
|
|
* @return null|string |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getVnpOrderInfo(): ?string |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->getParameter('vnp_OrderInfo'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Thiết lập thông tin đơn hàng hay lý do truy vấn đến VNPay. |
|
118
|
|
|
* |
|
119
|
|
|
* @param null|string $info |
|
120
|
|
|
* @return $this |
|
121
|
|
|
*/ |
|
122
|
|
|
public function setVnpOrderInfo(?string $info) |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->setParameter('vnp_OrderInfo', $info); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Trả về thời gian khởi tạo truy vấn đến VNPay. |
|
129
|
|
|
* |
|
130
|
|
|
* @return null|string |
|
131
|
|
|
* @see getVnpReturnUrl |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getVnpCreateDate(): ?string |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->getParameter('vnp_CreateDate'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Thiết lập thời gian khởi tạo truy vấn đến VNPay. |
|
140
|
|
|
* Mặc định sẽ là thời gian hiện tại. |
|
141
|
|
|
* |
|
142
|
|
|
* @param null|string $date |
|
143
|
|
|
* @return $this |
|
144
|
|
|
* @see setReturnUrl |
|
145
|
|
|
*/ |
|
146
|
|
|
public function setVnpCreateDate(?string $date) |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->setParameter('vnp_CreateDate', $date); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Trả về ip của khách dùng để thanh toán. |
|
153
|
|
|
* Đây là phương thức ánh xạ của [[getClientIp()]]. |
|
154
|
|
|
* |
|
155
|
|
|
* @return null|string |
|
156
|
|
|
* @see getClientIp |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getVnpIpAddr(): ?string |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->getClientIp(); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Thiết lập ip của khách dùng để thanh toán. |
|
165
|
|
|
* Đây là phương thức ánh xạ của [[setClientIp()]]. |
|
166
|
|
|
* Mặc định nếu không thiết lập sẽ là IP của khách. |
|
167
|
|
|
* |
|
168
|
|
|
* @param null|string $ip |
|
169
|
|
|
* @return $this |
|
170
|
|
|
* @see setClientIp |
|
171
|
|
|
*/ |
|
172
|
|
|
public function setVnpIpAddr(?string $ip) |
|
173
|
|
|
{ |
|
174
|
|
|
return $this->setClientIp($ip); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* {@inheritdoc} |
|
179
|
|
|
*/ |
|
180
|
|
|
public function getClientIp(): ?string |
|
181
|
|
|
{ |
|
182
|
|
|
return $this->getParameter('vnp_IpAddr'); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* {@inheritdoc} |
|
187
|
|
|
*/ |
|
188
|
|
|
public function setClientIp($value) |
|
189
|
|
|
{ |
|
190
|
|
|
return $this->setParameter('vnp_IpAddr', $value); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Trả về phương thức mã hóa dùng để tạo chữ ký dự liệu (md5, sha256). |
|
195
|
|
|
* |
|
196
|
|
|
* @return null|string |
|
197
|
|
|
* @since 1.0.1 |
|
198
|
|
|
*/ |
|
199
|
|
|
public function getSecureHashType(): ?string |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->getParameter('vnp_SecureHashType'); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Thiết lập phương thức mã hóa dùng để tạo chữ ký dự liệu. |
|
206
|
|
|
* |
|
207
|
|
|
* @param null|string $secureHashType |
|
208
|
|
|
* |
|
209
|
|
|
* @return $this |
|
210
|
|
|
* @since 1.0.1 |
|
211
|
|
|
*/ |
|
212
|
|
|
public function setSecureHashType(?string $secureHashType) |
|
213
|
|
|
{ |
|
214
|
|
|
return $this->setParameter('vnp_SecureHashType', $secureHashType); |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|