Skip to content

Commit

Permalink
Merge pull request #103 from TransbankDevelopers/feat/remove-default-…
Browse files Browse the repository at this point in the history
…configuration

feat: remove default environment configuration
  • Loading branch information
mvarlic authored Aug 28, 2024
2 parents 1e17a90 + 1377589 commit 4e8618e
Show file tree
Hide file tree
Showing 20 changed files with 1,278 additions and 284 deletions.
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;
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
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;
30 changes: 25 additions & 5 deletions lib/transbank/webpay/oneclick/mall_inscription.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
import BaseTransaction from '../../common/base_transaction';
import Options from '../../common/options';
import Oneclick from '.';
import { DeleteRequest, FinishRequest, StartRequest } from './requests';
import RequestService from '../../common/request_service';
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';

class MallInscription extends BaseTransaction {

/**
* Constructor class MallInscription Oneclick.
* @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 || Oneclick.getDefaultOptions() || new Options(IntegrationCommerceCodes.ONECLICK_MALL, IntegrationApiKeys.WEBPAY, Environment.Integration);
super(options);
}

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

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

/**
* Starts a card inscription process
* @param username Cardholder's username
Expand Down
30 changes: 25 additions & 5 deletions lib/transbank/webpay/oneclick/mall_transaction.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
import Oneclick from '.';
import Options from '../../common/options';
import TransactionDetail from '../common/transaction_detail';
import BaseTransaction from '../../common/base_transaction';
import RequestService from '../../common/request_service';
import { AuthorizeRequest, CaptureRequest, RefundRequest, StatusRequest } from './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';

class MallTransaction extends BaseTransaction {

/**
* Constructor class MallTransaction Oneclick.
* @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 || Oneclick.getDefaultOptions() || new Options(IntegrationCommerceCodes.ONECLICK_MALL, IntegrationApiKeys.WEBPAY, Environment.Integration);
super(options);
}

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

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

/**
* Authorizes a payment to be charde onto the cardholder's card
* @param username Cardholder's username
Expand Down
92 changes: 0 additions & 92 deletions lib/transbank/webpay/transaccion_completa/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 _Transaction from './transaction';
import _MallTransaction from './mall_transaction';
import IntegrationCommerceCodes from '../../common/integration_commerce_codes';
import IntegrationApiKeys from '../../common/integration_api_keys';

module TransaccionCompleta {

Expand All @@ -17,94 +13,6 @@ module TransaccionCompleta {
*/
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 TransaccionCompleta.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) => {
TransaccionCompleta.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) => {
TransaccionCompleta.options = new Options(_commerceCode, _apiKey, Environment.Integration);
};

/**
* This method configures the module to use Transaccion Completa in the Integration environment.
*/
export const configureForTesting = () => {
TransaccionCompleta.options = new Options(IntegrationCommerceCodes.TRANSACCION_COMPLETA, IntegrationApiKeys.WEBPAY, Environment.Integration);
};

/**
* This method configures the module to use Transaccion Completa Deferred in the Integration environment.
*/
export const configureForTestingDeferred = () => {
TransaccionCompleta.options = new Options(IntegrationCommerceCodes.TRANSACCION_COMPLETA_DEFERRED, IntegrationApiKeys.WEBPAY, Environment.Integration);
};

/**
* This method configures the module to use Transaccion Completa Mall in the Integration environment.
*/
export const configureForTestingMall = () => {
TransaccionCompleta.options = new Options(IntegrationCommerceCodes.TRANSACCION_COMPLETA_MALL, IntegrationApiKeys.WEBPAY, Environment.Integration);
};

/**
* This method configures the module to use Transaccion Completa Mall Deferred in the Integration environment.
*/
export const configureForTestingMallDeferred = () => {
TransaccionCompleta.options = new Options(IntegrationCommerceCodes.TRANSACCION_COMPLETA_MALL_DEFERRED, IntegrationApiKeys.WEBPAY, Environment.Integration);
};

/**
* This method configures the module to use Transaccion Completa without CVV in the Integration environment.
*/
export const configureForTestingNoCVV = () => {
TransaccionCompleta.options = new Options(IntegrationCommerceCodes.TRANSACCION_COMPLETA_SIN_CVV, IntegrationApiKeys.WEBPAY, Environment.Integration);
};

/**
* This method configures the module to use Transaccion Completa Deferred without CVV in the Integration environment.
*/
export const configureForTestingDeferredNoCVV = () => {
TransaccionCompleta.options = new Options(IntegrationCommerceCodes.TRANSACCION_COMPLETA_DEFERRED_SIN_CVV, IntegrationApiKeys.WEBPAY, Environment.Integration);
};

/**
* This method configures the module to use Transaccion Completa Mall without CVV in the Integration environment.
*/
export const configureForTestingMallNoCVV = () => {
TransaccionCompleta.options = new Options(IntegrationCommerceCodes.TRANSACCION_COMPLETA_MALL_SIN_CVV, IntegrationApiKeys.WEBPAY, Environment.Integration);
};

/**
* This method configures the module to use Transaccion Completa Mall Deferred without CVV in the Integration environment.
*/
export const configureForTestingMallDeferredNoCVV = () => {
TransaccionCompleta.options = new Options(IntegrationCommerceCodes.TRANSACCION_COMPLETA_MALL_DEFERRED_SIN_CVV, IntegrationApiKeys.WEBPAY, Environment.Integration);
};

}

export default TransaccionCompleta;
Loading

0 comments on commit 4e8618e

Please sign in to comment.