From 68579f83ad74d7feda4ef057a2322636796fd24d Mon Sep 17 00:00:00 2001 From: recca0120 Date: Tue, 16 Jan 2024 13:10:39 +0800 Subject: [PATCH] refactor --- src/Message/AbstractRequest.php | 9 +++++++++ src/Message/FetchTransactionRequest.php | 6 +----- src/Message/PurchaseRequest.php | 5 +---- src/Message/RefundRequest.php | 6 +----- src/Message/VoidRequest.php | 6 +----- tests/Message/FetchTransactionRequestTest.php | 5 +++++ tests/Message/RefundRequestTest.php | 5 +++++ tests/Message/VoidRequestTest.php | 4 ++++ 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 01e8223..5417a16 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -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 diff --git a/src/Message/FetchTransactionRequest.php b/src/Message/FetchTransactionRequest.php index d3b5665..87eaece 100644 --- a/src/Message/FetchTransactionRequest.php +++ b/src/Message/FetchTransactionRequest.php @@ -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'; } /** diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 0457b16..e40f101 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -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'; } /** diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index d827101..1c5162f 100644 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -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'; } /** diff --git a/src/Message/VoidRequest.php b/src/Message/VoidRequest.php index 2d902bd..27113fb 100644 --- a/src/Message/VoidRequest.php +++ b/src/Message/VoidRequest.php @@ -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'; } /** diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php index 9f4b437..588210e 100644 --- a/tests/Message/FetchTransactionRequestTest.php +++ b/tests/Message/FetchTransactionRequestTest.php @@ -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 diff --git a/tests/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php index 6cbdd8f..f4438c5 100644 --- a/tests/Message/RefundRequestTest.php +++ b/tests/Message/RefundRequestTest.php @@ -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() + ); } } diff --git a/tests/Message/VoidRequestTest.php b/tests/Message/VoidRequestTest.php index 03dbd1a..44d101f 100644 --- a/tests/Message/VoidRequestTest.php +++ b/tests/Message/VoidRequestTest.php @@ -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