From 09be003e6bc7f67c91aceb23d5259bbee5ebfd6c Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Mon, 7 Oct 2024 08:44:07 -0300 Subject: [PATCH 1/5] test: delete existing inscription returns true --- tests/Webpay/OneClick/TransbankOneclickTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Webpay/OneClick/TransbankOneclickTest.php b/tests/Webpay/OneClick/TransbankOneclickTest.php index ec470b8a..1d2bfe9c 100644 --- a/tests/Webpay/OneClick/TransbankOneclickTest.php +++ b/tests/Webpay/OneClick/TransbankOneclickTest.php @@ -265,8 +265,7 @@ public function it_deletes_an_existing_inscription() $inscription = new MallInscription($options, $requestServiceMock); $deleteResponse = $inscription->delete('tbkTestUser', 'useNameTest'); - $this->assertTrue($deleteResponse->wasSuccessfull()); - $this->assertSame(204, $deleteResponse->getCode()); + $this->assertTrue($deleteResponse); } /** @test */ From 1f28404d8aa091c4d894492c017775c7c536dd2f Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Mon, 7 Oct 2024 08:44:32 -0300 Subject: [PATCH 2/5] test: delete failed inscription throws exception --- tests/Webpay/OneClick/TransbankOneclickTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Webpay/OneClick/TransbankOneclickTest.php b/tests/Webpay/OneClick/TransbankOneclickTest.php index 1d2bfe9c..7d568a3c 100644 --- a/tests/Webpay/OneClick/TransbankOneclickTest.php +++ b/tests/Webpay/OneClick/TransbankOneclickTest.php @@ -278,10 +278,8 @@ public function it_deletes_an_unexisting_inscription() ->willThrowException(new WebpayRequestException("Could not obtain a response from Transbank API", null, 404)); $options = new Options('apiKey', 'commerceCode', Options::ENVIRONMENT_INTEGRATION); $inscription = new MallInscription($options, $requestServiceMock); - $deleteResponse = $inscription->delete('tbkTestUser', 'useNameTest'); - - $this->assertFalse($deleteResponse->wasSuccessfull()); - $this->assertSame(404, $deleteResponse->getCode()); + $this->expectException(InscriptionDeleteException::class); + $inscription->delete('tbkTestUser', 'useNameTest'); } /** @test */ From 3c0f1254ac5acbc4142f07e4270a23dd0bb5a2eb Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Mon, 7 Oct 2024 08:47:09 -0300 Subject: [PATCH 3/5] refactor: remove unused inscription delete response class --- .../Responses/InscriptionDeleteResponse.php | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php diff --git a/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php b/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php deleted file mode 100644 index a8b505b8..00000000 --- a/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php +++ /dev/null @@ -1,28 +0,0 @@ -success = $success; - $this->code = $httpCode; - } - - public function wasSuccessfull(): bool - { - return $this->success === true; - } - - /** - * @return int|null - */ - public function getCode(): int|null - { - return $this->code; - } -} From b4591b6b9eb3d5b7c8ed6b726b3d2a9996d69972 Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Mon, 7 Oct 2024 08:47:36 -0300 Subject: [PATCH 4/5] test: remove deprecated tests --- .../InscriptionDeleteResponseTest.php | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 tests/Webpay/OneClick/Responses/InscriptionDeleteResponseTest.php diff --git a/tests/Webpay/OneClick/Responses/InscriptionDeleteResponseTest.php b/tests/Webpay/OneClick/Responses/InscriptionDeleteResponseTest.php deleted file mode 100644 index 4f943bd5..00000000 --- a/tests/Webpay/OneClick/Responses/InscriptionDeleteResponseTest.php +++ /dev/null @@ -1,33 +0,0 @@ -assertTrue($response->wasSuccessfull()); - $this->assertSame(200, $response->getCode()); - } - - public function testWasSuccessfull() - { - $response = new InscriptionDeleteResponse(true); - $this->assertTrue($response->wasSuccessfull()); - - $response = new InscriptionDeleteResponse(false); - $this->assertFalse($response->wasSuccessfull()); - } - - public function testGetCode() - { - $response = new InscriptionDeleteResponse(true, 200); - $this->assertSame(200, $response->getCode()); - - $response = new InscriptionDeleteResponse(true, 404); - $this->assertSame(404, $response->getCode()); - } -} From 8606aea71a910f9871921eb50cd8920abe59fbdb Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Mon, 7 Oct 2024 08:48:35 -0300 Subject: [PATCH 5/5] feat: oneclick delete method returns true on success --- src/Webpay/Oneclick/MallInscription.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Webpay/Oneclick/MallInscription.php b/src/Webpay/Oneclick/MallInscription.php index 30f3af15..5430b992 100644 --- a/src/Webpay/Oneclick/MallInscription.php +++ b/src/Webpay/Oneclick/MallInscription.php @@ -7,7 +7,6 @@ use Transbank\Webpay\Oneclick\Exceptions\InscriptionDeleteException; use Transbank\Webpay\Oneclick\Exceptions\InscriptionFinishException; use Transbank\Webpay\Oneclick\Exceptions\InscriptionStartException; -use Transbank\Webpay\Oneclick\Responses\InscriptionDeleteResponse; use Transbank\Webpay\Oneclick\Responses\InscriptionFinishResponse; use Transbank\Webpay\Oneclick\Responses\InscriptionStartResponse; @@ -89,14 +88,13 @@ public function finish(string $token): InscriptionFinishResponse * @param string $tbkUser * @param string $username * - * @return InscriptionDeleteResponse + * @return bool * * @throws InscriptionDeleteException * @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException */ - public function delete(string $tbkUser, string $username): InscriptionDeleteResponse + public function delete(string $tbkUser, string $username): bool { - $successDeletedCode = 204; $payload = [ 'tbk_user' => $tbkUser, 'username' => $username, @@ -109,9 +107,6 @@ public function delete(string $tbkUser, string $username): InscriptionDeleteResp $payload ); } catch (WebpayRequestException $exception) { - if ($exception->getHttpCode() !== $successDeletedCode) { - return new InscriptionDeleteResponse(false, $exception->getHttpCode()); - } throw new InscriptionDeleteException( $exception->getMessage(), @@ -122,6 +117,6 @@ public function delete(string $tbkUser, string $username): InscriptionDeleteResp ); } - return new InscriptionDeleteResponse(true, $successDeletedCode); + return true; } }