RequestData::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
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
9
namespace yiiviet\payment\vtcpay;
10
11
use vxm\gatewayclients\RequestData as BaseRequestData;
12
13
/**
14
 * Lớp RequestData cung cấp dữ liệu để truy vấn đến VTCPay tạo lệnh thanh toán.
15
 *
16
 * @method PaymentClient getClient() đối tượng client đã dùng để thực thi request.
17
 *
18
 * @property PaymentClient $client đối tượng client đã dùng để thực thi request.
19
 *
20
 * @author Vuong Minh <[email protected]>
21
 * @since 1.0.2
22
 */
23
class RequestData extends BaseRequestData
24
{
25
26
    /**
27
     * @inheritdoc
28
     */
29 2
    public function rules()
30
    {
31
        return [
32 2
            [['website_id', 'signature', 'reference_number', 'receiver_account', 'currency', 'amount'], 'required', 'on' => PaymentGateway::RC_PURCHASE]
33
        ];
34
    }
35
36
    /**
37
     * @inheritdoc
38
     * @throws \yii\base\NotSupportedException
39
     */
40 2
    protected function ensureAttributes(array &$attributes)
41
    {
42 2
        $client = $this->getClient();
43 2
        parent::ensureAttributes($attributes);
44
45 2
        $attributesEnsured = $attributes;
46 2
        $attributesEnsured['website_id'] = $client->merchantId;
47 2
        $attributesEnsured['receiver_account'] = $attributes['receiver_account'] ?? $client->business;
48 2
        $attributesEnsured['currency'] = $attributes['currency'] ?? 'VND';
49
50 2
        unset($attributesEnsured['signature']);
51 2
        ksort($attributesEnsured);
52 2
        $dataSign = implode('|', $attributesEnsured);
53 2
        $attributesEnsured['signature'] = $client->signature($dataSign);
54
55 2
        $attributes = $attributesEnsured;
56 2
    }
57
58
}
59