Completed
Pull Request — master (#15)
by
unknown
02:55
created

PaymentClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 62
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 16 4
A initDataSignature() 0 10 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 nhuluc\payment\vtcpay;
10
11
use Yii;
12
13
use yii\base\InvalidConfigException;
14
15
use nhuluc\payment\BasePaymentClient;
16
use nhuluc\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 Nhu Luc <[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
     * @var bool phân biệt ký tự hoa thường khi xác minh chữ ký.
44
     */
45
    public $caseSensitive = false;
46
47 13
    /**
48
     * @inheritdoc
49 13
     * @throws InvalidConfigException
50
     * @since 1.0.3
51
     */
52
    public function init()
53 13
    {
54
        if ($this->business === null) {
55
            throw new InvalidConfigException('Property `business` must be set!');
56
        }
57 13
58
        if ($this->secureCode === null) {
59
            throw new InvalidConfigException('Property `secureCode` must be set!');
60
        }
61 13
62 13
        if ($this->merchantId === null) {
63
            throw new InvalidConfigException('Property `merchantId` must be set!');
64
        }
65
66
        parent::init();
67
    }
68
69 7
    /**
70
     * @inheritdoc
71 7
     * @return object|\yiiviet\payment\HashDataSignature
72
     * @throws \yii\base\InvalidConfigException
73 7
     */
74 7
    protected function initDataSignature(string $data, string $type = null): ?DataSignature
75
    {
76 7
        $data .= '|' . $this->secureCode;
77
78
        return Yii::createObject([
79
            'class' => 'nhuluc\payment\HashDataSignature',
80
            'hashAlgo' => 'sha256',
81
            'caseSensitive' => $this->caseSensitive
82
        ], [$data]);
83
    }
84
85
}
86