Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove default environment configuration #103

Merged
merged 24 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a02df39
feat: add build method for webpay plus transaction
mvarlic Aug 23, 2024
94230ff
feat: add build method for webpay plus mall transaction
mvarlic Aug 23, 2024
b15d4d3
feat: add build method for oneclick mall transaction
mvarlic Aug 23, 2024
ad749a2
feat: add build method for oneclick mall inscription
mvarlic Aug 23, 2024
9f253f8
feat: add build method for full transaction
mvarlic Aug 23, 2024
df90c3a
feat: add build method for mall full transaction
mvarlic Aug 23, 2024
a424623
feat: add build method for patpass
mvarlic Aug 23, 2024
8627b87
feat: remove other initialization methods for webpay plus
mvarlic Aug 23, 2024
cb81866
feat: remove other initialization methods for oneclick
mvarlic Aug 23, 2024
42ce70c
feat: remove other initialization methods for full transaction
mvarlic Aug 23, 2024
dbfed23
feat: add option validation
mvarlic Aug 23, 2024
ec9d63d
chore: add nock library for test
mvarlic Aug 23, 2024
1b37381
test: add oneclick tests
mvarlic Aug 23, 2024
a6db020
test: add oneclick tests
mvarlic Aug 23, 2024
43ac984
test: add full transaction tests
mvarlic Aug 23, 2024
82ffb08
test: add webpay plus tests
mvarlic Aug 23, 2024
5243e82
feat: remove other initialization methods for patpass
mvarlic Aug 26, 2024
b9f7fec
feat: remove default initialization for patpass
mvarlic Aug 26, 2024
3a06df6
test: add patpass tests
mvarlic Aug 26, 2024
a137738
docs: remove optional
mvarlic Aug 26, 2024
d33d03f
refactor: remove unused variable
mvarlic Aug 26, 2024
0cff1ad
tests: remove random
mvarlic Aug 28, 2024
0659a74
tests: update url
mvarlic Aug 28, 2024
1377589
test: update url to https
mvarlic Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading