|
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\baokim; |
|
9
|
|
|
|
|
10
|
|
|
use yii\base\InvalidConfigException; |
|
11
|
|
|
use yii\helpers\ArrayHelper; |
|
12
|
|
|
|
|
13
|
|
|
use yiiviet\payment\VerifiedData as BaseVerifiedData; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Lớp VerifiedData cung cấp dữ liệu đã được xác minh từ các truy vấn IPN, success url. |
|
17
|
|
|
* |
|
18
|
|
|
* @method PaymentClient getClient() đối tượng client đã dùng để thực thi request. |
|
19
|
|
|
* |
|
20
|
|
|
* @property PaymentClient $client đối tượng client đã dùng để thực thi request. |
|
21
|
|
|
* @property mixed $order_id mã đơn hàng tại hệ thống. |
|
22
|
|
|
* @property int $created_on thời gian tạo đơn hàng (timestamp). |
|
23
|
|
|
* @property int $payment_type hình thức khách giao dịch (1 Trực tiếp, 2 Tạm giữ). |
|
24
|
|
|
* @property int $transaction_status trạng thái giao dịch. |
|
25
|
|
|
* @property int $total_amount tổng số tiền khách trả. |
|
26
|
|
|
* @property int $net_amount tổng số tiền thực nhận. |
|
27
|
|
|
* @property int $fee_amount số tiền phí Bảo Kim thu. |
|
28
|
|
|
* @property int $merchant_id mã website tích hợp. |
|
29
|
|
|
* @property int $transaction_id mã giao dịch tại Bảo Kim. |
|
30
|
|
|
* @property string $payer_name tên người mua, chỉ tồn tại khi phương thức thanh toán thông qua bảo kim không phải `pro`. |
|
31
|
|
|
* @property string $payer_email email người mua, chỉ tồn tại khi phương thức thanh toán thông qua bảo kim không phải `pro`. |
|
32
|
|
|
* @property string $payer_phone_no số điện thoại người mua, chỉ tồn tại khi phương thức thanh toán thông qua bảo kim không phải `pro`. |
|
33
|
|
|
* @property string $shipping_address địa chỉ giao hàng, chỉ tồn tại khi phương thức thanh toán thông qua bảo kim không phải `pro`. |
|
34
|
|
|
* @property string $customer_name tên người mua, chỉ tồn tại khi phương thức thanh toán `pro`. |
|
35
|
|
|
* @property string $customer_email email người mua, chỉ tồn tại khi phương thức thanh toán `pro`. |
|
36
|
|
|
* @property string $customer_phone số điện thoại người mua, chỉ tồn tại khi phương thức thanh toán `pro`. |
|
37
|
|
|
* @property string $customer_address địa chỉ giao hàng, chỉ tồn tại khi phương thức thanh toán `pro`. |
|
38
|
|
|
* @property string $merchant_address địa chỉ merchant, chỉ tồn tại khi phương thức thanh toán `pro`. |
|
39
|
|
|
* @property string $merchant_email email merchant, chỉ tồn tại khi phương thức thanh toán `pro`. |
|
40
|
|
|
* @property string $merchant_location khu vực merchant, chỉ tồn tại khi phương thức thanh toán `pro`. |
|
41
|
|
|
* @property string $merchant_name tên người bán (merchant), chỉ tồn tại khi phương thức thanh toán `pro`. |
|
42
|
|
|
* @property string $merchant_phone số điên thoại người bán, chỉ tồn tại khi phương thức thanh toán `pro`. |
|
43
|
|
|
* @property string $customer_location khu vực khách hàng, chỉ tồn tại khi phương thức thanh toán `pro`. |
|
44
|
|
|
* |
|
45
|
|
|
* @author Vuong Minh <[email protected]> |
|
46
|
|
|
* @since 1.0 |
|
47
|
|
|
*/ |
|
48
|
|
|
class VerifiedData extends BaseVerifiedData |
|
49
|
|
|
{ |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritdoc |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function rules() |
|
55
|
|
|
{ |
|
56
|
|
|
return [ |
|
57
|
1 |
|
[['checksum'], 'required', 'on' => PaymentGateway::VRC_PURCHASE_SUCCESS], |
|
58
|
|
|
[['checksum'], 'verifyChecksum', 'message' => '{attribute} not match', 'on' => PaymentGateway::VRC_PURCHASE_SUCCESS] |
|
59
|
|
|
]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Phương thức kiểm tra tính hợp lệ của mã `checksum` gửi từ Bảo Kim. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $attribute Chứa giá trị thuộc tính cần kiểm tra. |
|
66
|
|
|
* @param string $params Mảng thông tin khi thiết lập rule. |
|
67
|
|
|
* @param \yii\validators\InlineValidator $validator Đối tượng [[\yii\validators\InlineValidator]] đang thực thi kiểm tra dữ liệu. |
|
68
|
|
|
* @throws \yii\base\NotSupportedException|InvalidConfigException |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function verifyChecksum($attribute, $params, \yii\validators\InlineValidator $validator) |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
/** @var PaymentClient $client */ |
|
73
|
1 |
|
$client = $this->getClient(); |
|
74
|
1 |
|
$data = $this->get(false); |
|
75
|
1 |
|
$expectSignature = ArrayHelper::remove($data, $attribute, false); |
|
76
|
1 |
|
ksort($data); |
|
77
|
1 |
|
$dataSign = implode('', $data); |
|
78
|
|
|
|
|
79
|
1 |
View Code Duplication |
if (!$expectSignature || !$client->validateSignature($dataSign, $expectSignature, PaymentClient::SIGNATURE_HMAC)) { |
|
|
|
|
|
|
80
|
1 |
|
$validator->addError($this, $attribute, $validator->message); |
|
81
|
|
|
} |
|
82
|
1 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.