Completed
Push — master ( 4f7c7c...fdaf8f )
by Vuong
02:10
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
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 11
    public function init()
57
    {
58 11
        if ($this->partnerCode === null) {
59
            throw new InvalidConfigException('Property `partnerCode` must be set!');
60
        }
61
62 11
        if ($this->accessKey === null) {
63
            throw new InvalidConfigException('Property `accessKey` must be set!');
64
        }
65
66 11
        if ($this->secretKey === null) {
67
            throw new InvalidConfigException('Property `secretKey` must be set!');
68
        }
69
70 11
        parent::init();
71 11
    }
72
73
    /**
74
     * @inheritdoc
75
     * @return DataSignature|null|object
76
     * @throws \yii\base\InvalidConfigException
77
     */
78 8
    protected function initDataSignature(string $data, string $type = null): ?DataSignature
79
    {
80 8
        return Yii::createObject([
81 8
            'class' => HmacDataSignature::class,
82 8
            'key' => $this->secretKey,
83 8
            'hmacAlgo' => 'sha256',
84 8
        ], [$data]);
85
    }
86
}
87