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 RefundRequest 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', 'refund'); |
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ề số tiền cần hoàn trả. |
56
|
|
|
* Đây là phương thức ánh xạ của [[getAmount()]]. |
57
|
|
|
* |
58
|
|
|
* @return null|string |
59
|
|
|
* @see getAmount |
60
|
|
|
*/ |
61
|
|
|
public function getVnpAmount(): ?string |
62
|
|
|
{ |
63
|
|
|
return $this->getAmount(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Thiết lập số tiền hoàn trả. |
68
|
|
|
* Đây là phương thức ánh xạ của [[setAmount()]]. |
69
|
|
|
* |
70
|
|
|
* @param null|string $number |
71
|
|
|
* @return $this |
72
|
|
|
* @see setAmount |
73
|
|
|
*/ |
74
|
|
|
public function setVnpAmount(?string $number) |
75
|
|
|
{ |
76
|
|
|
return $this->setAmount($number); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Trả về hình thức hoàn tiền. |
81
|
|
|
* |
82
|
|
|
* @return null|string |
83
|
|
|
*/ |
84
|
|
|
public function getVnpTransactionType(): ?string |
85
|
|
|
{ |
86
|
|
|
return $this->getParameter('vnp_TransactionType'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Thiết lập hình thức hoàn tiền. |
91
|
|
|
* |
92
|
|
|
* @param null|string $type |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function setVnpTransactionType(?string $type) |
96
|
|
|
{ |
97
|
|
|
return $this->setParameter('vnp_TransactionType', $type); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function getAmount(): ?string |
104
|
|
|
{ |
105
|
|
|
return $this->getParameter('vnp_Amount'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
|
|
public function setAmount($value) |
112
|
|
|
{ |
113
|
|
|
return $this->setParameter('vnp_Amount', $value); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Trả về thời gian phát sinh giao dịch tại VNPay. |
118
|
|
|
* |
119
|
|
|
* @return null|string |
120
|
|
|
*/ |
121
|
|
|
public function getVnpTransDate(): ?string |
122
|
|
|
{ |
123
|
|
|
return $this->getParameter('vnp_TransDate'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Thiết lập thời gian phát sinh giao dịch tại VNPay. |
128
|
|
|
* |
129
|
|
|
* @param null|string $date |
130
|
|
|
* @return $this |
131
|
|
|
*/ |
132
|
|
|
public function setVnpTransDate(?string $date) |
133
|
|
|
{ |
134
|
|
|
return $this->setParameter('vnp_TransDate', $date); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* {@inheritdoc} |
139
|
|
|
*/ |
140
|
|
|
protected function getSignatureParameters(): array |
141
|
|
|
{ |
142
|
|
|
return [ |
143
|
|
|
'vnp_Version', 'vnp_Command', 'vnp_TmnCode', 'vnp_TxnRef', 'vnp_OrderInfo', 'vnp_Amount', |
144
|
|
|
'vnp_TransDate', 'vnp_TransactionType', |
145
|
|
|
]; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|