Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Jan 16, 2024
1 parent 43eecf8 commit 68579f8
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 19 deletions.
9 changes: 9 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
*/
abstract class AbstractRequest extends BaseAbstractRequest
{
protected $liveEndpoint = 'https://core.newebpay.com/';

protected $testEndpoint = 'https://ccore.newebpay.com/';

public function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
}

/**
* @param ResponseInterface|string $response
* @return array
Expand Down
6 changes: 1 addition & 5 deletions src/Message/FetchTransactionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ class FetchTransactionRequest extends AbstractRequest
{
use HasDefaults;

protected $liveEndpoint = 'https://core.newebpay.com/API/QueryTradeInfo';

protected $testEndpoint = 'https://ccore.newebpay.com/API/QueryTradeInfo';

public function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
return parent::getEndpoint().'API/QueryTradeInfo';
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ class PurchaseRequest extends AbstractRequest
{
use HasDefaults;

protected $liveEndpoint = 'https://core.newebpay.com/MPG/mpg_gateway';

protected $testEndpoint = 'https://ccore.newebpay.com/MPG/mpg_gateway';

public function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
return parent::getEndpoint().'MPG/mpg_gateway';
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Message/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ class RefundRequest extends AbstractRequest
{
use HasDefaults;

protected $liveEndpoint = 'https://ccore.newebpay.com/API/CreditCard/Close';

protected $testEndpoint = 'https://ccore.newebpay.com/API/CreditCard/Close';

public function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
return parent::getEndpoint().'API/CreditCard/Close';
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Message/VoidRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ class VoidRequest extends AbstractRequest
{
use HasDefaults;

protected $liveEndpoint = 'https://core.newebpay.com/API/CreditCard/Cancel';

protected $testEndpoint = 'https://ccore.newebpay.com/API/CreditCard/Cancel';

public function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
return parent::getEndpoint().'API/CreditCard/Cancel';
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/Message/FetchTransactionRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public function testSendData()
self::assertEquals('付款成功', $response->getMessage());
self::assertEquals('Vanespl_ec_1695795668', $response->getTransactionId());
self::assertEquals('23092714215835071', $response->getTransactionReference());

self::assertEquals(
'https://ccore.newebpay.com/API/QueryTradeInfo',
(string) $this->getMockClient()->getLastRequest()->getUri()
);
}

public function testSendDataForJSON(): void
Expand Down
5 changes: 5 additions & 0 deletions tests/Message/RefundRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ public function testSendDataFailed(): void
'61d27f528031d936b29c87802479e4e51e9cc72935abba1cade58c7524504e727e53d7209593175899023a68200d18e9cc998119e760a29cc76a5d1de88fc8da93367ffc9c50f09b9b6a43f42c716a10327734c40bd8b02139601ac6c0674a407930b2bf615bb13c7d5b383ad4c8e879d92298dcbb0be3022a5c8a0143a8c4447e528710993fc41041c299c895b405ed5187ca6f4c3d1a85130c8e83a742e6d1',
$postData['PostData_']
);

self::assertEquals(
'https://ccore.newebpay.com/API/CreditCard/Close',
(string) $this->getMockClient()->getLastRequest()->getUri()
);
}
}
4 changes: 4 additions & 0 deletions tests/Message/VoidRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function testSendData(): void
'61d27f528031d936b29c87802479e4e51e9cc72935abba1cade58c7524504e72a86f00fe167dca60eefc3f9c17917154a7c626641829b6bac38e3863b97c1b11a91399194a674a8fc2820c2247954fc5b16a2094e89a3fa79b15b3bf0c8dbf0677b7420af3e5c528426e1e0e6c41206b',
$postData['PostData_']
);
self::assertEquals(
'https://ccore.newebpay.com/API/CreditCard/Cancel',
(string) $this->getMockClient()->getLastRequest()->getUri()
);
}

public function testSendDataForJSON(): void
Expand Down

0 comments on commit 68579f8

Please sign in to comment.