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

PayRefundRequest::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 PayRefundRequest 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)
31
    {
32
        $response = $this->httpClient->request('POST', $this->getEndpoint().'/pay/refund', [
33
            'Content-Type' => 'application/json; charset=utf-8',
34
        ], json_encode($data));
35
        $responseData = $response->getBody()->getContents();
36
37
        return $this->response = new PayRefundResponse($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
     * Trả về mã cửa hàng.
105
     *
106
     * @return null|string
107
     */
108
    public function getStoreId(): ?string
109
    {
110
        return $this->getParameter('storeId');
111
    }
112
113
    /**
114
     * Thiết lập mã cửa hàng.
115
     *
116
     * @param  string  $id
117
     * @return $this
118
     */
119
    public function setStoreId(string $id)
120
    {
121
        return $this->setParameter('storeId', $id);
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127
    protected function getHashParameters(): array
128
    {
129
        $parameters = [
130
            'partnerCode', 'partnerRefId', 'momoTransId', 'amount',
131
        ];
132
133
        if ($this->getParameter('storeId')) {
134
            $parameters[] = 'storeId';
135
        }
136
137
        if ($this->getParameter('description')) {
138
            $parameters[] = 'description';
139
        }
140
141
        return $parameters;
142
    }
143
}
144