skailan-core
Version:
Servicio de autenticación y multitenancy para Skailan.
75 lines • 2.72 kB
JavaScript
import Joi from 'joi';
export class EPaycoConfigService {
static instance;
config;
constructor() {
this.config = this.loadConfig();
this.validateConfig();
}
static getInstance() {
if (!EPaycoConfigService.instance) {
EPaycoConfigService.instance = new EPaycoConfigService();
}
return EPaycoConfigService.instance;
}
loadConfig() {
const environment = (process.env.NODE_ENV === 'production' ? 'production' : 'sandbox');
return {
publicKey: process.env.EPAYCO_PUBLIC_KEY || '',
privateKey: process.env.EPAYCO_PRIVATE_KEY || '',
pKey: process.env.EPAYCO_P_KEY || '',
baseUrl: process.env.EPAYCO_BASE_URL ||
(environment === 'production'
? 'https://checkout.epayco.co/checkout.php'
: 'https://sandbox.epayco.co/checkout.php'),
confirmationUrl: process.env.EPAYCO_CONFIRMATION_URL || '',
responseUrl: process.env.EPAYCO_RESPONSE_URL || '',
environment,
currency: process.env.EPAYCO_CURRENCY || 'COP',
country: process.env.EPAYCO_COUNTRY || 'CO',
language: process.env.EPAYCO_LANGUAGE || 'es',
taxRate: parseFloat(process.env.EPAYCO_TAX_RATE || '0'),
};
}
validateConfig() {
const schema = Joi.object({
publicKey: Joi.string().required(),
privateKey: Joi.string().required(),
pKey: Joi.string().required(),
baseUrl: Joi.string().uri().required(),
confirmationUrl: Joi.string().uri().required(),
responseUrl: Joi.string().uri().required(),
environment: Joi.string().valid('sandbox', 'production').required(),
currency: Joi.string().length(3).required(),
country: Joi.string().length(2).required(),
language: Joi.string().length(2).required(),
taxRate: Joi.number().min(0).max(100).required(),
});
const { error } = schema.validate(this.config);
if (error) {
throw new Error(`EPayco configuration error: ${error.message}`);
}
}
getConfig() {
return { ...this.config };
}
isProduction() {
return this.config.environment === 'production';
}
isSandbox() {
return this.config.environment === 'sandbox';
}
getBaseUrl() {
return this.config.baseUrl;
}
getPublicKey() {
return this.config.publicKey;
}
getPrivateKey() {
return this.config.privateKey;
}
getPKey() {
return this.config.pKey;
}
}
//# sourceMappingURL=epayco.config.js.map