Completed
Push — master ( 22ac66...ff3f53 )
by Vuong
02:08
created

ResponseData::getIsOk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 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_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_REFUND, PaymentGateway::RC_QUERY_REFUND]].
21
 * @property mixed $requestId mã unique request id khi tạo request [[PaymentGateway::RC_QUERY_DR, PaymentGateway::RC_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_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 int $errorCode mã báo lỗi.
29
 * @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]].
30
 * @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]].
31
 * @property string $payUrl đường dẫn thanh toán chỉ tồn tại khi tạo request [[PaymentGateway::RC_PURCHASE]].
32
 *
33
 * @author Vuong Minh <[email protected]>
34
 * @since 1.0.3
35
 */
36
class ResponseData extends BaseResponseData
37
{
38
39
    /**
40
     * @inheritdoc
41
     * @throws \ReflectionException
42
     */
43 4
    public function scenarios()
44
    {
45 4
        $requestCommands = $this->getClient()->getGateway()->requestCommands();
46
47 4
        return array_fill_keys($requestCommands, ['signature']);
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53 4
    public function rules()
54
    {
55
        return [
56 4
            ['signature', 'required'],
57 4
            ['signature', SignatureValidator::class, 'client' => $this->getClient(), 'dataSignAttributes' => $this->getDataSignAttributes()]
58
        ];
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64 4
    public function getIsOk(): bool
65
    {
66 4
        return $this->validate();
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72 4
    protected function getDataSignAttributes(): array
73
    {
74 4
        switch ($this->getCommand()) {
75
            case PaymentGateway::RC_PURCHASE:
76 4
                return ['requestId', 'orderId', 'message', 'localMessage', 'payUrl', 'errorCode', 'requestType'];
77
            case PaymentGateway::RC_QUERY_DR:
78 1
                return ['partnerCode', 'accessKey', 'requestId', 'orderId', 'errorCode', 'transId', 'amount', 'message', 'localMessage', 'requestType', 'payType', 'extraData'];
79 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...
80 1
                return ['partnerCode', 'accessKey', 'requestId', 'orderId', 'errorCode', 'transId', 'message', 'localMessage', 'requestType'];
81 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...
82 1
                return ['partnerCode', 'accessKey', 'requestId', 'orderId', 'errorCode', 'transId', 'amount', 'message', 'localMessage', 'requestType'];
83
            default:
84
                return [];
85
        }
86
    }
87
}
88