Completed
Push — master ( 558fc2...aa58a2 )
by Vuong
01:31
created

PayQueryStatusRequest::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @link https://github.com/phpviet/omnipay-momo
4
 * @copyright (c) PHP Viet
5
 * @license [MIT](http://www.opensource.org/licenses/MIT)
6
 */
7
8
namespace Omnipay\MoMo\Message;
9
10
/**
11
 * @author Vuong Minh <[email protected]>
12
 * @since 1.0.0
13
 */
14
class PayQueryStatusRequest extends AbstractHashRequest
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function initialize(array $parameters = [])
20
    {
21
        parent::initialize($parameters);
22
        $this->setParameter('version', 2);
23
24
        return $this;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function sendData($data): PayQueryStatusResponse
31
    {
32
        $response = $this->httpClient->request('POST', $this->getEndpoint().'/pay/query-status', [
33
            'Content-Type' => 'application/json; charset=utf-8',
34
        ], json_encode($data));
35
        $responseData = $response->getBody()->getContents();
36
37
        return $this->response = new PayQueryStatusResponse($this, json_decode($responseData, true) ?? []);
38
    }
39
40
    /**
41
     * Trả về request id.
42
     *
43
     * @return null|string
44
     */
45
    public function getRequestId(): ?string
46
    {
47
        return $this->getParameter('requestId');
48
    }
49
50
    /**
51
     * Thiết lập request id của đơn hàng.
52
     *
53
     * @param  string  $id
54
     * @return $this
55
     */
56
    public function setRequestId(string $id)
57
    {
58
        return $this->setParameter('requestId', $id);
59
    }
60
61
    /**
62
     * Trả về mã đơn hàng.
63
     *
64
     * @return null|string
65
     */
66
    public function getPartnerRefId(): ?string
67
    {
68
        return $this->getParameter('partnerRefId');
69
    }
70
71
    /**
72
     * Thiết lập mã đơn hàng.
73
     *
74
     * @param  string  $id
75
     * @return $this
76
     */
77
    public function setPartnerRefId(string $id)
78
    {
79
        return $this->setParameter('partnerRefId', $id);
80
    }
81
82
    /**
83
     * Trả về mã đơn hàng của MoMo.
84
     *
85
     * @return null|string
86
     */
87
    public function getMomoTransId(): ?string
88
    {
89
        return $this->getParameter('momoTransId');
90
    }
91
92
    /**
93
     * Thiết lập mã giao dịch của MoMo.
94
     *
95
     * @param  string  $id
96
     * @return $this
97
     */
98
    public function setMomoTransId(string $id)
99
    {
100
        return $this->setParameter('momoTransId', $id);
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    protected function getHashParameters(): array
107
    {
108
        $parameters = [
109
            'requestId', 'partnerCode', 'partnerRefId',
110
        ];
111
112
        if ($this->getParameter('momoTransId')) {
113
            $parameters[] = 'momoTransId';
114
        }
115
116
        return $parameters;
117
    }
118
}
119