|
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 yii\helpers\ArrayHelper; |
|
12
|
|
|
|
|
13
|
|
|
use yiiviet\payment\VerifiedData as BaseVerifiedData; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Lớp VerifiedData tổng hợp dữ liệu đã được xác minh từ VTCPay. |
|
17
|
|
|
* |
|
18
|
|
|
* @method PaymentClient getClient() |
|
19
|
|
|
* |
|
20
|
|
|
* @property PaymentClient $client |
|
21
|
|
|
* |
|
22
|
|
|
* @author Vuong Minh <[email protected]> |
|
23
|
|
|
* @since 1.0.2 |
|
24
|
|
|
*/ |
|
25
|
|
|
class VerifiedData extends BaseVerifiedData |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @inheritdoc |
|
30
|
|
|
*/ |
|
31
|
|
|
public function rules() |
|
32
|
|
|
{ |
|
33
|
|
|
return [ |
|
34
|
|
|
[['signature'], 'validateSignature', 'message' => '{attribute} is not valid!', 'on' => [ |
|
35
|
|
|
PaymentGateway::VRC_PURCHASE_SUCCESS, PaymentGateway::VRC_IPN |
|
36
|
|
|
], 'skipOnEmpty' => false] |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Phương thức kiểm tra chữ ký dữ liệu có hợp lệ hay không từ VTCPay gửi sang. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $attribute Attribute có giá trị là chữ ký cần kiểm tra. |
|
44
|
|
|
* @param array $params Mảng tham trị thiết lập từ rule |
|
45
|
|
|
* @param \yii\validators\InlineValidator $validator |
|
46
|
|
|
* @throws \yii\base\InvalidConfigException|\yii\base\NotSupportedException |
|
47
|
|
|
*/ |
|
48
|
|
|
public function validateSecureHash($attribute, $params, \yii\validators\InlineValidator $validator) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$client = $this->getClient(); |
|
51
|
|
|
$data = $this->get(false); |
|
52
|
|
|
$expectSignature = ArrayHelper::remove($data, $attribute, false); |
|
53
|
|
|
|
|
54
|
|
|
if ($this->command === PaymentGateway::VRC_IPN) { |
|
55
|
|
|
$dataSign = $data['data'] ?? ''; |
|
56
|
|
|
} else { |
|
57
|
|
|
ksort($data); |
|
58
|
|
|
$dataSign = implode('|', $data); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$dataSign .= '|' . $client->secureCode; |
|
62
|
|
|
|
|
63
|
|
|
if (!$expectSignature || !$client->validateSignature($dataSign, $expectSignature)) { |
|
64
|
|
|
$validator->addError($this, $attribute, $validator->message); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.