ResponseData   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 38
ccs 5
cts 10
cp 0.5
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIsOk() 0 4 2
A getResponseCode() 0 8 2
A getMessage() 0 8 2
1
<?php
2
/**
3
 * @link https://github.com/yii2-vn/payment
4
 * @copyright Copyright (c) 2017 Yii2VN
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace yiiviet\payment\vnpayment;
9
10
use vxm\gatewayclients\ResponseData as BaseResponseData;
11
12
/**
13
 * Lớp ResponseData cung cấp dữ liệu phản hồi từ VnPayment sau khi thực hiện hàm [[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
 * @property bool $isOk trạng thái phản hồi từ VNPayment `TRUE` thành công và ngược lại.
19
 * @property int|null $responseCode mã phản hồi.
20
 * @property string $redirect_url đường dẫn sẽ redirect khách đến trang thanh toán, chỉ tồn tại khi `isOk` là TRUE.
21
 *
22
 * @author Vuong Minh <[email protected]>
23
 * @since 1.0
24
 */
25
class ResponseData extends BaseResponseData
26
{
27
    /**
28
     * @inheritdoc
29
     */
30 3
    public function getIsOk(): bool
31
    {
32 3
        return $this->getCommand() === PaymentGateway::RC_PURCHASE || $this->getResponseCode() === 0;
33
    }
34
35
    /**
36
     * Phương thức hổ trợ lấy response code và ép kiểu về int.
37
     *
38
     * @return int|null Trả về NULL nếu như dữ liệu trả về từ VnPayment không có thuộc tính `vnp_ResponseCode` và ngược lại.
39
     */
40 2
    public function getResponseCode(): ?int
41
    {
42 2
        if (isset($this['vnp_ResponseCode'])) {
43 2
            return (int)$this['vnp_ResponseCode'];
44
        } else {
45
            return null;
46
        }
47
    }
48
49
    /**
50
     * Phương thức hổ trợ lấy câu thông báo từ `vnp_Message` nhận từ VnPayment.
51
     *
52
     * @return null|string Trả về NULL nếu như dữ liệu VnPayment gửi về không tồn tại `vnp_Message` và ngược lại.
53
     */
54
    public function getMessage(): ?string
55
    {
56
        if (isset($this['vnp_Message'])) {
57
            return $this['vnp_Message'];
58
        } else {
59
            return null;
60
        }
61
    }
62
}
63