From 4f725a333078b37537920923ffd32e6b7dc4b76a Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 5 Jun 2024 10:40:26 -0400 Subject: [PATCH 1/4] feat: remove patpass by webpay --- src/Patpass/PatpassByWebpay.php | 23 --- .../Exceptions/TransactionCommitException.php | 10 -- .../Exceptions/TransactionCreateException.php | 10 -- .../Exceptions/TransactionStatusException.php | 10 -- .../Responses/TransactionCommitResponse.php | 137 ------------------ .../Responses/TransactionCreateResponse.php | 39 ----- .../Responses/TransactionStatusResponse.php | 7 - src/Patpass/PatpassByWebpay/Transaction.php | 102 ------------- 8 files changed, 338 deletions(-) delete mode 100644 src/Patpass/PatpassByWebpay.php delete mode 100644 src/Patpass/PatpassByWebpay/Exceptions/TransactionCommitException.php delete mode 100644 src/Patpass/PatpassByWebpay/Exceptions/TransactionCreateException.php delete mode 100644 src/Patpass/PatpassByWebpay/Exceptions/TransactionStatusException.php delete mode 100644 src/Patpass/PatpassByWebpay/Responses/TransactionCommitResponse.php delete mode 100644 src/Patpass/PatpassByWebpay/Responses/TransactionCreateResponse.php delete mode 100644 src/Patpass/PatpassByWebpay/Responses/TransactionStatusResponse.php delete mode 100644 src/Patpass/PatpassByWebpay/Transaction.php diff --git a/src/Patpass/PatpassByWebpay.php b/src/Patpass/PatpassByWebpay.php deleted file mode 100644 index f24ff6b3..00000000 --- a/src/Patpass/PatpassByWebpay.php +++ /dev/null @@ -1,23 +0,0 @@ -vci = Utils::returnValueIfExists($json, 'vci'); - $this->amount = Utils::returnValueIfExists($json, 'amount'); - $this->status = Utils::returnValueIfExists($json, 'status'); - $this->buyOrder = Utils::returnValueIfExists($json, 'buy_order'); - $this->sessionId = Utils::returnValueIfExists($json, 'session_id'); - $this->cardDetail = Utils::returnValueIfExists($json, 'card_detail'); - $this->accountingDate = Utils::returnValueIfExists($json, 'accounting_date'); - $this->transactionDate = Utils::returnValueIfExists($json, 'transaction_date'); - $this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code'); - $this->paymentTypeCode = Utils::returnValueIfExists($json, 'payment_type_code'); - $this->responseCode = Utils::returnValueIfExists($json, 'response_code'); - $this->installmentsNumber = Utils::returnValueIfExists($json, 'installments_number'); - } - - /** - * @return mixed - */ - public function getVci() - { - return $this->vci; - } - - /** - * @return mixed - */ - public function getAmount() - { - return $this->amount; - } - - /** - * @return mixed - */ - public function getStatus() - { - return $this->status; - } - - /** - * @return mixed - */ - public function getBuyOrder() - { - return $this->buyOrder; - } - - /** - * @return mixed - */ - public function getSessionId() - { - return $this->sessionId; - } - - /** - * @return mixed - */ - public function getCardDetail() - { - return $this->cardDetail; - } - - /** - * @return mixed - */ - public function getAccountingDate() - { - return $this->accountingDate; - } - - /** - * @return mixed - */ - public function getTransactionDate() - { - return $this->transactionDate; - } - - /** - * @return mixed - */ - public function getAuthorizationCode() - { - return $this->authorizationCode; - } - - /** - * @return mixed - */ - public function getPaymentTypeCode() - { - return $this->paymentTypeCode; - } - - /** - * @return mixed - */ - public function getResponseCode() - { - return (int) $this->responseCode; - } - - /** - * @return mixed - */ - public function getInstallmentsNumber() - { - return $this->installmentsNumber; - } - -} diff --git a/src/Patpass/PatpassByWebpay/Responses/TransactionCreateResponse.php b/src/Patpass/PatpassByWebpay/Responses/TransactionCreateResponse.php deleted file mode 100644 index a9c59532..00000000 --- a/src/Patpass/PatpassByWebpay/Responses/TransactionCreateResponse.php +++ /dev/null @@ -1,39 +0,0 @@ -token = Utils::returnValueIfExists($json, 'token'); - $this->url = Utils::returnValueIfExists($json, 'url'); - } - - /** - * @return mixed - */ - public function getToken() - { - return $this->token; - } - - /** - * @return mixed - */ - public function getUrl() - { - return $this->url; - } - -} diff --git a/src/Patpass/PatpassByWebpay/Responses/TransactionStatusResponse.php b/src/Patpass/PatpassByWebpay/Responses/TransactionStatusResponse.php deleted file mode 100644 index 29d780dd..00000000 --- a/src/Patpass/PatpassByWebpay/Responses/TransactionStatusResponse.php +++ /dev/null @@ -1,7 +0,0 @@ - $buyOrder, - 'session_id' => $sessionId, - 'amount' => $amount, - 'return_url' => $returnUrl, - 'wpm_detail' => $details, - ]; - $endpoint = static::CREATE_TRANSACTION_ENDPOINT; - - try { - $response = $this->sendRequest('POST', $endpoint, $payload); - } catch (WebpayRequestException $exception) { - throw new TransactionCreateException($exception->getMessage(), - $exception->getTransbankErrorMessage(), - $exception->getHttpCode(), - $exception->getFailedRequest(), - $exception - ); - } - - return new TransactionCreateResponse($response); - } - - public function commit($token) - { - $payload = []; - $endpoint = static::COMMIT_TRANSACTION_ENDPOINT; - - try { - $response = $this->sendRequest('PUT', $endpoint.'/'.$token, $payload); - } catch (WebpayRequestException $exception) { - throw new TransactionCommitException($exception->getMessage(), - $exception->getTransbankErrorMessage(), - $exception->getHttpCode(), - $exception->getFailedRequest(), - $exception - ); - } - - return new TransactionCommitResponse($response); - } - - public function status($token) - { - $payload = []; - $endpoint = str_replace('{token}', $token, self::GET_TRANSACTION_STATUS_ENDPOINT); - - try { - $response = $this->sendRequest('GET', $endpoint, $payload); - } catch (WebpayRequestException $exception) { - throw new TransactionStatusException($exception->getMessage(), - $exception->getTransbankErrorMessage(), - $exception->getHttpCode(), - $exception->getFailedRequest(), - $exception - ); - } - - return new TransactionStatusResponse($response); - } - - /** - * Get the default options if none are given. - * - * @return Transbank\Patpass\Options|null - */ - public static function getGlobalOptions() - { - return PatpassByWebpay::getOptions(); - } - - public static function getDefaultOptions() - { - return PatpassByWebpay::getDefaultOptions(); - } -} From a09dabab28da4eb25ea667ff58255c738ba1f2fa Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 5 Jun 2024 10:40:52 -0400 Subject: [PATCH 2/4] feat: remove webpay modal --- .../Exceptions/TransactionCommitException.php | 9 - .../Exceptions/TransactionCreateException.php | 9 - .../Exceptions/TransactionRefundException.php | 9 - .../Exceptions/TransactionStatusException.php | 9 - .../Responses/TransactionCommitResponse.php | 7 - .../Responses/TransactionCreateResponse.php | 26 --- .../Responses/TransactionRefundResponse.php | 7 - .../Responses/TransactionStatusResponse.php | 40 ----- src/Webpay/Modal/Transaction.php | 155 ------------------ src/Webpay/Modal/WebpayModal.php | 19 --- 10 files changed, 290 deletions(-) delete mode 100644 src/Webpay/Modal/Exceptions/TransactionCommitException.php delete mode 100644 src/Webpay/Modal/Exceptions/TransactionCreateException.php delete mode 100644 src/Webpay/Modal/Exceptions/TransactionRefundException.php delete mode 100644 src/Webpay/Modal/Exceptions/TransactionStatusException.php delete mode 100644 src/Webpay/Modal/Responses/TransactionCommitResponse.php delete mode 100644 src/Webpay/Modal/Responses/TransactionCreateResponse.php delete mode 100644 src/Webpay/Modal/Responses/TransactionRefundResponse.php delete mode 100644 src/Webpay/Modal/Responses/TransactionStatusResponse.php delete mode 100644 src/Webpay/Modal/Transaction.php delete mode 100644 src/Webpay/Modal/WebpayModal.php diff --git a/src/Webpay/Modal/Exceptions/TransactionCommitException.php b/src/Webpay/Modal/Exceptions/TransactionCommitException.php deleted file mode 100644 index dc0c5322..00000000 --- a/src/Webpay/Modal/Exceptions/TransactionCommitException.php +++ /dev/null @@ -1,9 +0,0 @@ -token = Utils::returnValueIfExists($json, 'token'); - } - - /** - * @return string|null - */ - public function getToken() - { - return $this->token; - } -} diff --git a/src/Webpay/Modal/Responses/TransactionRefundResponse.php b/src/Webpay/Modal/Responses/TransactionRefundResponse.php deleted file mode 100644 index 83167986..00000000 --- a/src/Webpay/Modal/Responses/TransactionRefundResponse.php +++ /dev/null @@ -1,7 +0,0 @@ -setTransactionStatusFields($json); - } - - public function isApproved() - { - if($this->getResponseCode() !== ResponseCodesEnum::RESPONSE_CODE_APPROVED) { - return false; - } - - switch($this->getStatus()) { - case TransactionStatusEnum::STATUS_CAPTURED: - case TransactionStatusEnum::STATUS_REVERSED: - case TransactionStatusEnum::STATUS_NULLIFIED: - case TransactionStatusEnum::STATUS_AUTHORIZED: - case TransactionStatusEnum::STATUS_PARTIALLY_NULLIFIED: - return true; - default : - return false; - } - } -} diff --git a/src/Webpay/Modal/Transaction.php b/src/Webpay/Modal/Transaction.php deleted file mode 100644 index a125d2f2..00000000 --- a/src/Webpay/Modal/Transaction.php +++ /dev/null @@ -1,155 +0,0 @@ - $buyOrder, - 'session_id' => $sessionId, - 'amount' => $amount, - ]; - - try { - $response = $this->sendRequest('POST', static::CREATE_TRANSACTION_ENDPOINT, $payload); - } catch (WebpayRequestException $exception) { - throw new TransactionCreateException($exception->getMessage(), - $exception->getTransbankErrorMessage(), - $exception->getHttpCode(), - $exception->getFailedRequest(), - $exception - ); - } - - return new TransactionCreateResponse($response); - } - - /** - * @param string $token - * - * @throws TransactionCommitException|GuzzleHttp\Exception\GuzzleException - * - * @return TransactionCommitResponse - ** - */ - public function commit($token) - { - $endpoint = str_replace('{token}', $token, static::COMMIT_TRANSACTION_ENDPOINT); - - try { - $response = $this->sendRequest('PUT', $endpoint, []); - } catch (WebpayRequestException $exception) { - throw new TransactionCommitException($exception->getMessage(), - $exception->getTransbankErrorMessage(), - $exception->getHttpCode(), - $exception->getFailedRequest(), - $exception - ); - } - - return new TransactionCommitResponse($response); - } - - /** - * @param $token - * - * @throws GuzzleHttp\Exception\GuzzleException - * @throws TransactionStatusException - * - * @return TransactionStatusResponse - */ - public function status($token) - { - $endpoint = str_replace('{token}', $token, static::STATUS_TRANSACTION_ENDPOINT); - - try { - $response = $this->sendRequest('GET', $endpoint, []); - } catch (WebpayRequestException $exception) { - throw new TransactionStatusException($exception->getMessage(), - $exception->getTransbankErrorMessage(), - $exception->getHttpCode(), - $exception->getFailedRequest(), - $exception - ); - } - - return new TransactionStatusResponse($response); - } - - /** - * @param $token - * @param $amount - * @param Options|null $options - * - * @throws GuzzleHttp\Exception\GuzzleException|TransactionRefundException - * - * @return TransactionRefundResponse - */ - public function refund($token, $amount) - { - $endpoint = str_replace('{token}', $token, static::REFUND_TRANSACTION_ENDPOINT); - - try { - $response = $this->sendRequest( - 'POST', - $endpoint, - ['amount' => $amount] - ); - } catch (WebpayRequestException $exception) { - throw new TransactionRefundException($exception->getMessage(), - $exception->getTransbankErrorMessage(), - $exception->getHttpCode(), - $exception->getFailedRequest(), - $exception - ); - } - - return new TransactionRefundResponse($response); - } - - public static function getDefaultOptions() - { - return Options::forIntegration(WebpayModal::DEFAULT_COMMERCE_CODE, WebpayModal::DEFAULT_API_KEY); - } - - public static function getGlobalOptions() - { - return WebpayModal::getOptions(); - } -} diff --git a/src/Webpay/Modal/WebpayModal.php b/src/Webpay/Modal/WebpayModal.php deleted file mode 100644 index a1910786..00000000 --- a/src/Webpay/Modal/WebpayModal.php +++ /dev/null @@ -1,19 +0,0 @@ - Date: Wed, 5 Jun 2024 10:41:43 -0400 Subject: [PATCH 3/4] test: remove patpass by webpay --- .../TransactionCommitResponseTest.php | 83 ------------------- .../TransactionCreateResponseTest.php | 34 -------- tests/Patpass/PatpassByWebpayTest.php | 29 ------- 3 files changed, 146 deletions(-) delete mode 100644 tests/Patpass/ByWebpay/Responses/TransactionCommitResponseTest.php delete mode 100644 tests/Patpass/ByWebpay/Responses/TransactionCreateResponseTest.php delete mode 100644 tests/Patpass/PatpassByWebpayTest.php diff --git a/tests/Patpass/ByWebpay/Responses/TransactionCommitResponseTest.php b/tests/Patpass/ByWebpay/Responses/TransactionCommitResponseTest.php deleted file mode 100644 index 74a07d5d..00000000 --- a/tests/Patpass/ByWebpay/Responses/TransactionCommitResponseTest.php +++ /dev/null @@ -1,83 +0,0 @@ - 'testVci', - 'amount' => 100, - 'status' => 'testStatus', - 'buy_order' => 'testBuyOrder', - 'session_id' => 'testSessionId', - 'card_detail' => 'testCardDetail', - 'accounting_date' => 'testAccountingDate', - 'transaction_date' => 'testTransactionDate', - 'authorization_code' => 'testAuthorizationCode', - 'payment_type_code' => 'testPaymentTypeCode', - 'installments_number' => 3 - ]; - - $this->commitResponse = new TransactionCommitResponse($json); - } - public function testSetAndGetVci() - { - $this->assertSame('testVci', $this->commitResponse->getVci()); - } - - public function testSetAndGetAmount() - { - $this->assertSame(100, $this->commitResponse->getAmount()); - } - - public function testSetAndGetStatus() - { - $this->assertSame('testStatus', $this->commitResponse->getStatus()); - } - - public function testSetAndGetBuyOrder() - { - $this->assertSame('testBuyOrder', $this->commitResponse->getBuyOrder()); - } - - public function testSetAndGetSessionId() - { - $this->assertSame('testSessionId', $this->commitResponse->getSessionId()); - } - - public function testSetAndGetCardDetail() - { - $this->assertSame('testCardDetail', $this->commitResponse->getCardDetail()); - } - - public function testSetAndGetAccountingDate() - { - $this->assertSame('testAccountingDate', $this->commitResponse->getAccountingDate()); - } - - public function testSetAndGetTransactionDate() - { - $this->assertSame('testTransactionDate', $this->commitResponse->getTransactionDate()); - } - - public function testSetAndGetAuthorizationCode() - { - $this->assertSame('testAuthorizationCode', $this->commitResponse->getAuthorizationCode()); - } - - public function testSetAndGetPaymentTypeCode() - { - $this->assertSame('testPaymentTypeCode', $this->commitResponse->getPaymentTypeCode()); - } - - public function testSetAndGetInstallmentsNumber() - { - $this->assertSame(3, $this->commitResponse->getInstallmentsNumber()); - } -} diff --git a/tests/Patpass/ByWebpay/Responses/TransactionCreateResponseTest.php b/tests/Patpass/ByWebpay/Responses/TransactionCreateResponseTest.php deleted file mode 100644 index 096ace97..00000000 --- a/tests/Patpass/ByWebpay/Responses/TransactionCreateResponseTest.php +++ /dev/null @@ -1,34 +0,0 @@ - 'testToken', - 'url' => 'testUrl' - ]; - - $response = new TransactionCreateResponse($json); - - $this->assertSame('testToken', $response->getToken()); - $this->assertSame('testUrl', $response->getUrl()); - } - - /** @test */ - public function it_returns_null_when_key_does_not_exist_in_json() - { - $json = [ - 'token' => 'testToken' - ]; - - $response = new TransactionCreateResponse($json); - - $this->assertSame('testToken', $response->getToken()); - $this->assertNull($response->getUrl()); - } -} diff --git a/tests/Patpass/PatpassByWebpayTest.php b/tests/Patpass/PatpassByWebpayTest.php deleted file mode 100644 index ec164b95..00000000 --- a/tests/Patpass/PatpassByWebpayTest.php +++ /dev/null @@ -1,29 +0,0 @@ -assertSame(PatpassByWebpay::DEFAULT_COMMERCE_CODE, $options->getCommerceCode()); - $this->assertSame(PatpassByWebpay::DEFAULT_API_KEY, $options->getApiKey()); - $this->assertSame(Options::ENVIRONMENT_INTEGRATION, $options->getIntegrationType()); - } - - /** @test */ - public function it_returns_default_options() - { - $options = PatpassByWebpay::getDefaultOptions(); - - $this->assertSame(PatpassByWebpay::DEFAULT_COMMERCE_CODE, $options->getCommerceCode()); - $this->assertSame(PatpassByWebpay::DEFAULT_API_KEY, $options->getApiKey()); - $this->assertSame(Options::ENVIRONMENT_INTEGRATION, $options->getIntegrationType()); - } -} From e39fbfa9db4ec47b306fdce980560c79c68760bc Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 5 Jun 2024 10:42:07 -0400 Subject: [PATCH 4/4] test: remove webpay modal --- .../Webpay/Modal/TransbankWebpayModalTest.php | 69 ------------------- 1 file changed, 69 deletions(-) delete mode 100644 tests/Webpay/Modal/TransbankWebpayModalTest.php diff --git a/tests/Webpay/Modal/TransbankWebpayModalTest.php b/tests/Webpay/Modal/TransbankWebpayModalTest.php deleted file mode 100644 index 480311a7..00000000 --- a/tests/Webpay/Modal/TransbankWebpayModalTest.php +++ /dev/null @@ -1,69 +0,0 @@ -create(1500, 'BuyOrder1', 'Session2312'); - $this->assertInstanceOf(\Transbank\Webpay\Modal\Responses\TransactionCreateResponse::class, $response); - $this->assertNotEmpty($response->getToken()); - } - - /** @test */ - public function it_creates_a_modal_transaction_without_givin_a_session_id() - { - $response = (new Transaction())->create(1500, 'BuyOrder1'); - $this->assertInstanceOf(\Transbank\Webpay\Modal\Responses\TransactionCreateResponse::class, $response); - $this->assertNotEmpty($response->getToken()); - } - - /** @test */ - public function it_fails_when_creates_a_modal_transaction_with_invalid_data() - { - $this->expectException(TransactionCreateException::class); - (new Transaction())->create('hola', ''); - } - - /** @test */ - public function it_get_the_status_of_a_transction() - { - $response = (new Transaction())->create(1500, 'BuyOrder1', 'Session2312'); - $status = Transaction::build()->status($response->getToken()); - $this->assertInstanceOf(TransactionStatusResponse::class, $status); - $this->assertEquals('INITIALIZED', $status->getStatus()); - } - - /** @test */ - public function it_fails_when_using_invalid_credentials() - { - $this->expectException(TransactionCreateException::class, 'Not Authorized'); - $transaction = new Transaction(Options::forIntegration('commerceCode', 'fakeApiKey')); - $transaction->create(1500, 'BuyOrder1', 'Session2312'); - } - - /** @test */ - public function it_cannot_commit_a_recently_created_transaction() - { - WebpayModal::configureForTesting(); - $this->expectException(TransactionCommitException::class, "Invalid status '0' for transaction while authorizing"); - $response = (new Transaction())->create(1500, 'BuyOrder1', 'Session2312'); - $response = Transaction::build()->commit($response->getToken()); - } - - /** @test */ - public function it_cannot_refund_a_recently_created_transaction() - { - $this->expectException(TransactionRefundException::class, 'Transaction is unfinished, it is not possible to refund it yet'); - $response = (new Transaction())->create(1500, 'BuyOrder1', 'Session2312'); - $response = Transaction::build()->refund($response->getToken(), 1500); - } -}