Skip to content

Commit a9688e3

Browse files
WIP
1 parent e75090c commit a9688e3

14 files changed

+216
-108
lines changed

src/AbstractGateway.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public function initialize(array $parameters = [])
3535
public function getDefaultParameters(): array
3636
{
3737
return [
38-
'vpc_Currency' => 'VND',
3938
'vpc_Version' => 2,
4039
'vpc_Locale' => 'vn',
4140
];

src/Concerns/Parameters.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -140,27 +140,6 @@ public function setVpcVersion(string $version)
140140
return $this->setParameter('vpc_Version', $version);
141141
}
142142

143-
/**
144-
* Trả về đơn vị tiền tệ sử dụng thanh toán của khách.
145-
*
146-
* @return null|string
147-
*/
148-
public function getVpcCurrency(): ?string
149-
{
150-
return $this->getCurrency();
151-
}
152-
153-
/**
154-
* Thiết lập đơn vị tiền tệ sử dụng thanh toán của khách.
155-
*
156-
* @param string $currency
157-
* @return $this
158-
*/
159-
public function setVpcCurrency(string $currency)
160-
{
161-
return $this->setCurrency($currency);
162-
}
163-
164143
/**
165144
* Trả giao diện ngôn ngữ khách dùng để thanh toán.
166145
*
@@ -181,20 +160,4 @@ public function setVpcLocale(string $locale)
181160
{
182161
return $this->setParameter('vpc_Locale', $locale);
183162
}
184-
185-
/**
186-
* {@inheritdoc}
187-
*/
188-
public function getCurrency(): ?string
189-
{
190-
return ($currency = $this->getParameter('vpc_Currency')) ? strtoupper($currency) : null;
191-
}
192-
193-
/**
194-
* {@inheritdoc}
195-
*/
196-
public function setCurrency($value)
197-
{
198-
return $this->setParameter('vpc_Currency', $value);
199-
}
200163
}

src/Message/AbstractNotificationRequest.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/Message/AbstractPurchaseRequest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function initialize(array $parameters = [])
2121
{
2222
parent::initialize($parameters);
2323

24+
$this->setParameter('vpc_Command', 'pay');
2425
$this->setAgainLink(
2526
$this->getAgainLink() ?? $this->httpRequest->getUri()
2627
);
@@ -30,6 +31,9 @@ public function initialize(array $parameters = [])
3031
$this->setTitle(
3132
$this->getTitle() ?? ''
3233
);
34+
$this->setCurrency(
35+
$this->getCurrency() ?? 'VND'
36+
);
3337

3438
return $this;
3539
}
@@ -50,7 +54,7 @@ public function getData(): array
5054
/**
5155
* {@inheritdoc}
5256
*/
53-
public function sendData($data)
57+
public function sendData($data): PurchaseResponse
5458
{
5559
return $this->response = new PurchaseResponse($this, $data);
5660
}
@@ -228,6 +232,43 @@ public function setVpcMerchTxnRef(string $ref)
228232
return $this->setParameter('vpc_MerchTxnRef', $ref);
229233
}
230234

235+
/**
236+
* Trả về đơn vị tiền tệ sử dụng thanh toán của khách.
237+
*
238+
* @return null|string
239+
*/
240+
public function getVpcCurrency(): ?string
241+
{
242+
return $this->getCurrency();
243+
}
244+
245+
/**
246+
* Thiết lập đơn vị tiền tệ sử dụng thanh toán của khách.
247+
*
248+
* @param string $currency
249+
* @return $this
250+
*/
251+
public function setVpcCurrency(string $currency)
252+
{
253+
return $this->setCurrency($currency);
254+
}
255+
256+
/**
257+
* {@inheritdoc}
258+
*/
259+
public function getCurrency(): ?string
260+
{
261+
return ($currency = $this->getParameter('vpc_Currency')) ? strtoupper($currency) : null;
262+
}
263+
264+
/**
265+
* {@inheritdoc}
266+
*/
267+
public function setCurrency($value)
268+
{
269+
return $this->setParameter('vpc_Currency', $value);
270+
}
271+
231272
/**
232273
* {@inheritdoc}
233274
*/
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-onepay
4+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
namespace Omnipay\OnePay\Message;
10+
11+
/**
12+
* @author Vuong Minh <[email protected]>
13+
* @since 1.0.0
14+
*/
15+
class AbstractQueryTransactionRequest extends AbstractSignatureRequest
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function initialize(array $parameters = [])
21+
{
22+
parent::initialize($parameters);
23+
$this->setParameter('vpc_Command', 'queryDR');
24+
25+
return $this;
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function sendData($data): QueryTransactionResponse
32+
{
33+
$url = $this->getEndpoint().'?'.http_build_query($data);
34+
$response = $this->httpClient->request('GET', $url);
35+
$raw = $response->getBody()->getContents();
36+
parse_str($raw, $responseData);
37+
38+
return $this->response = new QueryTransactionResponse($this, $responseData);
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
protected function getSignatureParameters(): array
45+
{
46+
$baseParameters = array_fill_keys([
47+
'vpc_Command', 'vpc_Version', 'vpc_MerchTxnRef', 'vpc_Merchant', 'vpc_AccessCode', 'vpc_User',
48+
'vpc_Password',
49+
], true);
50+
$parameters = array_merge($baseParameters, $this->getParameters());
51+
$parameters = array_filter(array_keys($parameters), function ($parameter) {
52+
return 0 === strpos($parameter, 'vpc_');
53+
});
54+
55+
return $parameters;
56+
}
57+
}

src/Message/CompletePurchaseResponse.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Message/Concerns/ResponseProperties.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ trait ResponseProperties
2121
*/
2222
public function __get($name)
2323
{
24-
if (isset($this->data[$name])) {
25-
return $this->data[$name];
24+
$property = $this->propertyNormalize($name);
25+
26+
if (isset($this->data[$property])) {
27+
return $this->data[$property];
2628
} else {
2729
trigger_error(sprintf('Undefined property: %s::%s', __CLASS__, '$'.$name), E_USER_NOTICE);
2830

@@ -39,10 +41,27 @@ public function __get($name)
3941
*/
4042
public function __set($name, $value)
4143
{
42-
if (isset($this->data[$name])) {
44+
$property = $this->propertyNormalize($name);
45+
46+
if (isset($this->data[$property])) {
4347
trigger_error(sprintf('Undefined property: %s::%s', __CLASS__, '$'.$name), E_USER_NOTICE);
4448
} else {
4549
$this->$name = $value;
4650
}
4751
}
52+
53+
/**
54+
* Phương thức hổ trợ chuyển đổi property `vpcAbc` thành `vpc_Abc`.
55+
*
56+
* @param string $property
57+
* @return null|string
58+
*/
59+
private function propertyNormalize(string $property): ?string
60+
{
61+
if (0 === strpos($property, 'vpc') && false === strpos($property, '_')) {
62+
return 'vpc_'.substr($property, 3);
63+
}
64+
65+
return null;
66+
}
4867
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-onepay
4+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
namespace Omnipay\OnePay\Message\Domestic;
10+
11+
use Omnipay\OnePay\Message\AbstractQueryTransactionRequest;
12+
13+
/**
14+
* @author Vuong Minh <[email protected]>
15+
* @since 1.0.0
16+
*/
17+
class QueryTransactionRequest extends AbstractQueryTransactionRequest
18+
{
19+
protected $testEndpoint = 'https://mtf.onepay.vn/onecomm-pay/Vpcdps.op';
20+
21+
protected $productionEndpoint = 'https://onepay.vn/onecomm-pay/Vpcdps.op';
22+
}

src/Message/AbstractIncomingRequest.php renamed to src/Message/IncomingRequest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @author Vuong Minh <[email protected]>
1212
* @since 1.0.0
1313
*/
14-
abstract class AbstractIncomingRequest extends AbstractRequest
14+
class IncomingRequest extends AbstractRequest
1515
{
1616
/**
1717
* {@inheritdoc}
@@ -26,18 +26,23 @@ public function getData(): array
2626
return $parameters;
2727
}
2828

29+
/**
30+
* {@inheritdoc}
31+
* @throws \Omnipay\Common\Exception\InvalidResponseException
32+
*/
33+
public function sendData($data): IncomingResponse
34+
{
35+
return $this->response = new IncomingResponse($this, $data);
36+
}
37+
2938
/**
3039
* {@inheritdoc}
3140
*/
3241
public function initialize(array $parameters = [])
3342
{
3443
parent::initialize($parameters);
3544

36-
$incomingParameters = $this->normalizeParameters(
37-
$this->getIncomingParameters()
38-
);
39-
40-
foreach ($incomingParameters as $parameter => $value) {
45+
foreach ($this->getIncomingParameters() as $parameter => $value) {
4146
$this->setParameter($parameter, $value);
4247
}
4348

@@ -49,5 +54,10 @@ public function initialize(array $parameters = [])
4954
*
5055
* @return array
5156
*/
52-
abstract protected function getIncomingParameters(): array;
57+
protected function getIncomingParameters(): array
58+
{
59+
return $this->normalizeParameters(
60+
$this->httpRequest->query->all()
61+
);
62+
}
5363
}

src/Message/AbstractSignatureResponse.php renamed to src/Message/IncomingResponse.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/omnipay-onepay
4+
*
45
* @copyright (c) PHP Viet
5-
* @license [MIT](http://www.opensource.org/licenses/MIT)
6+
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
78

89
namespace Omnipay\OnePay\Message;
@@ -13,7 +14,7 @@
1314
* @author Vuong Minh <[email protected]>
1415
* @since 1.0.0
1516
*/
16-
abstract class AbstractSignatureResponse extends AbstractResponse
17+
class IncomingResponse extends Response
1718
{
1819
use Concerns\ResponseSignatureValidation;
1920

0 commit comments

Comments
 (0)