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\AppInApp; |
9
|
|
|
|
10
|
|
|
use Omnipay\MoMo\Message\AbstractHashRequest; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Vuong Minh <[email protected]> |
14
|
|
|
* @since 1.0.0 |
15
|
|
|
*/ |
16
|
|
|
class PurchaseRequest extends AbstractHashRequest |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
|
public function initialize(array $parameters = []) |
22
|
|
|
{ |
23
|
|
|
parent::initialize($parameters); |
24
|
|
|
$this->setParameter('payType', 3); |
25
|
|
|
$this->setParameter('version', 2); |
26
|
|
|
|
27
|
|
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function getData(): array |
34
|
|
|
{ |
35
|
|
|
$this->validate('appData', 'customerNumber'); |
36
|
|
|
|
37
|
|
|
return parent::getData(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function sendData($data) |
44
|
|
|
{ |
45
|
|
|
$response = $this->httpClient->request('POST', $this->getEndpoint().'/pay/app', [ |
46
|
|
|
'Content-Type' => 'application/json; charset=utf-8', |
47
|
|
|
], json_encode($data)); |
48
|
|
|
$responseData = $response->getBody()->getContents(); |
49
|
|
|
|
50
|
|
|
return $this->response = new PurchaseResponse($this, json_decode($responseData, true) ?? []); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Trả về app data token nhận từ MoMo. |
55
|
|
|
* |
56
|
|
|
* @return null|string |
57
|
|
|
*/ |
58
|
|
|
public function getAppData(): ?string |
59
|
|
|
{ |
60
|
|
|
return $this->getParameter('appData'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Thiết app token từ app MoMo gửi sang. |
65
|
|
|
* |
66
|
|
|
* @param string $appData |
67
|
|
|
* @return $this |
68
|
|
|
*/ |
69
|
|
|
public function setAppData(string $appData) |
70
|
|
|
{ |
71
|
|
|
return $this->setParameter('appData', $appData); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Trả về tên cửa hàng. |
76
|
|
|
* |
77
|
|
|
* @return null|string |
78
|
|
|
*/ |
79
|
|
|
public function getStoreId(): ?string |
80
|
|
|
{ |
81
|
|
|
return $this->getParameter('storeId'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Thiết lập mã cửa hàng. |
86
|
|
|
* |
87
|
|
|
* @param string $id |
88
|
|
|
* @return $this |
89
|
|
|
*/ |
90
|
|
|
public function setStoreId(string $id) |
91
|
|
|
{ |
92
|
|
|
return $this->setParameter('storeId', $id); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Trả về store name. |
97
|
|
|
* |
98
|
|
|
* @return null|string |
99
|
|
|
*/ |
100
|
|
|
public function getStoreName(): ?string |
101
|
|
|
{ |
102
|
|
|
return $this->getParameter('storeName'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Thiết lập tên cửa hàng. |
107
|
|
|
* |
108
|
|
|
* @param string $name |
109
|
|
|
* @return $this |
110
|
|
|
*/ |
111
|
|
|
public function setStoreName(string $name) |
112
|
|
|
{ |
113
|
|
|
return $this->setParameter('storeName', $name); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Trả về mã đơn hàng. |
118
|
|
|
* |
119
|
|
|
* @return null|string |
120
|
|
|
*/ |
121
|
|
|
public function getPartnerRefId(): ?string |
122
|
|
|
{ |
123
|
|
|
return $this->getParameter('partnerRefId'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Thiết lập mã đơn hàng. |
128
|
|
|
* |
129
|
|
|
* @param string $id |
130
|
|
|
* @return $this |
131
|
|
|
*/ |
132
|
|
|
public function setPartnerRefId(string $id) |
133
|
|
|
{ |
134
|
|
|
return $this->setParameter('partnerRefId', $id); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Trả về mã đơn hàng bổ sung. |
139
|
|
|
* |
140
|
|
|
* @return null|string |
141
|
|
|
*/ |
142
|
|
|
public function getPartnerTransId(): ?string |
143
|
|
|
{ |
144
|
|
|
return $this->getParameter('partnerTransId'); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Thiết lập mã đơn hàng bổ sung. |
149
|
|
|
* |
150
|
|
|
* @param string $id |
151
|
|
|
* @return $this |
152
|
|
|
*/ |
153
|
|
|
public function setPartnerTransId(string $id) |
154
|
|
|
{ |
155
|
|
|
return $this->setParameter('partnerTransId', $id); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Trả về tên công ty, đơn vị của bạn. |
160
|
|
|
* |
161
|
|
|
* @return null|string |
162
|
|
|
*/ |
163
|
|
|
public function getPartnerName(): ?string |
164
|
|
|
{ |
165
|
|
|
return $this->getParameter('partnerName'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Thiết lập tên công ty, tổ chức của bạn. |
170
|
|
|
* |
171
|
|
|
* @param string $name |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
|
|
public function setPartnerName(string $name) |
175
|
|
|
{ |
176
|
|
|
return $this->setParameter('partnerName', $name); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Trả về số điện thoại khách hàng. |
181
|
|
|
* |
182
|
|
|
* @return null|string |
183
|
|
|
*/ |
184
|
|
|
public function getCustomerNumber(): ?string |
185
|
|
|
{ |
186
|
|
|
return $this->getParameter('customerNumber'); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Thiết lập số điện thoại khách hàng. |
191
|
|
|
* |
192
|
|
|
* @param string $number |
193
|
|
|
* @return $this |
194
|
|
|
*/ |
195
|
|
|
public function setCustomerNumber(string $number) |
196
|
|
|
{ |
197
|
|
|
return $this->setParameter('customerNumber', $number); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* {@inheritdoc} |
202
|
|
|
*/ |
203
|
|
|
protected function getHashParameters(): array |
204
|
|
|
{ |
205
|
|
|
$parameters = [ |
206
|
|
|
'partnerCode', 'partnerRefId', 'amount', |
207
|
|
|
]; |
208
|
|
|
|
209
|
|
|
if ($this->getParameter('partnerName')) { |
210
|
|
|
$parameters[] = 'partnerName'; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
if ($this->getParameter('partnerTransId')) { |
214
|
|
|
$parameters[] = 'partnerTransId'; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
if ($this->getParameter('storeId')) { |
218
|
|
|
$parameters[] = 'storeId'; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
if ($this->getParameter('storeName')) { |
222
|
|
|
$parameters[] = 'storeName'; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
return $parameters; |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|