Skip to content

Commit

Permalink
get data from request
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Nov 11, 2023
1 parent 3aa67c9 commit 4248859
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 187 deletions.
200 changes: 100 additions & 100 deletions build/report.junit.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$config = require __DIR__.'/config.php';
$gateway = Omnipay::create('Cathaybk');
$gateway->initialize($config);
$request = $gateway->completePurchase($_POST);
$request = $gateway->completePurchase();
$response = $request->send();

require __DIR__.'/response.php';
1 change: 1 addition & 0 deletions demo/config.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
return [
'STOREID' => '',
'CUBKEY' => '',
'RETURL' => 'complete.php',
];
4 changes: 1 addition & 3 deletions demo/notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
$config = require __DIR__.'/config.php';
$gateway = Omnipay::create('Cathaybk');
$gateway->initialize($config);
$request = $gateway->acceptNotification(array_merge($_POST, [
'returnUrl' => 'complete.php',
]));
$request = $gateway->acceptNotification();
$response = $request->send();

echo $response->getMessage();
14 changes: 7 additions & 7 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
* }
* </code>
*
* @method RequestInterface authorize(array $options = array())
* @method RequestInterface completeAuthorize(array $options = array())
* @method RequestInterface createCard(array $options = array())
* @method RequestInterface updateCard(array $options = array())
* @method RequestInterface deleteCard(array $options = array())
* @method RequestInterface authorize(array $options = [])
* @method RequestInterface completeAuthorize(array $options = [])
* @method RequestInterface createCard(array $options = [])
* @method RequestInterface updateCard(array $options = [])
* @method RequestInterface deleteCard(array $options = [])
*/
class Gateway extends AbstractGateway
{
Expand All @@ -89,7 +89,7 @@ public function getName()

public function getDefaultParameters()
{
return ['STOREID' => '', 'CUBKEY' => ''];
return ['STOREID' => '', 'CUBKEY' => '', 'RETURL' => ''];
}

/**
Expand All @@ -113,7 +113,7 @@ public function purchase(array $options = [])
*/
public function completePurchase(array $options = [])
{
return array_key_exists('strRsXML', $options)
return array_key_exists('strRsXML', $this->httpRequest->request->all())
? $this->acceptNotification($options)
: $this->createRequest(CompletePurchaseRequest::class, $options);
}
Expand Down
36 changes: 2 additions & 34 deletions src/Message/AcceptNotificationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,16 @@ class AcceptNotificationRequest extends AbstractRequest implements NotificationI
use HasAssertCaValue;
use HasSignCaValue;

/**
* @return AcceptNotificationRequest
*/
public function setRetUrl($returnUrl)
{
return $this->setReturnUrl($returnUrl);
}

/**
* @return string
*/
public function getRetUrl()
{
return $this->getReturnUrl();
}

/**
* @return AcceptNotificationRequest
*/
public function setStrRsXML($strRsXML)
{
return $this->setParameter('strRsXML', $strRsXML);
}

/**
* @return string
*/
public function getStrRsXML()
{
return $this->getParameter('strRsXML');
}

/**
* @return array
*
* @throws InvalidRequestException
*/
public function getData()
{
$this->validate('STOREID', 'CUBKEY', 'strRsXML', 'returnUrl');
$this->validate('STOREID', 'CUBKEY', 'returnUrl');

$returnValues = Helper::xml2array($this->getStrRsXML());
$returnValues = Helper::xml2array($this->httpRequest->request->get('strRsXML'));
$this->assertCaValue($returnValues);
$retUrl = $this->getReturnUrl();

Expand Down
23 changes: 1 addition & 22 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,23 @@

use Omnipay\Cathaybk\Support\Helper;
use Omnipay\Cathaybk\Traits\HasAssertCaValue;
use Omnipay\Cathaybk\Traits\HasLanguage;
use Omnipay\Cathaybk\Traits\HasStore;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Message\AbstractRequest;

class CompletePurchaseRequest extends AbstractRequest
{
use HasStore;
use HasLanguage;
use HasAssertCaValue;

/**
* @return CompletePurchaseRequest
*/
public function setStrOrderInfo($strOrderInfo)
{
return $this->setParameter('strOrderInfo', $strOrderInfo);
}

/**
* @return string
*/
public function getStrOrderInfo()
{
return $this->getParameter('strOrderInfo');
}

/**
* @return array
*
* @throws InvalidRequestException
*/
public function getData()
{
$this->validate('STOREID', 'CUBKEY', 'strOrderInfo');

$orderInfo = Helper::xml2array($this->getStrOrderInfo());

$orderInfo = Helper::xml2array($this->httpRequest->request->get('strOrderInfo'));
$this->assertCaValue($orderInfo);

return $orderInfo;
Expand Down
16 changes: 16 additions & 0 deletions src/Traits/HasStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,20 @@ public function getCubKey()
{
return $this->getParameter('CUBKEY');
}

/**
* @return static
*/
public function setRetUrl($value)
{
return $this->setParameter('returnUrl', $value);
}

/**
* @return string
*/
public function getRetUrl()
{
return $this->getParameter('returnUrl');
}
}
29 changes: 17 additions & 12 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@ public function testPurchase()
public function testGetAcceptNotificationWhenCompletePurchaseHasStrRsXML()
{
$options = ['strRsXML' => 'foo'];
$request = $this->gateway->completePurchase($options);
$this->getHttpRequest()->request->add($options);
$request = $this->gateway->completePurchase();

self::assertInstanceOf(AcceptNotificationRequest::class, $request);
}

public function testCompletePurchase()
{
$xmlData = $this->generateXmlData();
$data = ['strOrderInfo' => Helper::array2xml($xmlData)];
$this->getHttpRequest()->request->add($data);

$options = ['strOrderInfo' => Helper::array2xml($xmlData)];

$request = $this->gateway->completePurchase($options);
$request = $this->gateway->completePurchase();
$response = $request->send();

self::assertInstanceOf(CompletePurchaseRequest::class, $request);
Expand All @@ -75,8 +77,9 @@ public function testCompletePurchase()

public function testAcceptNotification()
{
$options = [];
$request = $this->gateway->acceptNotification($options);
$data = [];
$this->getHttpRequest()->request->add($data);
$request = $this->gateway->acceptNotification();
self::assertInstanceOf(AcceptNotificationRequest::class, $request);
}

Expand Down Expand Up @@ -106,13 +109,15 @@ public function testVoid()
*/
private function generateXmlData()
{
$options = ['CUBXML' => [
'CAVALUE' => '',
'ORDERINFO' => [
'STOREID' => $this->storeId,
'ORDERNUMBER' => uniqid('order_number', true),
$options = [
'CUBXML' => [
'CAVALUE' => '',
'ORDERINFO' => [
'STOREID' => $this->storeId,
'ORDERNUMBER' => uniqid('order_number', true),
],
],
]];
];
$options['CUBXML']['CAVALUE'] = Helper::caValue(array_merge(
$options,
['STOREID' => $this->storeId, 'CUBKEY' => $this->cubKey]
Expand Down
4 changes: 3 additions & 1 deletion tests/Message/AcceptNotificationRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public function testGetData()
$cubKey = uniqid('cub_key', true);
$returnUrl = 'https://foo.bar/return-url';
$xmlData = $this->generateXmlData($storeId, $cubKey);
$this->getHttpRequest()->request->add([
'strRsXML' => Helper::array2xml($xmlData),
]);
$request = new AcceptNotificationRequest($this->getHttpClient(), $this->getHttpRequest());

$options = [
'STOREID' => $storeId,
'CUBKEY' => $cubKey,
'RETURL' => $returnUrl,
'strRsXML' => $strRsXML = Helper::array2xml($xmlData),
];
$request->initialize($options);

Expand Down
17 changes: 10 additions & 7 deletions tests/UnionPayGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,22 @@ public function testPurchase()

public function testCompletePurchase()
{
$options = ['CUBXML' => [
'CAVALUE' => '',
'ORDERINFO' => [
'STOREID' => $this->storeId,
'ORDERNUMBER' => uniqid('order_number', true),
$options = [
'CUBXML' => [
'CAVALUE' => '',
'ORDERINFO' => [
'STOREID' => $this->storeId,
'ORDERNUMBER' => uniqid('order_number', true),
],
],
]];
];
$options['CUBXML']['CAVALUE'] = Helper::caValue(array_merge(
$options,
['STOREID' => $this->storeId, 'CUBKEY' => $this->cubKey]
), ['STOREID', 'ORDERNUMBER', 'CUBKEY']);

$request = $this->gateway->completePurchase(['strOrderInfo' => Helper::array2xml($options)]);
$this->getHttpRequest()->request->add(['strOrderInfo' => Helper::array2xml($options)]);
$request = $this->gateway->completePurchase();
$response = $request->send();

self::assertInstanceOf(CompletePurchaseRequest::class, $request);
Expand Down

0 comments on commit 4248859

Please sign in to comment.