From c9fc0f0f90c524bc1aef70ec6806c6e89c5c185d Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Wed, 28 Aug 2024 14:18:22 -0500 Subject: [PATCH] feat: remove webpay modal --- lib/index.ts | 3 +- lib/transbank/webpay/modal/index.ts | 55 ------------- lib/transbank/webpay/modal/requests/index.ts | 5 -- .../modal/requests/modal_create_request.ts | 26 ------- lib/transbank/webpay/modal/transaction.ts | 77 ------------------- 5 files changed, 1 insertion(+), 165 deletions(-) delete mode 100644 lib/transbank/webpay/modal/index.ts delete mode 100644 lib/transbank/webpay/modal/requests/index.ts delete mode 100644 lib/transbank/webpay/modal/requests/modal_create_request.ts delete mode 100644 lib/transbank/webpay/modal/transaction.ts diff --git a/lib/index.ts b/lib/index.ts index 81c97b6..bb00ef1 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,5 +1,4 @@ export { default as WebpayPlus } from './transbank/webpay/webpay_plus'; -export { default as WebpayPlusModal } from './transbank/webpay/modal'; export { default as Oneclick } from './transbank/webpay/oneclick'; export { default as TransaccionCompleta } from './transbank/webpay/transaccion_completa'; export { default as PatpassComercio } from './transbank/patpass'; @@ -9,4 +8,4 @@ export { default as CommitDetail } from './transbank/webpay/transaccion_completa export { default as Options } from './transbank/common/options'; export { default as Environment } from './transbank/webpay/common/environment'; export { default as IntegrationApiKeys } from './transbank/common/integration_api_keys'; -export { default as IntegrationCommerceCodes } from './transbank/common/integration_commerce_codes'; \ No newline at end of file +export { default as IntegrationCommerceCodes } from './transbank/common/integration_commerce_codes'; diff --git a/lib/transbank/webpay/modal/index.ts b/lib/transbank/webpay/modal/index.ts deleted file mode 100644 index ba05061..0000000 --- a/lib/transbank/webpay/modal/index.ts +++ /dev/null @@ -1,55 +0,0 @@ -import IntegrationApiKeys from '../../common/integration_api_keys'; -import IntegrationCommerceCodes from '../../common/integration_commerce_codes'; -import Environment from '../common/environment'; -import Options from '../../common/options'; -import _Transaction from './transaction'; - -module WebpayPlusModal { - /** - * Contains methods used to create, commit, refund and capture Transactions. - */ - export const Transaction: typeof _Transaction = _Transaction; - - /** - * Contains currently configured Commerce Code, Api Key and Environment - */ - export let options: Options; - - /** - * @returns currently configured Commerce Code and Api Key - */ - export const getDefaultOptions = () => { - return WebpayPlusModal.options; - }; - - /** - * This methods configures the module to point to the Production Environment with the given params. - * @param _commerceCode Commerce Code given by Transbank when contracting the product - * @param _apiKey Api Key given by Transbank when you sucessfuly validate your integration - */ - export const configureForProduction = (_commerceCode: string, _apiKey: string) => { - WebpayPlusModal.options = new Options(_commerceCode, _apiKey, Environment.Production); - }; - - /** - * This methods configures the module to point to the Integration Environment with the given params. - * You can check use the credentials provided in the official docs. - * https://transbankdevelopers.cl/documentacion/como_empezar#codigos-de-comercio - * @param _commerceCode Commerce Code given by Transbank. - * @param _apiKey Api Key given by Transbank. - */ - export const configureForIntegration = (_commerceCode: string, _apiKey: string) => { - WebpayPlusModal.options = new Options(_commerceCode, _apiKey, Environment.Integration); - }; - - /** - * This method configures the module to use Webpay Plus in the Integration environment. - */ - export const configureWebpayPlusForTesting = () => { - WebpayPlusModal.options = new Options(IntegrationCommerceCodes.WEBPAY_PLUS_MODAL, IntegrationApiKeys.WEBPAY, Environment.Integration); - }; - - -} - -export default WebpayPlusModal; \ No newline at end of file diff --git a/lib/transbank/webpay/modal/requests/index.ts b/lib/transbank/webpay/modal/requests/index.ts deleted file mode 100644 index a112cdc..0000000 --- a/lib/transbank/webpay/modal/requests/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ModalCreateRequest } from './modal_create_request'; - -export { - ModalCreateRequest -}; diff --git a/lib/transbank/webpay/modal/requests/modal_create_request.ts b/lib/transbank/webpay/modal/requests/modal_create_request.ts deleted file mode 100644 index 2375566..0000000 --- a/lib/transbank/webpay/modal/requests/modal_create_request.ts +++ /dev/null @@ -1,26 +0,0 @@ -import ApiConstants from '../../../common/api_constants'; -import RequestBase from '../../../common/request_base'; - -class ModalCreateRequest extends RequestBase { - buyOrder: string; - sessionId: string; - amount: number; - - constructor(buyOrder: string, sessionId: string, amount: number) { - super(`${ApiConstants.WEBPAY_ENDPOINT}/transactions`, 'POST'); - - this.buyOrder = buyOrder; - this.sessionId = sessionId; - this.amount = amount; - } - - toJson(): string { - return JSON.stringify({ - buy_order: this.buyOrder, - session_id: this.sessionId, - amount: this.amount, - }); - } -} - -export { ModalCreateRequest }; diff --git a/lib/transbank/webpay/modal/transaction.ts b/lib/transbank/webpay/modal/transaction.ts deleted file mode 100644 index af77cbb..0000000 --- a/lib/transbank/webpay/modal/transaction.ts +++ /dev/null @@ -1,77 +0,0 @@ -import Options from '../../common/options'; -import BaseTransaction from '../../common/base_transaction'; -import WebpayPlusModal from './'; -import { ModalCreateRequest } from './requests'; -import RequestService from '../../common/request_service'; -import { CommitRequest, RefundRequest, StatusRequest } from '../webpay_plus/requests'; -import ValidationUtil from '../../common/validation_util'; -import ApiConstants from '../../common/api_constants'; -import IntegrationCommerceCodes from '../../common/integration_commerce_codes'; -import IntegrationApiKeys from '../../common/integration_api_keys'; -import Environment from '../common/environment'; - -/** - * Contains methods to interact with WebpayPlus API - */ -class Transaction extends BaseTransaction { - - /** - * Constructor class Webpay Plus Modal transaction. - * @param options (Optional) You can pass options to use a custom configuration. - */ - constructor(options: Options) { - options = options || WebpayPlusModal.getDefaultOptions() || new Options(IntegrationCommerceCodes.WEBPAY_PLUS_MODAL, IntegrationApiKeys.WEBPAY, Environment.Integration); - super(options); - } - - /** - * Create a Webpay Plus transaction. - * @param buyOrder Commerce buy order, make sure this is unique. - * @param sessionId You can use this field to pass session data if needed. - * @param amount Transaction amount - */ - async create( - buyOrder: string, - sessionId: string, - amount: number - ){ - ValidationUtil.hasTextWithMaxLength(buyOrder, ApiConstants.BUY_ORDER_LENGTH, "buyOrder"); - ValidationUtil.hasTextWithMaxLength(sessionId, ApiConstants.SESSION_ID_LENGTH, "sessionId"); - let createRequest = new ModalCreateRequest(buyOrder, sessionId, amount); - return RequestService.perform(createRequest, this.options); - } - - /** - * Commit a transaction, this should be invoked after the card holder pays - * @param token Unique transaction identifier - */ - async commit(token: string){ - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); - return RequestService.perform(new CommitRequest(token), this.options); - } - /** - * Obtain the status of a specific transaction - * @param token Unique transaction identifier - */ - async status(token: string){ - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); - return RequestService.perform(new StatusRequest(token), this.options); - } - - /** - * Request a refund of a specific transaction, if you refund for the full amount and you're within - * the time window the transaction will be reversed. If you're past that window or refund for less - * than the total amount the transaction will be void. - * @param token Unique transaction identifier - * @param amount Amount to be refunded - */ - async refund( - token: string, - amount: number - ){ - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); - return RequestService.perform(new RefundRequest(token, amount), this.options); - } -} - -export default Transaction;