Skip to content

Commit 6203b2e

Browse files
Added pay query and refund messages.
1 parent dc42b14 commit 6203b2e

File tree

7 files changed

+360
-18
lines changed

7 files changed

+360
-18
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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\Concerns;
9+
10+
/**
11+
* @author Vuong Minh <[email protected]>
12+
* @since 1.0.0
13+
*/
14+
trait PayRequestParameters
15+
{
16+
17+
}

src/Message/POS/PurchaseRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function sendData($data): PurchaseResponse
4444
}
4545

4646
/**
47-
* Trả về store id.
47+
* Trả về mã cửa hàng.
4848
*
4949
* @return null|string
5050
*/

src/Message/PayConfirmRequest.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Omnipay\MoMo\Message;
99

10-
use Omnipay\MoMo\Concerns\Parameters;
11-
1210
/**
1311
* @link https://developers.momo.vn/#/docs/pos_payment?id=x%c3%a1c-nh%e1%ba%adn-giao-d%e1%bb%8bch
1412
* @link https://developers.momo.vn/#/docs/qr_payment?id=x%c3%a1c-nh%e1%ba%adn-giao-d%e1%bb%8bch
@@ -19,7 +17,19 @@
1917
*/
2018
class PayConfirmRequest extends AbstractSignatureRequest
2119
{
22-
use Parameters;
20+
/**
21+
* {@inheritdoc}
22+
* @throws \Omnipay\Common\Exception\InvalidResponseException
23+
*/
24+
public function sendData($data): PayConfirmResponse
25+
{
26+
$response = $this->httpClient->request('POST', $this->getEndpoint().'/pay/confirm', [
27+
'Content-Type' => 'application/json; charset=utf-8',
28+
], json_encode($data));
29+
$responseData = $response->getBody()->getContents();
30+
31+
return $this->response = new PayConfirmResponse($this, json_decode($responseData, true) ?? []);
32+
}
2333

2434
/**
2535
* Trả về request id.
@@ -121,20 +131,6 @@ public function setRequestType(string $type): void
121131
$this->setParameter('requestType', $type);
122132
}
123133

124-
/**
125-
* {@inheritdoc}
126-
* @throws \Omnipay\Common\Exception\InvalidResponseException
127-
*/
128-
public function sendData($data): PayConfirmResponse
129-
{
130-
$response = $this->httpClient->request('POST', $this->getEndpoint().'/pay/confirm', [
131-
'Content-Type' => 'application/json; charset=utf-8',
132-
], json_encode($data));
133-
$responseData = $response->getBody()->getContents();
134-
135-
return $this->response = new PayConfirmResponse($this, json_decode($responseData, true) ?? []);
136-
}
137-
138134
/**
139135
* {@inheritdoc}
140136
*/
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
* @throws \Omnipay\Common\Exception\InvalidRequestException
19+
*/
20+
public function getData(): array
21+
{
22+
$this->setParameter('version', 2);
23+
24+
return parent::getData();
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+
*/
55+
public function setRequestId(string $id): void
56+
{
57+
$this->setParameter('requestId', $id);
58+
}
59+
60+
/**
61+
* Trả về mã đơn hàng.
62+
*
63+
* @return null|string
64+
*/
65+
public function getPartnerRefId(): ?string
66+
{
67+
return $this->getParameter('partnerRefId');
68+
}
69+
70+
/**
71+
* Thiết lập mã đơn hàng.
72+
*
73+
* @param string $id
74+
*/
75+
public function setPartnerRefId(string $id): void
76+
{
77+
$this->setParameter('partnerRefId', $id);
78+
}
79+
80+
/**
81+
* Trả về mã đơn hàng của MoMo.
82+
*
83+
* @return null|string
84+
*/
85+
public function getMomoTransId(): ?string
86+
{
87+
return $this->getParameter('momoTransId');
88+
}
89+
90+
/**
91+
* Thiết lập mã giao dịch của MoMo.
92+
*
93+
* @param string $id
94+
*/
95+
public function setMomoTransId(string $id): void
96+
{
97+
$this->setParameter('momoTransId', $id);
98+
}
99+
100+
/**
101+
* {@inheritdoc}
102+
*/
103+
protected function getHashParameters(): array
104+
{
105+
$parameters = ['requestId', 'partnerCode', 'partnerRefId'];
106+
107+
if ($this->getParameter('momoTransId')) {
108+
$parameters[] = 'momoTransId';
109+
}
110+
111+
return $parameters;
112+
}
113+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 PayQueryStatusResponse extends AbstractResponse
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function getCode(): ?string
20+
{
21+
return $this->data['status'] ?? null;
22+
}
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function getTransactionId(): ?string
28+
{
29+
return $this->data['data']['billId'] ?? null;
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function getTransactionReference()
36+
{
37+
return $this->data['data']['transid'] ?? null;
38+
}
39+
}

src/Message/PayRefundRequest.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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 getData(): array
20+
{
21+
$this->setParameter('version', 2);
22+
23+
return parent::getData();
24+
}
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function sendData($data)
30+
{
31+
$response = $this->httpClient->request('POST', $this->getEndpoint().'/pay/refund', [
32+
'Content-Type' => 'application/json; charset=utf-8',
33+
], json_encode($data));
34+
$responseData = $response->getBody()->getContents();
35+
36+
return $this->response = new PayRefundResponse($this, json_decode($responseData, true) ?? []);
37+
}
38+
39+
/**
40+
* Trả về request id.
41+
*
42+
* @return null|string
43+
*/
44+
public function getRequestId(): ?string
45+
{
46+
return $this->getParameter('requestId');
47+
}
48+
49+
/**
50+
* Thiết lập request id của đơn hàng.
51+
*
52+
* @param string $id
53+
*/
54+
public function setRequestId(string $id): void
55+
{
56+
$this->setParameter('requestId', $id);
57+
}
58+
59+
/**
60+
* Trả về mã đơn hàng.
61+
*
62+
* @return null|string
63+
*/
64+
public function getPartnerRefId(): ?string
65+
{
66+
return $this->getParameter('partnerRefId');
67+
}
68+
69+
/**
70+
* Thiết lập mã đơn hàng.
71+
*
72+
* @param string $id
73+
*/
74+
public function setPartnerRefId(string $id): void
75+
{
76+
$this->setParameter('partnerRefId', $id);
77+
}
78+
79+
/**
80+
* Trả về mã đơn hàng của MoMo.
81+
*
82+
* @return null|string
83+
*/
84+
public function getMomoTransId(): ?string
85+
{
86+
return $this->getParameter('momoTransId');
87+
}
88+
89+
/**
90+
* Thiết lập mã giao dịch của MoMo.
91+
*
92+
* @param string $id
93+
*/
94+
public function setMomoTransId(string $id): void
95+
{
96+
$this->setParameter('momoTransId', $id);
97+
}
98+
99+
/**
100+
* Trả về mã cửa hàng.
101+
*
102+
* @return null|string
103+
*/
104+
public function getStoreId(): ?string
105+
{
106+
return $this->getParameter('storeId');
107+
}
108+
109+
/**
110+
* Thiết lập mã cửa hàng.
111+
*
112+
* @param string $id
113+
*/
114+
public function setStoreId(string $id): void
115+
{
116+
$this->setParameter('storeId', $id);
117+
}
118+
119+
/**
120+
* {@inheritdoc}
121+
*/
122+
protected function getHashParameters(): array
123+
{
124+
$parameters = [
125+
'partnerCode', 'partnerRefId', 'momoTransId', 'amount',
126+
];
127+
128+
if ($this->getParameter('storeId')) {
129+
$parameters[] = 'storeId';
130+
}
131+
132+
if ($this->getParameter('description')) {
133+
$parameters[] = 'description';
134+
}
135+
136+
return $parameters;
137+
}
138+
}

0 commit comments

Comments
 (0)