From a4548ddf3e1c1881b722ff078af511d5dc98420c Mon Sep 17 00:00:00 2001 From: recca0120 Date: Mon, 13 Nov 2023 15:23:14 +0800 Subject: [PATCH] FetchTransactionTest --- src/Message/FetchTransactionRequest.php | 1 + tests/GatewayTest.php | 3 -- tests/Message/FetchTransactionRequestTest.php | 39 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/Message/FetchTransactionRequestTest.php diff --git a/src/Message/FetchTransactionRequest.php b/src/Message/FetchTransactionRequest.php index 6087b44..6b107cf 100644 --- a/src/Message/FetchTransactionRequest.php +++ b/src/Message/FetchTransactionRequest.php @@ -59,6 +59,7 @@ public function getData() return $value !== null && $value !== ''; }); + var_dump($data); $data['CheckValue'] = $this->checkValue($data); return $data; diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 49b73ff..fbc7ad0 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -116,9 +116,6 @@ public function testFetchTransaction() self::assertEquals('授權成功', $response->getMessage()); self::assertEquals('Vanespl_ec_1695795668', $response->getTransactionId()); self::assertEquals('23092714215835071', $response->getTransactionReference()); - - parse_str((string) $this->getMockClient()->getLastRequest()->getBody(), $postData); - self::assertEquals('CD326F689018E7862727547F85CECD7DD7AE0FDB7782DE2C1E46B4417245B51F', $postData['CheckValue']); } public function testVoid() diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php new file mode 100644 index 0000000..93fd35f --- /dev/null +++ b/tests/Message/FetchTransactionRequestTest.php @@ -0,0 +1,39 @@ +getHttpClient(), $this->getHttpRequest()); + + $this->setMockHttpResponse('FetchTransactionSuccess.txt'); + + $request->initialize(array_merge([ + 'HashKey' => 'Fs5cX1TGqYM2PpdbE14a9H83YQSQF5jn', + 'HashIV' => 'C6AcmfqJILwgnhIP', + 'MerchantID' => 'MS127874575', + 'testMode' => true, + ], [ + 'TimeStamp' => $timestamp, + 'transactionId' => 'Vanespl_ec_'.$timestamp, + 'amount' => 30, + ])); + + $response = $request->send(); + + self::assertTrue($response->isSuccessful()); + self::assertEquals('00', $response->getCode()); + self::assertEquals('授權成功', $response->getMessage()); + self::assertEquals('Vanespl_ec_1695795668', $response->getTransactionId()); + self::assertEquals('23092714215835071', $response->getTransactionReference()); + + parse_str((string) $this->getMockClient()->getLastRequest()->getBody(), $postData); + self::assertEquals('CD326F689018E7862727547F85CECD7DD7AE0FDB7782DE2C1E46B4417245B51F', $postData['CheckValue']); + } +}