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\AllInOne; |
9
|
|
|
|
10
|
|
|
use Omnipay\MoMo\Message\AbstractSignatureRequest as BaseAbstractSignatureRequest; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Vuong Minh <[email protected]> |
14
|
|
|
* @since 1.0.0 |
15
|
|
|
*/ |
16
|
|
|
abstract class AbstractSignatureRequest extends BaseAbstractSignatureRequest |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Trả về lớp đối tượng phản hồi tương ứng của Request. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $responseClass; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Trả về id đơn hàng. |
27
|
|
|
* |
28
|
|
|
* @return null|string |
29
|
|
|
*/ |
30
|
|
|
public function getOrderId(): ?string |
31
|
|
|
{ |
32
|
|
|
return $this->getParameter('orderId'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Thiết lập id đơn hàng. |
37
|
|
|
* |
38
|
|
|
* @param null|string $id |
39
|
|
|
* @return $this |
40
|
|
|
*/ |
41
|
|
|
public function setOrderId(?string $id) |
42
|
|
|
{ |
43
|
|
|
return $this->setParameter('orderId', $id); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Trả về request id. |
48
|
|
|
* |
49
|
|
|
* @return null|string |
50
|
|
|
*/ |
51
|
|
|
public function getRequestId(): ?string |
52
|
|
|
{ |
53
|
|
|
return $this->getParameter('requestId'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Thiết lập request id của đơn hàng. |
58
|
|
|
* |
59
|
|
|
* @param null|string $id |
60
|
|
|
* @return $this |
61
|
|
|
*/ |
62
|
|
|
public function setRequestId(?string $id) |
63
|
|
|
{ |
64
|
|
|
return $this->setParameter('requestId', $id); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
* @throws \Omnipay\Common\Exception\InvalidResponseException |
70
|
|
|
*/ |
71
|
|
|
public function sendData($data) |
72
|
|
|
{ |
73
|
|
|
$response = $this->httpClient->request('POST', $this->getEndpoint().'/gw_payment/transactionProcessor', [ |
74
|
|
|
'Content-Type' => 'application/json; charset=UTF-8', |
75
|
|
|
], json_encode($data)); |
76
|
|
|
$responseClass = $this->responseClass; |
77
|
|
|
$responseData = $response->getBody()->getContents(); |
78
|
|
|
|
79
|
|
|
return $this->response = new $responseClass($this, json_decode($responseData, true) ?? []); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|