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
|
|
|
use SignatureValidatorTrait; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritdoc |
44
|
|
|
* @throws \ReflectionException |
45
|
|
|
*/ |
46
|
4 |
|
public function scenarios() |
47
|
|
|
{ |
48
|
4 |
|
$requestCommands = $this->getClient()->getGateway()->requestCommands(); |
49
|
|
|
|
50
|
4 |
|
return array_fill_keys($requestCommands, ['signature']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @inheritdoc |
55
|
|
|
*/ |
56
|
4 |
|
public function rules() |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
4 |
|
['signature', 'required'], |
60
|
|
|
['signature', 'signatureValidator', 'message' => '{attribute} is not valid!'] |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritdoc |
66
|
|
|
*/ |
67
|
4 |
|
public function getIsOk(): bool |
68
|
|
|
{ |
69
|
4 |
|
return $this->validate(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
4 |
|
protected function getDataSignAttributes(): array |
76
|
|
|
{ |
77
|
4 |
|
switch ($this->getCommand()) { |
78
|
|
|
case PaymentGateway::RC_PURCHASE: |
79
|
4 |
|
return ['requestId', 'orderId', 'message', 'localMessage', 'payUrl', 'errorCode', 'requestType']; |
80
|
|
|
case PaymentGateway::RC_QUERY_DR: |
81
|
1 |
|
return ['partnerCode', 'accessKey', 'requestId', 'orderId', 'errorCode', 'transId', 'amount', 'message', 'localMessage', 'requestType', 'payType', 'extraData']; |
82
|
|
View Code Duplication |
case PaymentGateway::RC_REFUND: |
|
|
|
|
83
|
|
|
return ['partnerCode', 'accessKey', 'requestId', 'orderId', 'errorCode', 'transId', 'message', 'localMessage', 'requestType']; |
84
|
|
View Code Duplication |
case PaymentGateway::RC_QUERY_REFUND: |
|
|
|
|
85
|
|
|
return ['partnerCode', 'accessKey', 'requestId', 'orderId', 'errorCode', 'transId', 'amount', 'message', 'localMessage', 'requestType']; |
86
|
|
|
default: |
87
|
|
|
return []; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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.