|
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
|
|
|
namespace yiiviet\payment\nganluong; |
|
9
|
|
|
|
|
10
|
|
|
use vxm\gatewayclients\RequestData as BaseRequestData; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Lớp RequestData cung cấp dữ liệu cho phương thức [[request()]] theo lệnh, để truy vấn với Ngân Lượng. |
|
14
|
|
|
* |
|
15
|
|
|
* @property PaymentClient $client |
|
16
|
|
|
* |
|
17
|
|
|
* @author Vuong Minh <[email protected]> |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class RequestData extends BaseRequestData |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @inheritdoc |
|
25
|
|
|
*/ |
|
26
|
4 |
|
public function rules() |
|
27
|
|
|
{ |
|
28
|
|
|
return [ |
|
29
|
4 |
|
[['merchant_id', 'merchant_password', 'version', 'function'], 'required'], |
|
30
|
|
|
[[ |
|
31
|
|
|
'bank_code', 'buyer_fullname', 'buyer_email', 'buyer_mobile', |
|
32
|
|
|
'total_amount', 'order_code', 'receiver_email', 'payment_method' |
|
33
|
|
|
], 'required', 'on' => PaymentGateway::RC_PURCHASE], |
|
34
|
|
|
[['otp', 'auth_url'], 'required', 'on' => PaymentGateway::RC_AUTHENTICATE], |
|
35
|
|
|
[['token'], 'required', 'on' => [PaymentGateway::RC_QUERY_DR, PaymentGateway::RC_AUTHENTICATE]] |
|
36
|
|
|
]; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
*/ |
|
42
|
4 |
|
protected function ensureAttributes(array &$attributes) |
|
43
|
|
|
{ |
|
44
|
|
|
/** @var PaymentClient $client */ |
|
45
|
4 |
|
$client = $this->getClient(); |
|
46
|
4 |
|
$command = $this->getCommand(); |
|
47
|
|
|
|
|
48
|
4 |
|
$attributes = array_merge($attributes, [ |
|
49
|
4 |
|
'merchant_id' => $client->merchantId, |
|
50
|
4 |
|
'merchant_password' => md5($client->merchantPassword), |
|
51
|
4 |
|
'version' => $client->getGateway()->getVersion() |
|
52
|
|
|
]); |
|
53
|
|
|
|
|
54
|
4 |
|
if ($command === PaymentGateway::RC_PURCHASE) { |
|
55
|
2 |
|
$attributes['function'] = 'SetExpressCheckout'; |
|
56
|
2 |
|
$attributes['receiver_email'] = $attributes['receiver_email'] ?? $client->email; |
|
57
|
|
|
|
|
58
|
2 |
|
if ($attributes['version'] === PaymentGateway::VERSION_3_2) { |
|
59
|
1 |
|
$attributes['payment_method'] = $attributes['payment_method'] ?? PaymentGateway::PAYMENT_METHOD_ATM_ONLINE; |
|
60
|
1 |
|
$this->addRule(['card_number', 'card_fullname', 'card_month', 'card_year'], 'required', [ |
|
61
|
1 |
|
'on' => $command |
|
62
|
|
|
]); |
|
63
|
|
|
} else { |
|
64
|
2 |
|
$attributes['payment_method'] = $attributes['payment_method'] ?? PaymentGateway::PAYMENT_METHOD_NL; |
|
65
|
|
|
} |
|
66
|
2 |
|
} elseif ($command === PaymentGateway::RC_AUTHENTICATE) { |
|
67
|
1 |
|
$attributes['function'] = 'AuthenTransaction'; |
|
68
|
|
|
} else { |
|
69
|
1 |
|
$attributes['function'] = 'GetTransactionDetail'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
4 |
|
parent::ensureAttributes($attributes); |
|
73
|
4 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|