Skip to content

Commit

Permalink
Merge pull request #302 from TransbankDevelopers/feat/improve-delete-…
Browse files Browse the repository at this point in the history
…method

feat: improve delete method
  • Loading branch information
Matiasnickolas authored Oct 7, 2024
2 parents f0cdcae + 8606aea commit f1035a3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 75 deletions.
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

0 comments on commit f1035a3

Please sign in to comment.