AbstractQueryTransactionRequest::sendData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @link https://github.com/phpviet/omnipay-onepay
4
 *
5
 * @copyright (c) PHP Viet
6
 * @license [MIT](https://opensource.org/licenses/MIT)
7
 */
8
9
namespace Omnipay\OnePay\Message;
10
11
/**
12
 * @author Vuong Minh <[email protected]>
13
 * @since 1.0.0
14
 */
15
class AbstractQueryTransactionRequest extends AbstractSignatureRequest
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function initialize(array $parameters = [])
21
    {
22
        parent::initialize($parameters);
23
        $this->setParameter('vpc_Command', 'queryDR');
24
25
        return $this;
26
    }
27
28
    /**
29
     * Trả về mã đơn hàng cần truy vấn giao dịch.
30
     *
31
     * @return null|string
32
     */
33
    public function getVpcMerchTxnRef(): ?string
34
    {
35
        return $this->getParameter('vpc_MerchTxnRef');
36
    }
37
38
    /**
39
     * Thiết lập mã đơn hàng cần truy vấn giao dịch tại hệ thống của bạn.
40
     *
41
     * @param  null|string  $ref
42
     * @return $this
43
     */
44
    public function setVpcMerchTxnRef(?string $ref)
45
    {
46
        return $this->setParameter('vpc_MerchTxnRef', $ref);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function sendData($data): QueryTransactionResponse
53
    {
54
        $url = $this->getEndpoint().'?'.http_build_query($data);
55
        $response = $this->httpClient->request('GET', $url);
56
        $raw = $response->getBody()->getContents();
57
        parse_str($raw, $responseData);
58
59
        return $this->response = new QueryTransactionResponse($this, $responseData);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    protected function getSignatureParameters(): array
66
    {
67
        return [
68
            'vpc_Command', 'vpc_Version', 'vpc_MerchTxnRef', 'vpc_Merchant', 'vpc_AccessCode', 'vpc_User',
69
            'vpc_Password',
70
        ];
71
    }
72
}
73