VerifiedData::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 2
cts 2
cp 1
rs 10
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\nganluong;
9
10
use yiiviet\payment\VerifiedData as BaseVerifiedData;
11
12
/**
13
 * Lớp VerifiedData cung cấp dữ liệu đã được xác thực từ Ngân Lượng gửi về.
14
 *
15
 * @method PaymentClient getClient() đối tượng client đã dùng để thực thi request.
16
 *
17
 * @property PaymentClient $client đối tượng client đã dùng để thực thi request.
18
 * @property string $token mã token dùng để truy vấn thông tin giao dịch.
19
 * @property string $error_code mã lỗi, chỉ tồn tại khi `token` hợp lệ.
20
 * @property mixed $order_code mã giao dịch tại hệ thống, chỉ tồn tại khi `token` hợp lệ.
21
 * @property double $total_amount số tiền đơn hàng, chỉ tồn tại khi `token` hợp lệ.
22
 * @property string $payment_method phương thức thanh toán, chỉ tồn tại khi `token` hợp lệ.
23
 * @property string $bank_code mã ngân hàng, chỉ tồn tại khi `token` hợp lệ.
24
 * @property string $payment_type hình thức thanh toán `1` là trực tiếp, `2` là tạm giữ, chỉ tồn tại khi `token` hợp lệ.
25
 * @property string $order_description thông tin đơn hàng, chỉ tồn tại khi `token` hợp lệ.
26
 * @property double $tax_amount tiền thuế, chỉ tồn tại khi `token` hợp lệ.
27
 * @property double $discount_amount tiền giảm giá, chỉ tồn tại khi `token` hợp lệ.
28
 * @property double $fee_shipping phí ship, chỉ tồn tại khi `token` hợp lệ.
29
 * @property string $return_url đường dẫn trả về khi thanh toán thành công, chỉ tồn tại khi `token` hợp lệ.
30
 * @property string $cancel_url đường dẫn trả về khi hủy thành công, chỉ tồn tại khi `token` hợp lệ.
31
 * @property string $notify_url đường dẫn Ngân Lượng gọi về khi khách thanh toán thành công, chỉ tồn tại khi `token` hợp lệ.
32
 * @property int $time_limit số phút còn lại để thực thi giao dịch, chỉ tồn tại khi `token` hợp lệ.
33
 * @property string $buyer_fullname tên người mua, chỉ tồn tại khi `token` hợp lệ.
34
 * @property string $buyer_email email người mua, chỉ tồn tại khi `token` hợp lệ.
35
 * @property string $buyer_mobile số điện thoại người mua, chỉ tồn tại khi `token` hợp lệ.
36
 * @property string $buyer_address địa chỉ người mua, chỉ tồn tại khi `token` hợp lệ.
37
 * @property string $affiliate_code mã đối tác của Ngân Lượng, chỉ tồn tại khi `token` hợp lệ.
38
 * @property string $transaction_status trạng thái giao dịch, chỉ tồn tại khi `token` hợp lệ.
39
 * @property string $transaction_id mã giao dịch tại Ngân Lượng, chỉ tồn tại khi `token` hợp lệ.
40
 * @property string $description thông tin giao dịch tại Ngân Lượng, chỉ tồn tại khi `token` hợp lệ.
41
 *
42
 * @author Vuong Minh <[email protected]>
43
 * @since 1.0
44
 */
45
class VerifiedData extends BaseVerifiedData
46
{
47
48
    /**
49
     * @inheritdoc
50
     */
51 1
    public function rules()
52
    {
53
        return [
54 1
            [['token'], 'required', 'on' => PaymentGateway::VRC_PURCHASE_SUCCESS],
55
            [['token'], 'ensureToken', 'message' => '{attribute} invalid!', 'on' => PaymentGateway::VRC_PURCHASE_SUCCESS]
56
        ];
57
    }
58
59
    /**
60
     * Phương thức kiểm tra tính hợp lệ của mã `token` gửi từ Ngân Lượng.
61
     *
62
     * @param string $attribute Chứa giá trị thuộc tính cần kiểm tra.
63
     * @param string $params Mảng thông tin khi thiết lập rule.
64
     * @param \yii\validators\InlineValidator $validator Đối tượng [[\yii\validators\InlineValidator]] đang thực thi kiểm tra dữ liệu.
65
     * @throws \ReflectionException|\yii\base\InvalidConfigException
66
     */
67
    public function ensureToken($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...
68
    {
69
        $response = $this->getClient()->getGateway()->queryDR(['token' => $this->token]);
70
71
        if (!$response->isOk) {
72
            $validator->addError($this, $attribute, $validator->message);
73
        } else {
74
            foreach ($response->get(false) as $attr => $value) {
75
                $this->defineAttribute($attr, $value);
76
            }
77
        }
78
    }
79
80
}
81