Completed
Push — master ( fdaf8f...ad3506 )
by Vuong
02:10
created

ResponseData::getDataSignAttributes()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 15

Duplication

Lines 4
Ratio 26.67 %

Code Coverage

Tests 10
CRAP Score 5.0187

Importance

Changes 0
Metric Value
dl 4
loc 15
ccs 10
cts 11
cp 0.9091
rs 9.4555
c 0
b 0
f 0
cc 5
nc 5
nop 0
crap 5.0187
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 vxm\gatewayclients\ResponseData as BaseResponseData;
11
12
/**
13
 * Lớp ResponseData cung cấp dữ liệu nhận được từ MOMO khi tạo [[request()]] ở [[PaymentGateway]].
14
 *
15
 * @method PaymentClient getClient() đối tượng client đã dùng để thực thi request.
16
 *
17
 * @property PaymentClient $client đối tượng client đã dùng để thực thi request.
18
 *
19
 * @property string $partnerCode của client sử dụng khi tạo request [[PaymentGateway::RC_QUERY_DR, PaymentGateway::RC_QUERY_REFUND, PaymentGateway::RC_QUERY_REFUND]].
20
 * @property string $accessKey của client sử dụng khi tạo request [[PaymentGateway::RC_QUERY_DR, PaymentGateway::RC_QUERY_REFUND, PaymentGateway::RC_QUERY_REFUND]].
21
 * @property mixed $requestId mã unique request id khi tạo request [[PaymentGateway::RC_QUERY_DR, PaymentGateway::RC_QUERY_REFUND, PaymentGateway::RC_QUERY_REFUND]].
22
 * @property double $amount số tiền của đơn hàng chỉ tồn tại với request [[PaymentGateway::RC_QUERY_DR, PaymentGateway::RC_QUERY_REFUND]].
23
 * @property string $orderId mã đơn hàng tại hệ thống.
24
 * @property string $orderType có giá trị cố định là `momo_wallet`.
25
 * @property string $transId mã giao dịch tại MOMO chỉ tồn tại khi tạo request [[PaymentGateway::RC_QUERY_DR, PaymentGateway::RC_QUERY_REFUND, PaymentGateway::RC_QUERY_REFUND]].
26
 * @property string $message thống báo (eng).
27
 * @property string $localMessage thống báo (vi).
28
 * @property string $responseTime thời gian phản hồi.
29
 * @property int $errorCode mã báo lỗi.
30
 * @property string $payType hình thức thanh toán (web hoặc qr) chỉ tồn tại khi tạo request [[PaymentGateway::RC_QUERY_DR]].
31
 * @property mixed $extraData dữ liệu kèm theo khi tạo request purchase chỉ tồn tại khi tạo request [[PaymentGateway::RC_QUERY_DR]].
32
 * @property string $payUrl đường dẫn thanh toán chỉ tồn tại khi tạo request [[PaymentGateway::RC_PURCHASE]].
33
 *
34
 * @author Vuong Minh <[email protected]>
35
 * @since 1.0.3
36
 */
37
class ResponseData extends BaseResponseData
38
{
39
40
    /**
41
     * @inheritdoc
42
     * @throws \ReflectionException
43
     */
44 4
    public function scenarios()
45
    {
46 4
        $requestCommands = $this->getClient()->getGateway()->requestCommands();
47
48 4
        return array_fill_keys($requestCommands, ['signature']);
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 4
    public function rules()
55
    {
56
        return [
57 4
            ['signature', 'required'],
58 4
            ['signature', SignatureValidator::class, 'client' => $this->getClient(), 'dataSignAttributes' => $this->getDataSignAttributes()]
59
        ];
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65 4
    public function getIsOk(): bool
66
    {
67 4
        return $this->validate();
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73 4
    protected function getDataSignAttributes(): array
74
    {
75 4
        switch ($this->getCommand()) {
76 4
            case PaymentGateway::RC_PURCHASE:
77 4
                return ['requestId', 'orderId', 'message', 'localMessage', 'payUrl', 'errorCode', 'requestType'];
78 3
            case PaymentGateway::RC_QUERY_DR:
79 1
                return ['partnerCode', 'accessKey', 'requestId', 'orderId', 'errorCode', 'transId', 'amount', 'message', 'localMessage', 'requestType', 'payType', 'extraData'];
80 2 View Code Duplication
            case PaymentGateway::RC_REFUND:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81 1
                return ['partnerCode', 'accessKey', 'requestId', 'orderId', 'errorCode', 'transId', 'message', 'localMessage', 'requestType'];
82 1 View Code Duplication
            case PaymentGateway::RC_QUERY_REFUND:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83 1
                return ['partnerCode', 'accessKey', 'requestId', 'orderId', 'errorCode', 'transId', 'amount', 'message', 'localMessage', 'requestType'];
84
            default:
85
                return [];
86
        }
87
    }
88
}
89