VerifiedData::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 2
cts 2
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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
12
use yiiviet\payment\VerifiedData as BaseVerifiedData;
13
14
/**
15
 * Lớp VerifiedData cung cấp dữ liệu đã được xác thực từ OnePay gửi về.
16
 *
17
 * @method PaymentClient getClient() đối tượng client đã dùng để thực thi request.
18
 *
19
 * @property PaymentClient $client đối tượng client đã dùng để thực thi request.
20
 * @property mixed $OrderInfo mô tả đơn hảng.
21
 * @property mixed $MerchTxnRef mã đơn hàng trên hệ thống của bạn.
22
 * @property int $Amount số tiền.
23
 * @property string $Locale ngôn ngữ khách dùng để thanh toán.
24
 * @property string $CurrencyCode mã tiền tệ.
25
 * @property string $Merchant merchant id.
26
 * @property string $TransactionNo mã giao dịch tại OnePay.
27
 *
28
 * @author Vuong Minh <[email protected]>
29
 * @since 1.0
30
 */
31
class VerifiedData extends BaseVerifiedData
32
{
33
34
    use MagicPropertiesTrait;
35
36
    /**
37
     * @inheritdoc
38
     */
39 4 View Code Duplication
    public function rules()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
40
    {
41
        return [
42 4
            [['vpc_SecureHash'], 'required', 'on' => [
43
                PaymentGateway::VRC_IPN, PaymentGateway::VRC_PURCHASE_SUCCESS
44
            ]],
45
            [['vpc_SecureHash'], 'validateSecureHash', 'message' => '{attribute} is not valid!', 'on' => [
46
                PaymentGateway::VRC_IPN, PaymentGateway::VRC_PURCHASE_SUCCESS
47
            ]]
48
        ];
49
    }
50
51
    /**
52
     * Phương thức kiểm tra chữ ký dữ liệu nhận từ OnePay.
53
     *
54
     * @param string $attribute Attribute chứa giá trị chữ ký cần kiểm tra.
55
     * @param array $params Mảng các tham trị được thiết lập từ rule.
56
     * @param \yii\validators\InlineValidator $validator Đối tượng thực thi kiểm tra.
57
     * @throws \yii\base\InvalidConfigException|\yii\base\NotSupportedException
58
     */
59
    public function validateSecureHash($attribute, $params, \yii\validators\InlineValidator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
        $data = $this->get(false);
62
        $expectSignature = ArrayHelper::remove($data, $attribute, false);
63
        $dataSign = [];
64
65
        foreach ($data as $param => $value) {
66
            if (strpos($param, 'vpc_') === 0) {
67
                $dataSign[$param] = $value;
68
            }
69
        }
70
71
        ksort($dataSign);
72
        $data = urldecode(http_build_query($dataSign));
73
74
        if (!$expectSignature || !$this->getClient()->validateSignature($data, $expectSignature)) {
75
            $validator->addError($this, $attribute, $validator->message);
76
        }
77
    }
78
79
}
80