UNPKG

api-beep-onboarding

Version:

Oracle OCI FaaS for Api Beep Onboarding library

365 lines (291 loc) 9.97 kB
/** * * BeePay 2.023-2.024 - Oracle OCI FaaS for Api Beep Onboarding * Way4 WS runtime SOAP response implementation * * Changes: * jlugo: 2023-dic-01. File creation * jlugo: 2023-jan-16. Update merchant ID and merchant Amex for Store, to use store procedure for database validation * jlugo: 2024-apr-25. Moved to a library */ /* RGVzYXJyb2xsYWRvIHBvciBKb25hdGhhbiBMdWdv */ /** * Base class for SOAP web service response */ class WSResponse { #errors = []; /** * * @param {{ retcode:String, retmsg:String }} node * @returns {boolean} */ addError(node) { if (node.retcode !== "0") { const m = node.retmsg?.split(": ")?.[1] === undefined ? node.retmsg : node.retmsg.split(": ")[1]; this.#errors.push({ apiCode: `APIOB-WSE-${node.retcode}`, apiMessage: `${m}` }); } } /** * @typedef {Object} Contract * @property {string} outobject.merchantcontractdetailsapirecord.institutioncode * @property {string} outobject.merchantcontractdetailsapirecord.client * @property {string} outobject.merchantcontractdetailsapirecord.contractname * @property {string} outobject.merchantcontractdetailsapirecord.contractnumber * @property {string} outobject.merchantcontractdetailsapirecord.parentcontract * @property {string} outobject.merchantcontractdetailsapirecord.contractcategory * @property {string} outobject.merchantcontractdetailsapirecord.opendate * @property {string} outobject.merchantcontractdetailsapirecord.statuscode * @property {string} outobject.merchantcontractdetailsapirecord.currency * @property {string} outobject.merchantcontractdetailsapirecord.productcode * @property {string} outobject.merchantcontractdetailsapirecord.mcc * @property {string} outobject.merchantcontractdetailsapirecord.merchantid * @property {string} outobject.merchantcontractdetailsapirecord.devicetypecode * @param {Contract} body */ setContract(body) { if (body.retcode === "0") { this.institution = body.outobject.merchantcontractdetailsapirecord.institutioncode; this.client = body.outobject.merchantcontractdetailsapirecord.client; this.contractName = body.outobject.merchantcontractdetailsapirecord.contractname; this.contractNumber = body.outobject.merchantcontractdetailsapirecord.contractnumber; this.parentContract = body.outobject.merchantcontractdetailsapirecord.parentcontract; this.contractCategory = body.outobject.merchantcontractdetailsapirecord.contractcategory; this.openDate = body.outobject.merchantcontractdetailsapirecord.opendate; this.accountStatus = body.outobject.merchantcontractdetailsapirecord.statuscode; this.currency = body.outobject.merchantcontractdetailsapirecord.currency; this.productCode = body.outobject.merchantcontractdetailsapirecord.productcode; if (body.outobject.merchantcontractdetailsapirecord.mcc) { this.mcc = body.outobject.merchantcontractdetailsapirecord.mcc; } if (body.outobject.merchantcontractdetailsapirecord.merchantid) { this.merchantId = body.outobject.merchantcontractdetailsapirecord.merchantid; } if (body.outobject.merchantcontractdetailsapirecord.devicetypecode) { this.deviceType = body.outobject.merchantcontractdetailsapirecord.devicetypecode; } return; } this.addError(body); } get Errors() { return this.#errors; } get hasErrors() { return this.#errors.length > 0; } } /** * Common SOAP web service response for address creation */ class WSAddressResponse extends WSResponse { /** * * @param {{ retcode:String, retmsg:String, createdaddress:String }} body */ constructor(body) { super(); if (body.retcode === "0") { this.code = body.createdaddress; return; } super.addError(body); } } /** * Create merchant, acquiring contract, address and contract classifiers response */ export class WSClientCreateResponse extends WSResponse { static CreateMerchantResponseType = 0; static CreateAcquiringContractV2ResponseType = 1; static CreateContractAddressV2 = 2; static SetContractClassifierResponseType = 3 constructor(body) { super(); this.#createMerchant(body[WSClientCreateResponse.CreateMerchantResponseType]); this.#createAcquiringContract(body[WSClientCreateResponse.CreateAcquiringContractV2ResponseType]); this.address = new WSAddressResponse(body[WSClientCreateResponse.CreateContractAddressV2]); // SetContractClassifier: return RetCode and RetMsg. Classifiers is an Array in the request body.slice(WSClientCreateResponse.SetContractClassifierResponseType). forEach((n) => { super.addError(n); }); } /** * * @param {{ retcode: string, retmsg:string, newclient: string }} node */ #createMerchant(node) { if (node.retcode === "0") { this.code = node.newclient; return; } super.addError(node); } /** * * @param {{ retcode: string, retmsg:string, createdcontract: string, contractnumber:string }} node */ #createAcquiringContract(node) { if (node.retcode === "0") { this.contractNumber = node.contractnumber; return; } super.addError(node); } } /** * Create a subcontract response (Level Division) */ export class WSDivisionCreateResponse extends WSResponse { /** * * @param {{ retcode: string, retmsg: string, createdsubcontract: string, contractnumber:string }} body */ constructor(body) { super(); if (body.retcode === "0") { this.code = body.createdsubcontract; this.contractNumber = body.contractnumber; return; } super.addError(body); } } /** * Create a subcontract response (Level Store) */ export class WSStoreCreateResponse extends WSResponse { /** * * @param {{ retcode: string, retmsg: string, createdsubcontract: string, contractnumber:string }} body */ constructor(body) { super(); if (body.retcode === "0") { this.code = body.createdsubcontract; this.merchantId = body.contractnumber; return; } // retCode: 2016 -> retmsg: Appl #0051-2023-12-07-1380-908: Duplicate Contract Number this.duplicateMerchantId = (body.retcode === "2016"); super.addError(body); } } /** * Subcontract configuration response (Level Store) */ export class WSStoreConfigResponse extends WSResponse { static CreateAcquiringContractAddress = 0; static AddContractApplicationInfo = 1; constructor(body) { super(); this.address = new WSAddressResponse(body[WSStoreConfigResponse.CreateAcquiringContractAddress]); // AddContractApplicationInfo: return RetCode and RetMsg. // SetContractClassifier: return RetCode and RetMsg. // SetDeviceParms: return RetCode and RetMsg. // Contract parameters (AppInf) and classifiers are an Array() in the request body.slice(WSStoreConfigResponse.AddContractApplicationInfo). forEach((n) => { super.addError(n); }); } } /** * Create a subcontract response (Level Device) */ export class WSDeviceCreateResponse extends WSResponse { constructor(body) { super(); this.#createDevice(body); } /** * * @param {{ retcode: string, retmsg: string, devicecontractnumber: string, devicenumber: string }} node */ #createDevice(node) { if (node.retcode === "0") { this.contractNumber = node.devicecontractnumber; this.terminalId = node.devicenumber; return; } super.addError(node); } } /** * Device configuration response (Level Device) */ export class WSDeviceConfigResponse extends WSResponse { /** * * @param {Array} body */ constructor(body) { super(); // // SetContractClassifier: return RetCode and RetMsg. // Acquiring contract application custom data and classifiers are an Array() in the request body.forEach((n) => { super.addError(n); }); } } /** * Standard WS edition response */ export class WSEditResponse extends WSResponse { /** * * @param {Array|Object} body */ constructor(body) { super(); if (body instanceof Array) { body.forEach((n) => { super.addError(n); }); return; } if (body.retcode !== "0") { super.addError(body); } } } /** * */ export class WSContractResponse extends WSResponse { /** * * @param {Object} body */ constructor(body) { super(); super.setContract(body); } } /** * Standard WS edition response */ export class WSStatusResponse extends WSResponse { static SetAcquiringContractStatus = 0; static GetAcquiringContract = 1; /** * * @param {Object} body */ constructor(body) { super(); this.#setStatus(body[WSStatusResponse.SetAcquiringContractStatus]); super.setContract(body[WSStatusResponse.GetAcquiringContract]); } /** * * @param {{ retcode: string, retmsg:string, newclient: string }} node */ #setStatus(node) { if (node.retcode === "0") { return; } super.addError(node); } }