QueryTransactionRequest::getVnpTransactionNo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @link https://github.com/phpviet/omnipay-vnpay
4
 *
5
 * @copyright (c) PHP Viet
6
 * @license [MIT](https://opensource.org/licenses/MIT)
7
 */
8
9
namespace Omnipay\VNPay\Message;
10
11
/**
12
 * @author Vuong Minh <[email protected]>
13
 * @since 1.0.0
14
 */
15
class QueryTransactionRequest extends AbstractSignatureRequest
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $productionEndpoint = 'https://merchant.vnpay.vn/merchant_webapi/merchant.html';
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected $testEndpoint = 'https://sandbox.vnpayment.vn/merchant_webapi/merchant.html';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function initialize(array $parameters = [])
31
    {
32
        parent::initialize($parameters);
33
34
        $this->setParameter('vnp_Command', 'querydr');
35
36
        return $this;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     * @throws \Omnipay\Common\Exception\InvalidResponseException
42
     */
43
    public function sendData($data): SignatureResponse
44
    {
45
        $query = http_build_query($data, null, '&', PHP_QUERY_RFC3986);
46
        $requestUrl = $this->getEndpoint().'?'.$query;
47
        $response = $this->httpClient->request('GET', $requestUrl);
48
        $responseRawData = $response->getBody()->getContents();
49
        parse_str($responseRawData, $responseData);
50
51
        return $this->response = new SignatureResponse($this, $responseData);
52
    }
53
54
    /**
55
     * Trả về mã giao dịch của VNPay.
56
     * Đây là phương thức ánh xạ của [[getTransactionReference()]].
57
     *
58
     * @return null|string
59
     * @see getTransactionReference
60
     */
61
    public function getVnpTransactionNo(): ?string
62
    {
63
        return $this->getParameter('vnp_TransactionNo');
64
    }
65
66
    /**
67
     * Thiết lập mã giao dịch của VNPay.
68
     * Đây là phương thức ánh xạ của [[setTransactionReference()]].
69
     *
70
     * @param  null|string  $no
71
     * @return $this
72
     * @see setTransactionReference
73
     */
74
    public function setVnpTransactionNo(?string $no)
75
    {
76
        return $this->setParameter('vnp_TransactionNo', $no);
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function getTransactionReference(): ?string
83
    {
84
        return $this->getParameter('vnp_TransactionNo');
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function setTransactionReference($value)
91
    {
92
        return $this->setParameter('vnp_TransactionNo', $value);
93
    }
94
95
    /**
96
     * Trả về thời gian phát sinh giao dịch tại VNPay.
97
     *
98
     * @return null|string
99
     */
100
    public function getVnpTransDate(): ?string
101
    {
102
        return $this->getParameter('vnp_TransDate');
103
    }
104
105
    /**
106
     * Thiết lập thời gian phát sinh giao dịch tại VNPay.
107
     *
108
     * @param  null|string  $date
109
     * @return $this
110
     */
111
    public function setVnpTransDate(?string $date)
112
    {
113
        return $this->setParameter('vnp_TransDate', $date);
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119
    protected function getSignatureParameters(): array
120
    {
121
        $parameters = [
122
            'vnp_Version', 'vnp_Command', 'vnp_TmnCode', 'vnp_TxnRef', 'vnp_OrderInfo', 'vnp_TransDate',
123
            'vnp_CreateDate', 'vnp_IpAddr',
124
        ];
125
126
        if ($this->getVnpTransactionNo()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getVnpTransactionNo() of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
127
            $parameters[] = 'vnp_TransactionNo';
128
        }
129
130
        return $parameters;
131
    }
132
}
133