Completed
Push — master ( 22f05f...6ee38e )
by Vuong
02:09
created

PaymentClient::init()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.5923

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 6
cts 9
cp 0.6667
rs 9.7333
c 0
b 0
f 0
cc 4
nc 4
nop 0
crap 4.5923
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 Yii;
12
13
use yii\base\InvalidConfigException;
14
15
use yiiviet\payment\BasePaymentClient;
16
use yiiviet\payment\DataSignature;
17
18
/**
19
 * Lớp PaymentClient hổ trợ tạo và kiểm tra chữ ký dữ liệu và có các thuộc tính kết nối đến cổng thanh toán VTCPay.
20
 *
21
 * @author Vuong Minh <[email protected]>
22
 * @since 1.0.2
23
 */
24
class PaymentClient extends BasePaymentClient
25
{
26
27
    /**
28
     * @var string tài khoản nhận tiền mặc định khi thực hiện giao dịch.
29
     */
30
    public $business;
31
32
    /**
33
     * @var string Mã bảo vệ nhận khi đăng ký tích hợp.
34
     */
35
    public $secureCode;
36
37
    /**
38
     * @var string Mã website nhận khi đăng ký
39
     */
40
    public $merchantId;
41
42
    /**
43
     * @inheritdoc
44
     * @throws InvalidConfigException
45
     * @since 1.0.3
46
     */
47 13
    public function init()
48
    {
49 13
        if ($this->business === null) {
50
            throw new InvalidConfigException('Property `business` must be set!');
51
        }
52
53 13
        if ($this->secureCode === null) {
54
            throw new InvalidConfigException('Property `secureCode` must be set!');
55
        }
56
57 13
        if ($this->merchantId === null) {
58
            throw new InvalidConfigException('Property `merchantId` must be set!');
59
        }
60
61 13
        parent::init();
62 13
    }
63
64
    /**
65
     * @inheritdoc
66
     * @return object|\yiiviet\payment\HashDataSignature
67
     * @throws \yii\base\InvalidConfigException
68
     */
69 7
    protected function initDataSignature(string $data, string $type = null): ?DataSignature
70
    {
71 7
        $data .= '|' . $this->secureCode;
72
73 7
        return Yii::createObject([
74 7
            'class' => 'yiiviet\payment\HashDataSignature',
75
            'hashAlgo' => 'sha256'
76 7
        ], [$data]);
77
    }
78
79
}
80