Skip to content

Commit

Permalink
catch InvalidResponseException
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Feb 27, 2024
1 parent 63a862a commit ec738a8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Message/MyCash/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Omnipay\EPays\Message\MyCash;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\EPays\Traits\MyCash\HasMyCash;

Expand All @@ -13,15 +13,15 @@ class CompletePurchaseRequest extends AbstractRequest
/**
* @return array
*
* @throws InvalidRequestException
* @throws InvalidResponseException
*/
public function getData()
{
$data = $this->httpRequest->request->all();
$validate = array_key_exists('Validate', $data) ? $data['Validate'] : '';

if ($this->makeHash($data) !== $validate) {
throw new InvalidRequestException('Incorrect hash');
throw new InvalidResponseException('Incorrect hash');
}

return $data;
Expand Down
1 change: 1 addition & 0 deletions src/Message/XWallet/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
abstract class AbstractRequest extends BaseAbstractRequest
{
private $liveEndpoint = 'https://xwallet-op.epays.tw';

private $testEndpoint = 'http://xpop-test.epays.com.tw';

public function getEndpoint()
Expand Down
4 changes: 2 additions & 2 deletions tests/Message/MyCash/AcceptNotificationRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Omnipay\EPays\Tests\Message\MyCash;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\NotificationInterface;
use Omnipay\EPays\Message\MyCash\AcceptNotificationRequest;
use Omnipay\EPays\Message\MyCash\CompletePurchaseRequest;
Expand All @@ -18,7 +18,7 @@ class AcceptNotificationRequestTest extends TestCase

public function testValidateFails(): void
{
$this->expectException(InvalidRequestException::class);
$this->expectException(InvalidResponseException::class);

$options = [
'RtnCode' => '1',
Expand Down
4 changes: 2 additions & 2 deletions tests/Message/MyCash/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Omnipay\EPays\Tests\Message\MyCash;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\EPays\Message\MyCash\CompletePurchaseRequest;
use Omnipay\Tests\TestCase;

Expand All @@ -16,7 +16,7 @@ class CompletePurchaseRequestTest extends TestCase

public function testValidateFails(): void
{
$this->expectException(InvalidRequestException::class);
$this->expectException(InvalidResponseException::class);
$this->expectExceptionMessage('Incorrect hash');

$options = [
Expand Down
4 changes: 2 additions & 2 deletions tests/Message/XWallet/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function testSendData()
self::assertEquals('http://xpop-test.epays.com.tw/api/o/new', $response->getRedirectUrl());
self::assertEquals('POST', $response->getRedirectMethod());
self::assertEquals([
"Hashkey" => "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"data" => "u4OlyM8T0QFQPQkL8XhzfxH5QVFmVcYqUW+hXuic5a+y9cIjEY8qr3gOoIUmOZLufZtW/3fDRNP2yQAR2kt4Uaqpq24cR9GTgQBXg5eZDjEzsv4hCE+vXqHdQeNBOe+R",
'Hashkey' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'data' => 'u4OlyM8T0QFQPQkL8XhzfxH5QVFmVcYqUW+hXuic5a+y9cIjEY8qr3gOoIUmOZLufZtW/3fDRNP2yQAR2kt4Uaqpq24cR9GTgQBXg5eZDjEzsv4hCE+vXqHdQeNBOe+R',
], $response->getRedirectData());
}
}

0 comments on commit ec738a8

Please sign in to comment.