Skip to content

Commit

Permalink
catch InvalidRequestException
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Feb 27, 2024
1 parent 63a862a commit decee48
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
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
5 changes: 3 additions & 2 deletions src/Message/XWallet/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Omnipay\EPays\Message\XWallet;

use Exception;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\EPays\Encryptor;
use Omnipay\EPays\Traits\XWallet\HasEPays;
Expand All @@ -12,7 +13,7 @@ class CompletePurchaseRequest extends AbstractRequest
use HasEPays;

/**
* @throws InvalidResponseException
* @throws InvalidRequestException
*/
public function getData()
{
Expand All @@ -21,7 +22,7 @@ public function getData()
$encryptor = new Encryptor($this->getHashKey(), $this->getHashIV());
$data['data'] = $encryptor->decrypt($data['data']);
} catch (Exception $e) {
throw new InvalidResponseException('Decrypt data failed', 0, $e);
throw new InvalidRequestException('Decrypt data failed', 0, $e);
}

if (empty($data['data'])) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Message/XWallet/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Omnipay\EPays\Tests\Message\XWallet;

use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\EPays\Encryptor;
use Omnipay\EPays\Message\XWallet\CompletePurchaseRequest;
use Omnipay\Tests\TestCase;
Expand Down Expand Up @@ -69,7 +69,7 @@ public function testSend(): void

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

$httpRequest = new HttpRequest([], [], [], [], [], [], json_encode([
'state' => 1,
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 decee48

Please sign in to comment.