Completed
Push — master ( 1be858...1c2c45 )
by Vuong
02:00
created

RequestData   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 35
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 6 1
A ensureAttributes() 0 16 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()
17
 *
18
 * @property PaymentClient $client
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
    public function rules()
30
    {
31
        return [
32
            [['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
    protected function ensureAttributes(array &$attributes)
41
    {
42
        $client = $this->getClient();
43
        parent::ensureAttributes($attributes);
44
45
        $attributesEnsured = $attributes;
46
        $attributesEnsured['website_id'] = $client->merchantId;
47
        $attributesEnsured['receiver_account'] = $attributes['receiver_account'] ?? $client->business;
48
        $attributesEnsured['currency'] = $attributes['currency'] ?? 'VND';
49
50
        ksort($attributesEnsured);
51
        $dataSign = implode('|', $attributesEnsured) . '|' . $client->secureCode;
52
        $attributesEnsured['signature'] = $client->signature($dataSign);
53
54
        $attributes = $attributesEnsured;
55
    }
56
57
}
58