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 8191f6a

Browse files
Added message concerns
1 parent 573fa73 commit 8191f6a

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed
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-vtcpay
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](http://www.opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace Omnipay\VTCPay\Message\Concerns;
9+
10+
/**
11+
* @author Vuong Minh <vuongxuongminh@gmail.com>
12+
* @since 1.0.0
13+
*/
14+
trait RequestEndpoint
15+
{
16+
/**
17+
* Đường dẫn kết nối đến VTCPay để test.
18+
*
19+
* @var string
20+
*/
21+
protected $testEndPoint;
22+
23+
/**
24+
* Đường dẫn kết nối đến VTCPay ở môi trường production.
25+
*
26+
* @var string
27+
*/
28+
protected $productionEndpoint;
29+
30+
/**
31+
* Trả về url kết nối MoMo.
32+
*
33+
* @return string
34+
*/
35+
protected function getEndpoint(): string
36+
{
37+
return $this->getTestMode() ? $this->testEndPoint : $this->productionEndpoint;
38+
}
39+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-vtcpay
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](http://www.opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace Omnipay\VTCPay\Message\Concerns;
9+
10+
use Omnipay\VTCPay\Support\Signature;
11+
12+
/**
13+
* @author Vuong Minh <vuongxuongminh@gmail.com>
14+
* @since 1.0.0
15+
*/
16+
trait RequestSignature
17+
{
18+
/**
19+
* Trả về chữ ký điện tử gửi đến OnePay dựa theo [[getSignatureParameters()]].
20+
*
21+
* @return string
22+
*/
23+
protected function generateSignature(): string
24+
{
25+
$signature = new Signature(
26+
$this->getSecurityCode()
27+
);
28+
29+
return $signature->generate(
30+
$this->getParameters()
31+
);
32+
}
33+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-vtcpay
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](http://www.opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace Omnipay\VTCPay\Message\Concerns;
9+
10+
/**
11+
* @author Vuong Minh <vuongxuongminh@gmail.com>
12+
* @since 1.0.0
13+
*/
14+
trait ResponseProperties
15+
{
16+
/**
17+
* Phương thức hổ trợ tạo các thuộc tính của đối tượng từ dữ liệu gửi về từ OnePay.
18+
*
19+
* @param string $name
20+
* @return null|string
21+
*/
22+
public function __get($name)
23+
{
24+
if (isset($this->data[$name])) {
25+
return $this->data[$name];
26+
} else {
27+
trigger_error(sprintf('Undefined property: %s::%s', __CLASS__, '$'.$name), E_USER_NOTICE);
28+
29+
return;
30+
}
31+
}
32+
33+
/**
34+
* Phương thức hổ trợ bảo vệ các thuộc tính của đối tượng từ dữ liệu gửi về từ OnePay.
35+
*
36+
* @param string $name
37+
* @param mixed $value
38+
* @return null|string
39+
*/
40+
public function __set($name, $value)
41+
{
42+
if (isset($this->data[$name])) {
43+
trigger_error(sprintf('Undefined property: %s::%s', __CLASS__, '$'.$name), E_USER_NOTICE);
44+
} else {
45+
$this->$name = $value;
46+
}
47+
}
48+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-vtcpay
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](http://www.opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace Omnipay\VTCPay\Message\Concerns;
9+
10+
use Omnipay\VTCPay\Support\Signature;
11+
use Omnipay\Common\Exception\InvalidResponseException;
12+
13+
/**
14+
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
* @since 1.0.0
16+
*/
17+
trait ResponseSignatureValidation
18+
{
19+
/**
20+
* Kiểm tra tính hợp lệ của dữ liệu do MoMo phản hồi.
21+
*
22+
* @throws InvalidResponseException
23+
*/
24+
protected function validateSignature(): void
25+
{
26+
$data = $this->getData();
27+
$signature = new Signature(
28+
$this->getRequest()->getSecurityCode()
29+
);
30+
$actual = $data['signature'];
31+
unset($data['signature']);
32+
33+
if (! $signature->validate($data, $actual)) {
34+
throw new InvalidResponseException(sprintf('Data signature response from VTCPay is invalid!'));
35+
}
36+
}
37+
}

0 commit comments

Comments
(0)

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