Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 44fbf9a

Browse files
WIP
1 parent 904b1af commit 44fbf9a

17 files changed

+746
-5
lines changed

‎src/AbstractGateway.php‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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;
10+
11+
use Omnipay\Common\AbstractGateway as BaseAbstractGateway;
12+
13+
/**
14+
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
* @since 1.0.0
16+
*/
17+
abstract class AbstractGateway extends BaseAbstractGateway
18+
{
19+
use Concerns\Parameters;
20+
use Concerns\ParametersNormalization;
21+
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
public function initialize(array $parameters = [])
26+
{
27+
parent::initialize(
28+
$this->normalizeParameters($parameters)
29+
);
30+
31+
return $this;
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function getDefaultParameters(): array
38+
{
39+
return [
40+
'vpc_Currency' => 'VND',
41+
'vpc_Version' => 2,
42+
'vpc_Locale' => 'vn',
43+
];
44+
}
45+
}

‎src/Concerns/Parameters.php‎

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
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\Concerns;
10+
11+
/**
12+
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
* @since 1.0.0
14+
*/
15+
trait Parameters
16+
{
17+
/**
18+
* Trả về giá trị merchant id do OnePay cấp.
19+
*
20+
* @return null|string
21+
*/
22+
public function getVpcMerchant(): ?string
23+
{
24+
$this->getParameter('vpc_Merchant');
25+
}
26+
27+
/**
28+
* Thiết lập giá trị merchant id.
29+
*
30+
* @param string $merchant
31+
* @return $this
32+
*/
33+
public function setVpcMerchant(string $merchant)
34+
{
35+
return $this->setParameter('vpc_Merchant', $merchant);
36+
}
37+
38+
/**
39+
* Trả về giá trị access code do OnePay cấp.
40+
*
41+
* @return null|string
42+
*/
43+
public function getVpcAccessCode(): ?string
44+
{
45+
return $this->getParameter('vpc_AccessCode');
46+
}
47+
48+
/**
49+
* Thiết lập giá trị access code.
50+
*
51+
* @param string $code
52+
* @return $this
53+
*/
54+
public function setVpcAccessCode(string $code)
55+
{
56+
return $this->setParameter('vpc_AccessCode', $code);
57+
}
58+
59+
/**
60+
* Trả về giá trị hash key do OnePay cấp.
61+
*
62+
* @return null|string
63+
*/
64+
public function getVpcHashKey(): ?string
65+
{
66+
return $this->getParameter('vpc_HashKey');
67+
}
68+
69+
/**
70+
* Thiết lập giá trị hash key dùng để tạo chữ ký dữ liệu (secure hash).
71+
*
72+
* @param string $key
73+
* @return $this
74+
*/
75+
public function setVpcHashKey(string $key)
76+
{
77+
return $this->setParameter('vpc_HashKey', $key);
78+
}
79+
80+
/**
81+
* Trả về giá trị user do OnePay cấp.
82+
*
83+
* @return null|string
84+
*/
85+
public function getVpcUser(): ?string
86+
{
87+
return $this->getParameter('vpc_User');
88+
}
89+
90+
/**
91+
* Thiết lập giá trị user.
92+
*
93+
* @param string $user
94+
* @return $this
95+
*/
96+
public function setVpcUser(string $user)
97+
{
98+
return $this->setParameter('vpc_User', $user);
99+
}
100+
101+
/**
102+
* Trả về giá trị password do OnePay cấp.
103+
*
104+
* @return null|string
105+
*/
106+
public function getVpcPassword(): ?string
107+
{
108+
return $this->getParameter('vpc_Password');
109+
}
110+
111+
/**
112+
* Thiết lập giá trị password.
113+
*
114+
* @param string $password
115+
* @return $this
116+
*/
117+
public function setVpcPassword(string $password)
118+
{
119+
return $this->setParameter('vpc_Password', $password);
120+
}
121+
122+
/**
123+
* Trả về giá trị version hiện tại.
124+
*
125+
* @return null|string
126+
*/
127+
public function getVpcVersion(): ?string
128+
{
129+
return $this->getParameter('vpc_Version');
130+
}
131+
132+
/**
133+
* Thiết lập giá trị version muốn sử dụng.
134+
*
135+
* @param string $version
136+
* @return $this
137+
*/
138+
public function setVpcVersion(string $version)
139+
{
140+
return $this->setParameter('vpc_Version', $version);
141+
}
142+
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+
164+
/**
165+
* Trả giao diện ngôn ngữ khách dùng để thanh toán.
166+
*
167+
* @return null|string
168+
*/
169+
public function getVpcLocale(): ?string
170+
{
171+
return $this->getParameter('vpc_Locale');
172+
}
173+
174+
/**
175+
* Thiết lập giao diện ngôn ngữ khách dùng để thanh toán.
176+
*
177+
* @param string $locale
178+
* @return $this
179+
*/
180+
public function setVpcLocale(string $locale)
181+
{
182+
return $this->setParameter('vpc_Locale', $locale);
183+
}
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+
}
200+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Concerns;
10+
11+
/**
12+
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
* @since 1.0.0
14+
*/
15+
trait ParametersNormalization
16+
{
17+
/**
18+
* Phương thức hổ trợ xóa bỏ các ký tự `_` khi thiết lập các parameters.
19+
*
20+
* @param array $parameters
21+
* @return array
22+
*/
23+
protected function normalizeParameters(array $parameters): array
24+
{
25+
$normalizedParameters = [];
26+
27+
foreach ($parameters as $parameter => $value) {
28+
$parameter = str_replace('_', '', $parameter);
29+
$normalizedParameters[$parameter] = $value;
30+
}
31+
32+
return $normalizedParameters;
33+
}
34+
}

‎src/DomesticGateway.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/laravel-onepay
4+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
namespace Omnipay\OnePay;
10+
11+
/**
12+
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
* @since 1.0.0
14+
*/
15+
class DomesticGateway extends AbstractGateway
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function getName(): string
21+
{
22+
return 'OnePay Domestic';
23+
}
24+
}

‎src/InternationalGateway.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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;
10+
11+
/**
12+
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
* @since 1.0.0
14+
*/
15+
class InternationalGateway extends AbstractGateway
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function getName(): string
21+
{
22+
return 'OnePay International';
23+
}
24+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-onepay
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](http://www.opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace Omnipay\OnePay\Message;
9+
10+
/**
11+
* @author Vuong Minh <vuongxuongminh@gmail.com>
12+
* @since 1.0.0
13+
*/
14+
abstract class AbstractIncomingRequest extends AbstractRequest
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function getData(): array
20+
{
21+
call_user_func_array(
22+
[$this, 'validate'],
23+
array_keys($parameters = $this->getIncomingParameters())
24+
);
25+
26+
return $parameters;
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public function initialize(array $parameters = [])
33+
{
34+
parent::initialize($parameters);
35+
36+
$incomingParameters = $this->normalizeParameters(
37+
$this->getIncomingParameters()
38+
);
39+
40+
foreach ($incomingParameters as $parameter => $value) {
41+
$this->setParameter($parameter, $value);
42+
}
43+
44+
return $this;
45+
}
46+
47+
/**
48+
* Trả về danh sách parameters từ MoMo gửi sang.
49+
*
50+
* @return array
51+
*/
52+
abstract protected function getIncomingParameters(): array;
53+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /