Skip to content

Commit

Permalink
Merge branch 'develop' into snyk-fix-5470f06dc2625318a6336f0d8d8da253
Browse files Browse the repository at this point in the history
  • Loading branch information
mastudillot authored Dec 16, 2024
2 parents 753159b + 09659b1 commit 0782434
Show file tree
Hide file tree
Showing 35 changed files with 1,195 additions and 469 deletions.
3 changes: 1 addition & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
export { default as IntegrationCommerceCodes } from './transbank/common/integration_commerce_codes';
4 changes: 3 additions & 1 deletion lib/transbank/common/base_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class BaseTransaction {
* @param options You can pass options to use a custom configuration.
*/
constructor(options: Options) {
if (options === null)
throw new Error("Options can't be null.");
this.options = options;
}

}

export default BaseTransaction;
export default BaseTransaction;
5 changes: 3 additions & 2 deletions lib/transbank/common/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Options {
* Production, each has a unique URL. */
environment: string;
/** Timeout for requests in milliseconds */
timeout: number;
timeout?: number;

/**
* Create an instance of Options
Expand All @@ -23,10 +23,11 @@ class Options {
* @param timeout Timeout for requests in milliseconds
*/
constructor(commerceCode: string, apiKey: string, environment: string, timeout?: number) {
const defaultTimeout = 1000 * 60 * 10;
this.commerceCode = commerceCode;
this.apiKey = apiKey;
this.environment = environment;
this.timeout = timeout ?? 60000;
this.timeout = timeout ?? defaultTimeout;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/transbank/common/request_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const RequestService = {
method: request.method,
url: options.environment + request.endpoint,
headers: requestHeaders,
timeout: 10000,
timeout: options.timeout,
data: request.toJson(),
})
.then((response) => {
Expand Down
44 changes: 0 additions & 44 deletions lib/transbank/patpass/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import Options from '../common/options';
import Environment from './common/environment';
import _Inscription from './inscription';
import IntegrationApiKeys from '../common/integration_api_keys';
import IntegrationCommerceCodes from '../common/integration_commerce_codes';

module PatpassComercio {

Expand All @@ -11,46 +7,6 @@ module PatpassComercio {
*/
export const Inscription: typeof _Inscription = _Inscription;

/**
* 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 PatpassComercio.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) => {
PatpassComercio.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) => {
PatpassComercio.options = new Options(_commerceCode, _apiKey, Environment.Integration);
};

/**
* This method configures the module to use Patpass Comercio in the Integration environment.
*/
export const configureForTesting = () => {
PatpassComercio.options = new Options(IntegrationCommerceCodes.PATPASS_COMERCIO, IntegrationApiKeys.PATPASS_COMERCIO, Environment.Integration);
};


}

export default PatpassComercio;
30 changes: 25 additions & 5 deletions lib/transbank/patpass/inscription.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
import BaseTransaction from '../common/base_transaction';
import Options from '../common/options';
import PatpassComercio from '.';
import { StatusRequest, StartRequest } from './requests';
import RequestService from '../common/request_service';
import IntegrationCommerceCodes from '../common/integration_commerce_codes';
import IntegrationApiKeys from '../common/integration_api_keys';
import Environment from './common/environment';

class Inscription extends BaseTransaction {

/**
* Constructor class Inscription PatpassComercio.
* @param options (Optional) You can pass options to use a custom configuration.
* @param options You can pass options to use a custom configuration.
*/
constructor(options: Options) {
options = options || PatpassComercio.getDefaultOptions() || new Options(IntegrationCommerceCodes.PATPASS_COMERCIO, IntegrationApiKeys.PATPASS_COMERCIO, Environment.Integration);
super(options);
}

/**
* Creates and returns an instance of `Inscription` configured for the integration environment.
*
* @param commerceCode The commerce code.
* @param apiKey The API key used for authentication.
* @return A new instance of `Inscription` configured for the test environment (Environment.Integration).
*/
static buildForIntegration(commerceCode: string, apiKey: string): Inscription
{
return new Inscription(new Options(commerceCode, apiKey, Environment.Integration));
}

/**
* Creates and returns an instance of `Inscription` configured for the production environment.
*
* @param commerceCode The commerce code.
* @param apiKey The API key used for authentication.
* @return A new instance of `Inscription` configured for the production environment (Environment.Production).
*/
static buildForProduction(commerceCode: string, apiKey: string): Inscription
{
return new Inscription(new Options(commerceCode, apiKey, Environment.Production));
}

/**
* Starts a card inscription process
* @param url URL to which Transbank will redirect after cardholder finish enrolling their card
Expand Down
55 changes: 0 additions & 55 deletions lib/transbank/webpay/modal/index.ts

This file was deleted.

5 changes: 0 additions & 5 deletions lib/transbank/webpay/modal/requests/index.ts

This file was deleted.

26 changes: 0 additions & 26 deletions lib/transbank/webpay/modal/requests/modal_create_request.ts

This file was deleted.

77 changes: 0 additions & 77 deletions lib/transbank/webpay/modal/transaction.ts

This file was deleted.

49 changes: 0 additions & 49 deletions lib/transbank/webpay/oneclick/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import Options from '../../common/options';
import Environment from '../common/environment';
import _MallInscription from './mall_inscription';
import _MallTransaction from './mall_transaction';
import IntegrationApiKeys from '../../common/integration_api_keys';
import IntegrationCommerceCodes from '../../common/integration_commerce_codes';

module Oneclick {

Expand All @@ -16,51 +12,6 @@ module Oneclick {
*/
export const MallTransaction: typeof _MallTransaction = _MallTransaction;

/**
* 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 Oneclick.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) => {
Oneclick.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) => {
Oneclick.options = new Options(_commerceCode, _apiKey, Environment.Integration);
};

/**
* This method configures the module to use Oneclick Mall in the Integration environment.
*/
export const configureOneclickMallForTesting = () => {
Oneclick.options = new Options(IntegrationCommerceCodes.ONECLICK_MALL, IntegrationApiKeys.WEBPAY, Environment.Integration);
};

/**
* This method configures the module to use Oneclick Mall deferred in the Integration environment.
*/
export const configureOneclickMallDeferredForTesting = () => {
Oneclick.options = new Options(IntegrationCommerceCodes.ONECLICK_MALL_DEFERRED, IntegrationApiKeys.WEBPAY, Environment.Integration);
};
}

export default Oneclick;
Loading

0 comments on commit 0782434

Please sign in to comment.