Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve delete method #302

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/Webpay/Oneclick/MallInscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -122,6 +117,6 @@ public function delete(string $tbkUser, string $username): InscriptionDeleteResp
);
}

return new InscriptionDeleteResponse(true, $successDeletedCode);
return true;
}
}
28 changes: 0 additions & 28 deletions src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php

This file was deleted.

33 changes: 0 additions & 33 deletions tests/Webpay/OneClick/Responses/InscriptionDeleteResponseTest.php

This file was deleted.

9 changes: 3 additions & 6 deletions tests/Webpay/OneClick/TransbankOneclickTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -279,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 */
Expand Down