1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiiviet/yii2-payment |
4
|
|
|
* @copyright Copyright (c) 2017 Yii Viet |
5
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace yiiviet\payment\vtcpay; |
10
|
|
|
|
11
|
|
|
use vxm\gatewayclients\RequestData as BaseRequestData; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Lớp RequestData cung cấp dữ liệu để truy vấn đến VTCPay tạo lệnh thanh toán. |
15
|
|
|
* |
16
|
|
|
* @method PaymentClient getClient() đối tượng client đã dùng để thực thi request. |
17
|
|
|
* |
18
|
|
|
* @property PaymentClient $client đối tượng client đã dùng để thực thi request. |
19
|
|
|
* |
20
|
|
|
* @author Vuong Minh <[email protected]> |
21
|
|
|
* @since 1.0.2 |
22
|
|
|
*/ |
23
|
|
|
class RequestData extends BaseRequestData |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritdoc |
28
|
|
|
*/ |
29
|
2 |
|
public function rules() |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
2 |
|
[['website_id', 'signature', 'reference_number', 'receiver_account', 'currency', 'amount'], 'required', 'on' => PaymentGateway::RC_PURCHASE] |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritdoc |
38
|
|
|
* @throws \yii\base\NotSupportedException |
39
|
|
|
*/ |
40
|
2 |
|
protected function ensureAttributes(array &$attributes) |
41
|
|
|
{ |
42
|
2 |
|
$client = $this->getClient(); |
43
|
2 |
|
parent::ensureAttributes($attributes); |
44
|
|
|
|
45
|
2 |
|
$attributesEnsured = $attributes; |
46
|
2 |
|
$attributesEnsured['website_id'] = $client->merchantId; |
47
|
2 |
|
$attributesEnsured['receiver_account'] = $attributes['receiver_account'] ?? $client->business; |
48
|
2 |
|
$attributesEnsured['currency'] = $attributes['currency'] ?? 'VND'; |
49
|
|
|
|
50
|
2 |
|
unset($attributesEnsured['signature']); |
51
|
2 |
|
ksort($attributesEnsured); |
52
|
2 |
|
$dataSign = implode('|', $attributesEnsured); |
53
|
2 |
|
$attributesEnsured['signature'] = $client->signature($dataSign); |
54
|
|
|
|
55
|
2 |
|
$attributes = $attributesEnsured; |
56
|
2 |
|
} |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|