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

PaymentClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 60
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 16 4
A initDataSignature() 0 8 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\momo;
9
10
use Yii;
11
12
use yii\base\InvalidConfigException;
13
14
use yiiviet\payment\BasePaymentClient;
15
use yiiviet\payment\DataSignature;
16
use yiiviet\payment\HmacDataSignature;
17
18
/**
19
 * Lớp PaymentClient chứa các thuộc tính dùng để hổ trợ [[PaymentGateway]] kết nối đến MOMO.
20
 *
21
 * @method PaymentGateway getGateway()
22
 * @property PaymentGateway $gateway
23
 *
24
 * @author Vuong Minh <[email protected]>
25
 * @since 1.0
26
 */
27
class PaymentClient extends BasePaymentClient
28
{
29
    /**
30
     * Thuộc tính dùng để khai báo kết nối đến MOMO khi tạo [[request()]] ở [[PaymentGateway]].
31
     * Nó do MOMO cấp khi đăng ký tích hợp website.
32
     *
33
     * @var string
34
     */
35
    public $partnerCode;
36
37
    /**
38
     * Thuộc tính dùng để khai báo kết nối đến MOMO khi tạo [[request()]] ở [[PaymentGateway]].
39
     * Nó do MOMO cấp khi đăng ký tích hợp website.
40
     *
41
     * @var string
42
     */
43
    public $accessKey;
44
45
    /**
46
     * Thuộc tính được dùng để tạo chữ ký dữ liệu khi tạo [[request()]] ở [[PaymentGateway]].
47
     *
48
     * @var string
49
     */
50
    public $secretKey;
51
52
    /**
53
     * @inheritdoc
54
     * @throws InvalidConfigException
55
     */
56
    public function init()
57
    {
58
        if ($this->partnerCode === null) {
59
            throw new InvalidConfigException('Property `partnerCode` must be set!');
60
        }
61
62
        if ($this->accessKey === null) {
63
            throw new InvalidConfigException('Property `accessKey` must be set!');
64
        }
65
66
        if ($this->secretKey === null) {
67
            throw new InvalidConfigException('Property `secretKey` must be set!');
68
        }
69
70
        parent::init();
71
    }
72
73
    /**
74
     * @inheritdoc
75
     * @return DataSignature|null|object
76
     * @throws \yii\base\InvalidConfigException
77
     */
78
    protected function initDataSignature(string $data, string $type = null): ?DataSignature
79
    {
80
        return Yii::createObject([
81
            'class' => HmacDataSignature::class,
82
            'key' => $this->secretKey,
83
            'hmacAlgo' => 'sha256'
84
        ]);
85
    }
86
}
87