Skip to content

Commit 915e633

Browse files
Added messages
1 parent 60ef48c commit 915e633

File tree

8 files changed

+640
-0
lines changed

8 files changed

+640
-0
lines changed
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-vtcpay
4+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
namespace Omnipay\VTCPay\Message;
10+
11+
/**
12+
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
* @since 1.0.0
14+
*/
15+
abstract class AbstractIncomingRequest extends AbstractRequest
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function initialize(array $parameters = [])
21+
{
22+
parent::initialize($parameters);
23+
24+
foreach ($this->getIncomingParameters() as $parameter => $value) {
25+
$this->setParameter($parameter, $value);
26+
}
27+
28+
return $this;
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
* @throws \Omnipay\Common\Exception\InvalidRequestException
34+
*/
35+
public function getData(): array
36+
{
37+
$this->validate('signature');
38+
39+
return $this->getIncomingParameters();
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
* @throws \Omnipay\Common\Exception\InvalidResponseException
45+
*/
46+
public function sendData($data): IncomingResponse
47+
{
48+
return $this->response = new IncomingResponse($this, $data);
49+
}
50+
51+
/**
52+
* Trả về danh sách parameters từ VTCPay gửi sang.
53+
*
54+
* @return array
55+
*/
56+
abstract protected function getIncomingParameters(): array;
57+
}

src/Message/AbstractRequest.php

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+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
namespace Omnipay\VTCPay\Message;
10+
11+
use Omnipay\VTCPay\Concerns\Parameters;
12+
use Omnipay\VTCPay\Concerns\ParametersNormalize;
13+
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;
14+
15+
/**
16+
* @author Vuong Minh <vuongxuongminh@gmail.com>
17+
* @since 1.0.0
18+
*/
19+
abstract class AbstractRequest extends BaseAbstractRequest
20+
{
21+
use Parameters;
22+
use ParametersNormalize;
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function initialize(array $parameters = [])
28+
{
29+
return parent::initialize(
30+
$this->normalizeParameters($parameters)
31+
);
32+
}
33+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-vtcpay
4+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
namespace Omnipay\VTCPay\Message;
10+
11+
/**
12+
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
* @since 1.0.0
14+
*/
15+
class CompletePurchaseRequest extends AbstractIncomingRequest
16+
{
17+
/**
18+
* {@inheritdoc}
19+
* @throws \Omnipay\Common\Exception\InvalidRequestException
20+
*/
21+
public function getData(): array
22+
{
23+
$this->validate('amount', 'reference_number', 'status', 'website_id');
24+
25+
return parent::getData();
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
protected function getIncomingParameters(): array
32+
{
33+
return $this->httpRequest->query->all();
34+
}
35+
}

src/Message/IncomingResponse.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-vtcpay
4+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
namespace Omnipay\VTCPay\Message;
10+
11+
use Omnipay\Common\Message\RequestInterface;
12+
13+
/**
14+
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
* @since 1.0.0
16+
*/
17+
class IncomingResponse extends Response
18+
{
19+
use Concerns\ResponseSignatureValidation;
20+
21+
/**
22+
* {@inheritdoc}
23+
* @throws \Omnipay\Common\Exception\InvalidResponseException
24+
*/
25+
public function __construct(RequestInterface $request, $data)
26+
{
27+
parent::__construct($request, $data);
28+
29+
$this->validateSignature();
30+
}
31+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-vtcpay
4+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
namespace Omnipay\VTCPay\Message;
10+
11+
/**
12+
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
* @since 1.0.0
14+
*/
15+
class NotificationRequest extends AbstractIncomingRequest
16+
{
17+
/**
18+
* {@inheritdoc}
19+
* @throws \Omnipay\Common\Exception\InvalidRequestException
20+
*/
21+
public function getData(): array
22+
{
23+
$this->validate('data');
24+
25+
return parent::getData();
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function sendData($data): IncomingResponse
32+
{
33+
$signature = $data['signature'];
34+
$data = $data['data'];
35+
$data['signature'] = $signature;
36+
37+
return parent::sendData($data);
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
protected function getIncomingParameters(): array
44+
{
45+
return $this->httpRequest->request->all();
46+
}
47+
}

0 commit comments

Comments
 (0)