|
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\onepay; |
|
9
|
|
|
|
|
10
|
|
|
use yii\helpers\ArrayHelper; |
|
11
|
|
|
use yiiviet\payment\VerifiedData as BaseVerifiedData; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class VerifiedData |
|
15
|
|
|
* |
|
16
|
|
|
* @method PaymentClient getClient() |
|
17
|
|
|
* |
|
18
|
|
|
* @property PaymentClient $client |
|
19
|
|
|
* |
|
20
|
|
|
* @author Vuong Minh <[email protected]> |
|
21
|
|
|
* @since 1.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class VerifiedData extends BaseVerifiedData |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
use MagicPropertiesTrait; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @inheritdoc |
|
30
|
|
|
*/ |
|
31
|
4 |
View Code Duplication |
public function rules() |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
return [ |
|
34
|
4 |
|
[['vpc_SecureHash'], 'validateSecureHash', 'message' => '{attribute} is not valid!', 'on' => [ |
|
35
|
|
|
PaymentGateway::VRC_IPN, PaymentGateway::VRC_PURCHASE_SUCCESS |
|
36
|
|
|
], 'skipOnEmpty' => false] |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Phương thức kiểm tra chữ ký dữ liệu nhận từ OnePay. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $attribute Attribute chứa giá trị chữ ký cần kiểm tra. |
|
44
|
|
|
* @param array $params Mảng các tham trị được thiết lập từ rule. |
|
45
|
|
|
* @param \yii\validators\InlineValidator $validator Đối tượng thực thi kiểm tra. |
|
46
|
|
|
* @throws \yii\base\InvalidConfigException|\yii\base\NotSupportedException |
|
47
|
|
|
*/ |
|
48
|
4 |
|
public function validateSecureHash($attribute, $params, \yii\validators\InlineValidator $validator) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
4 |
|
$data = $this->get(false); |
|
51
|
4 |
|
$expectSignature = ArrayHelper::remove($data, $attribute, false); |
|
52
|
4 |
|
$dataSign = []; |
|
53
|
|
|
|
|
54
|
4 |
|
foreach ($data as $param => $value) { |
|
55
|
|
|
if (strpos($param, 'vpc_') === 0) { |
|
56
|
|
|
$dataSign[$param] = $value; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
4 |
|
ksort($dataSign); |
|
61
|
4 |
|
$data = urldecode(http_build_query($dataSign)); |
|
62
|
|
|
|
|
63
|
4 |
|
if (!$expectSignature || !$this->getClient()->validateSignature($data, $expectSignature)) { |
|
64
|
4 |
|
$validator->addError($this, $attribute, $validator->message); |
|
65
|
|
|
} |
|
66
|
4 |
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.