Completed
Push — master ( 2d293e...b89557 )
by Vuong
02:12
created

PaymentGatewayCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 2
dl 0
loc 119
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A purchase() 0 4 1
A queryDR() 0 4 1
A refund() 0 4 1
A verifyRequestPurchaseSuccess() 0 4 1
A verifyRequestIPN() 0 4 1
A verifyRequest() 0 4 1
A queryRefund() 0 4 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;
9
10
use GatewayClients\DataInterface;
11
12
use vxm\gatewayclients\GatewayCollection;
13
14
/**
15
 * Lớp PaymentGatewayCollection dùng để tập hợp tất cả các cổng thanh toán thành 1 component trong app,
16
 * khi bạn có nhu cầu sử dụng nhiều cổng thanh toán.
17
 *
18
 * @method BasePaymentGateway getGateway($id)
19
 * @method BasePaymentGateway[] getGateways()
20
 *
21
 * @property BasePaymentGateway $gateway
22
 * @property BasePaymentGateway[] $gateways
23
 *
24
 * @author Vuong Minh <[email protected]>
25
 * @since 1.0
26
 */
27
class PaymentGatewayCollection extends GatewayCollection
28
{
29
    /**
30
     * Đây là phương thức ánh xạ của [[request()]]. Dùng để tạo lệnh thanh toán.
31
     *
32
     * @param array $data Dữ liệu thanh toán.
33
     * @param int|string $gatewayId Id của cổng thanh toán.
34
     * @param null|int|string $clientId Id client của cổng thanh toán dùng đề tạo lệnh.
35
     * Nếu không thiết lập thì [[getDefaultClient()]] sẽ được gọi trong cổng thanh toán.
36
     * @return \vxm\gatewayclients\ResponseData|DataInterface
37
     * @see [[BasePaymentGateway::purchase()]]
38
     * @throws \yii\base\InvalidConfigException
39
     */
40 8
    public function purchase(array $data, $gatewayId, $clientId = null): DataInterface
41
    {
42 8
        return $this->request(BasePaymentGateway::RC_PURCHASE, $data, $gatewayId, $clientId);
43
    }
44
45
    /**
46
     * Đây là phương thức ánh xạ của [[request()]]. Dùng để tạo lệnh truy vấn thông tin giao dịch.
47
     *
48
     * @param array $data Dữ liệu thanh toán.
49
     * @param int|string $gatewayId Id của cổng thanh toán.
50
     * @param null|int|string $clientId Id client của cổng thanh toán dùng đề tạo lệnh.
51
     * Nếu không thiết lập thì [[getDefaultClient()]] sẽ được gọi trong cổng thanh toán.
52
     * @return \vxm\gatewayclients\ResponseData|DataInterface
53
     * @see [[BasePaymentGateway::purchase()]]
54
     * @throws \yii\base\InvalidConfigException
55
     */
56 6
    public function queryDR(array $data, $gatewayId, $clientId = null): DataInterface
57
    {
58 6
        return $this->request(BasePaymentGateway::RC_QUERY_DR, $data, $gatewayId, $clientId);
59
    }
60
61
    /**
62
     * Đây là phương thức ánh xạ của [[request()]]. Dùng để tạo lệnh yêu cầu hoàn tiền.
63
     *
64
     * @param array $data dữ liệu yêu cầu hoàn tiền.
65
     * @param int|string $gatewayId Id của cổng thanh toán.
66
     * @param null|int|string $clientId Id client của cổng thanh toán dùng đề tạo lệnh.
67
     * Nếu không thiết lập thì [[getDefaultClient()]] sẽ được gọi trong cổng thanh toán.
68
     * @return \vxm\gatewayclients\ResponseData|DataInterface
69
     * @see [[BasePaymentGateway::purchase()]]
70
     * @throws \yii\base\InvalidConfigException
71
     * @since 1.0.3
72
     */
73 1
    public function refund(array $data, $gatewayId, $clientId = null): DataInterface
74
    {
75 1
        return $this->request(BasePaymentGateway::RC_REFUND, $data, $gatewayId, $clientId);
76
    }
77
78
    /**
79
     * Đây là phương thức ánh xạ của [[request()]]. Dùng để tạo lệnh truy vấn trạng thái hoàn tiền.
80
     *
81
     * @param array $data dữ liệu truy vấn.
82
     * @param int|string $gatewayId Id của cổng thanh toán.
83
     * @param null|int|string $clientId Id client của cổng thanh toán dùng đề tạo lệnh.
84
     * Nếu không thiết lập thì [[getDefaultClient()]] sẽ được gọi trong cổng thanh toán.
85
     * @return \vxm\gatewayclients\ResponseData|DataInterface
86
     * @see [[BasePaymentGateway::purchase()]]
87
     * @throws \yii\base\InvalidConfigException
88
     * @since 1.0.3
89
     */
90
    public function queryRefund(array $data, $gatewayId, $clientId = null): DataInterface
91
    {
92
        return $this->request(BasePaymentGateway::RC_QUERY_REFUND, $data, $gatewayId, $clientId);
93
    }
94
95
    /**
96
     * Đây là phương thức ánh xạ của [[verifyRequest()]]. Dùng để xác minh tính hợp lệ của dữ liệu khi khách hoàn tất thanh toán.
97
     *
98
     * @param int|string $gatewayId Id cổng thanh toán dùng để chỉ định xác minh.
99
     * @param \yii\web\Request|null $request Đối tượng `request` chứa dữ liệu cần được xác minh.
100
     * @param null|int|string $clientId Id client của cổng thanh toán dùng đề tạo lệnh.
101
     * Nếu không thiết lập thì [[getDefaultClient()]] sẽ được gọi trong cổng thanh toán.
102
     * @return bool|VerifiedData|DataInterface Trả về dữ liệu đã được xác minh hoặc là FALSE nếu dữ liệu không hợp lệ.
103
     * @see [[BasePaymentGateway::verifyRequestPurchaseSuccess()]].
104
     * @throws \yii\base\InvalidConfigException|\ReflectionException
105
     */
106 4
    public function verifyRequestPurchaseSuccess($gatewayId, \yii\web\Request $request = null, $clientId = null)
107
    {
108 4
        return $this->verifyRequest(BasePaymentGateway::VRC_PURCHASE_SUCCESS, $gatewayId, $request, $clientId);
109
    }
110
111
    /**
112
     * Đây là phương thức ánh xạ của [[verifyRequest()]]. Dùng để xác minh tính hợp lệ của dữ liệu khi cổng thanh toán gửi dữ liệu sang,
113
     * khi khách hoàn tất giao dịch.
114
     *
115
     * @param int|string $gatewayId Id cổng thanh toán dùng để chỉ định xác minh.
116
     * @param \yii\web\Request|null $request Đối tượng `request` chứa dữ liệu cần được xác minh.
117
     * @param null|int|string $clientId Id client của cổng thanh toán dùng đề tạo lệnh.
118
     * Nếu không thiết lập thì [[getDefaultClient()]] sẽ được gọi trong cổng thanh toán.
119
     * @return bool|VerifiedData|DataInterface Trả về dữ liệu đã được xác minh hoặc là FALSE nếu dữ liệu không hợp lệ.
120
     * @see [[BasePaymentGateway::verifyRequestIPN()]].
121
     * @throws \yii\base\InvalidConfigException|\ReflectionException
122
     */
123 3
    public function verifyRequestIPN($gatewayId, \yii\web\Request $request = null, $clientId = null)
124
    {
125 3
        return $this->verifyRequest(BasePaymentGateway::VRC_IPN, $gatewayId, $request, $clientId);
126
    }
127
128
    /**
129
     * Phương thức xác minh tính hợp lệ của request mà cổng thanh toán gửi về, đây là phương thức ánh xạ của
130
     * [[BasePaymentGateway::verifyRequest()]].
131
     *
132
     * @param int|string $command Lệnh yêu cầu xác minh.
133
     * @param \yii\web\Request $request Đối tượng `request` chứa dữ liệu cần xác minh.
134
     * @param int|string $gatewayId Id của cổng thanh toán dùng để tạo lệnh.
135
     * @param null|int|string $clientId Id client của cổng thanh toán dùng đề tạo lệnh.
136
     * Nếu không thiết lập thì [[BasePaymentGateway::getDefaultClient()]] sẽ được gọi trong cổng thanh toán.
137
     * @return bool|VerifiedData|DataInterface
138
     * @see [[BasePaymentGateway::verifyRequest()]]
139
     * @throws \yii\base\InvalidConfigException|\ReflectionException
140
     */
141 7
    public function verifyRequest($command, $gatewayId, \yii\web\Request $request = null, $clientId = null)
142
    {
143 7
        return $this->getGateway($gatewayId)->verifyRequest($command, $request, $clientId);
144
    }
145
}
146