UNPKG

api-beep-onboarding

Version:

Oracle OCI FaaS for Api Beep Onboarding library

730 lines (646 loc) 52.9 kB
/** * * BeePay 2.023-2.024 - Oracle OCI FaaS for Api Beep Onboarding * Database operations * * Changes: * jlugo: 2024-apr-26. File creation. * Separate database operations from the database layer * jlugo: 2024-may-06. Add getContractAsync and setStatusAsync methods * jacosta: 2025-feb-25. Add the POS Classifiers to the Device. */ /* RGVzYXJyb2xsYWRvIHBvciBKb25hdGhhbiBMdWdv */ import process from "node:process"; import oracledb from "oracledb"; import SoapOps from "./soap-ops.js"; import { ADWError, ADWConnection } from "./oci-adw.js"; import { env } from "./utils.js"; /** * Database onboarding operations */ export class DatabaseOps { m_conn; m_debug; /** * * @param {ADWConnection} connection - Injected from main program * @param {Object} debug - Node.js console object */ constructor(connection, debug) { this.m_conn = connection; this.m_debug = debug; } /** * From LAFISE CRI specifications. Tag from XML <city>Ciudad, Canton</city> * Tag from XML <state>999</state> - ISO Code * @param {String} city - "CIUDAD, CANTON" * @returns {{city: (String|null), canton: (String|null)}} */ #getCityAndCanton(city) { const tmp = city?.split(","); return {city: tmp?.[0]?.trim() ?? null, canton: tmp?.[1]?.trim() ?? null}; } /** * * @param {Array} classifiers - Store|Device classifiers * @param {String} classifier - Classifier key * @returns {String|null} - Classifier value */ #getValueFromClassifier(classifiers, classifier) { /** @param {String} elem.classifier */ const c = classifiers?.find((elem) => elem.classifier === classifier); return c ? c.value : null; } /** * * @param {Array} parameters - Store contract parameters * @param {String} param - Parameter key * @param {String} param.tagValue * @returns {String|null} - Parameter value */ #getValueFromStoreParameters(parameters, param) { const p = parameters?.find((elem) => elem.tagName === param); return p ? p.tagValue : null; } /** * * @param {Array} parameters - Device contract parameters * @param {String} param - Parameter key * @returns {String|null} - Parameter value */ #getValueFromDeviceParameters(parameters, param) { const p = parameters?.find((elem) => elem.code === param); return p ? p.value : null; } /** * * @typedef {Object} Tariff * @property {String} tariffCode * @property {String} dateFrom * @property {String} feeBase * @property {String} feeMin * @property {String} feeMax * @property {String} feePcnt * * @param {Array} tariffs - Device tariffs * @param {String} code - Tariff key * @returns {Tariff} */ #getTariffFromDeviceTariffs(tariffs, code) { const t = tariffs?.find((elem) => elem.tariffCode === code); return t ?? null; } /** * * @param {String} contractType * @returns {String|null} */ #getQuery(contractType) { if (contractType === SoapOps.ContractType.Client){ return "SELECT status_code || ';' || status_description AS status FROM DT_CLIENT WHERE client_number=:p1"; } if (contractType === SoapOps.ContractType.Store){ return "SELECT status_code || ';' || status_description AS status FROM DT_STORE WHERE merchant_id=:p1"; } if (contractType === SoapOps.ContractType.Device){ return "SELECT status_code || ';' || status_description AS status FROM DT_TERMINAL WHERE terminal_id=:p1"; } return null; // Divisions are not stored into the database } /** * * @param {String} status * @returns {String} */ #getStatusDescription(status) { return Object.keys(SoapOps.ContractStatus).find(key => SoapOps.ContractStatus[key] === status) ?? ""; } /** * * @param {String} contractType * @returns {String|null} */ #getProcedure(contractType) { if (contractType === SoapOps.ContractType.Client){ return "PR_ACTUALIZA_DT_CLIENT_STATUS"; } if (contractType === SoapOps.ContractType.Store){ return "PR_ACTUALIZA_DT_STORE_STATUS"; } if (contractType === SoapOps.ContractType.Device){ return "PR_ACTUALIZA_DT_TERMINAL_STATUS"; } // Divisions are not stored into DB return null; } /** * Execute DB store procedure PR_INSERTA_CLIENTE(...) * * @param {Object} client * @param {String} client.clientNumber * @param {Date} client.registrationDate * @param {String} client.registrationType * @param {String} client.registrationNumber * @param {String} client.companyName * @param {String} client.tradeName * @param {String} client.shortName * @param {String} client.salutationSuffix * @param {String} client.firstName * @param {String} client.lastName * @param {Object} client.position * @param {Object} client.contractName * @param {Object} client.comment * @param {Object} client.contract * @param {Object} client.phone * @param {String} client.address.line1 * @param {String} client.address.line2 * @returns {Promise<Object|ADWError>} */ async clientCreateAsync(client) { const start = process.hrtime.bigint(); let result; try { const { city, canton } = this.#getCityAndCanton(client.address.city); const registrationDate = new Date(client.registrationDate); // Convert to js Date object before send to the database result = await this.m_conn?.executeAsync(`BEGIN PR_INSERTA_CLIENTE(:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20, :p21, :p22, :p23, :p24, :p25, :p26); END;`, { p1: { val: client?.clientNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p2: { val: client?.registrationType, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p3: { val: client?.registrationNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p4: { val: client?.companyName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p5: { val: client?.tradeName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p6: { val: client?.shortName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p7: { val: client?.salutationSuffix, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p8: { val: client?.firstName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p9: { val: client?.lastName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p10: { val: client?.address.country, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p11: { val: client?.position ?? null, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p12: { val: registrationDate, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_DATE }, p13: { val: client?.contractName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p14: { val: client?.comment, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p15: { val: client?.contract?.productCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p16: { val: registrationDate, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_DATE }, p17: { val: client?.phone, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p18: { val: client?.address?.line1, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p19: { val: client?.address?.line2, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p20: { val: client?.address.country, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p21: { val: city, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p22: { val: client?.address?.zipCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p23: { val: client?.address?.email, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p24: { val: env.bank_code, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p25: { val: client?.address?.state, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p26: { val: canton, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR } }); } catch (ex) { result = new ADWError("DBO02", ex.message); this.m_debug?.log(`APIOB-DBO02. ${ex.message}`); } const end = process.hrtime.bigint(); this.m_debug?.log(`DB exec PR_INSERTA_CLIENTE(${client.clientNumber ?? ""}). ${(end - start) / 1000000n}ms`); return result; } /** * Execute DB store procedure PR_ACTUALIZA_CLIENTE(...) * * @param {Object} client * @returns {Promise<Object|ADWError>} */ async clientEditAsync(client) { const start = process.hrtime.bigint(); let result; try { const { city, canton } = this.#getCityAndCanton(client.address.city); result = await this.m_conn?.executeAsync(`BEGIN PR_ACTUALIZA_DT_CLIENT(:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20, :p21, :p22); END;`, { p1: { val: client?.clientNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p2: { val: client?.registrationType, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p3: { val: client?.registrationNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p4: { val: client?.companyName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p5: { val: client?.tradeName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p6: { val: client?.shortName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p7: { val: client?.salutationSuffix, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p8: { val: client?.firstName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p9: { val: client?.lastName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p10: { val: client?.address.country, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p11: { val: client?.position ?? null, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p12: { val: client?.contractName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p13: { val: client?.comment, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p14: { val: client?.phone, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p15: { val: client?.address?.line1, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p16: { val: client?.address?.line2, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p17: { val: client?.address.country, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p18: { val: city, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p19: { val: client?.address?.zipCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p20: { val: client?.address?.email, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p21: { val: client?.address?.state, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p22: { val: canton, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR } }); } catch (ex) { result = new ADWError("DBO03", ex.message); this.m_debug?.log(`APIOB-DBO03. ${ex.message}`); } const end = process.hrtime.bigint(); this.m_debug?.log(`DB exec PR_ACTUALIZA_DT_CLIENT(${client.clientNumber}). ${(end - start) / 1000000n}ms`); return result; } /** * Execute DB store procedure PR_INSERTA_TIENDA_COMERCIO_EXISTENTE(...) * * @param {Object} store * @param {String} store.clientNumber * @param {Date} store.registrationDate * @param {String} store.merchantId * @param {String} store.contractName * @param {String} store.comment * @param {String} store.productCode * @param {String} store.mcc * @param {String} store.merchantAmex * @param {Object} store.address * @param {Array} store.classifiers * @param {Array} store.contractParameters * * @returns {Promise<Object|ADWError>} */ async storeCreateAsync(store) { const start = process.hrtime.bigint(); let result; try { const { city, canton } = this.#getCityAndCanton(store?.address?.city); const enableAmex = this.#getValueFromClassifier(store?.classifiers, "ENABLE_AMEX"); const enableMC = this.#getValueFromClassifier(store?.classifiers, "ENABLE_MC"); const enableVISA = this.#getValueFromClassifier(store?.classifiers, "ENABLE_VISA"); const contactlessPayment = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_CTLS_IND"); const cardHighRisk = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_HIGH_RISK_IND"); const indicatorMC = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_MC_CARD_IND"); const indicatorVISA = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_VISA_CARD_IND"); const indicatorOTHER = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_OTHER_CARD_IND"); const roleTypeCode = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_ROLE_CODE"); const registrationDate = new Date(store.openDate); result = await this.m_conn?.executeAsync(`BEGIN PR_INSERTA_TIENDA_COMERCIO_EXISTENTE(:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20, :p21, :p22, :p23, :p24, :p25, :p26); END;`, { p1: { val: store?.clientNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p2: { val: store?.merchantId, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p3: { val: store?.contractName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p4: { val: store?.merchantId, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p5: { val: store?.comment, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p6: { val: store?.productCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p7: { val: store?.mcc, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p8: { val: registrationDate, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_DATE }, p9: { val: store?.merchantAmex, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p10: { val: store?.address?.country, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p11: { val: city, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p12: { val: store?.address?.state, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p13: { val: canton, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p14: { val: store?.address.zipCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p15: { val: store?.address?.line1, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p16: { val: store?.address?.line2, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p17: { val: enableAmex, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p18: { val: enableMC, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p19: { val: enableVISA, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p20: { val: contactlessPayment, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p21: { val: cardHighRisk, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p22: { val: indicatorMC, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p23: { val: indicatorVISA, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p24: { val: indicatorOTHER, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p25: { val: roleTypeCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p26: { val: null, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR } }); } catch (ex) { result = new ADWError("DBO04", ex.message); this.m_debug?.log(`APIOB-DBO04. ${ex.message}`); } const end = process.hrtime.bigint(); this.m_debug?.log(`DB exec PR_INSERTA_TIENDA_COMERCIO_EXISTENTE(${store?.clientNumber ?? ""}, ${store?.merchantId ?? ""}). ${(end - start) / 1000000n}ms`); return result; } /** * Execute DB store procedure PR_ACTUALIZA_DT_STORE(...) * * @param {Object} store * @returns {Promise<Object|ADWError>} */ async storeEditAsync(store) { const start = process.hrtime.bigint(); let result; try { const { city, canton } = this.#getCityAndCanton(store?.address?.city); const enableAmex = this.#getValueFromClassifier(store?.classifiers, "ENABLE_AMEX"); const enableMC = this.#getValueFromClassifier(store?.classifiers, "ENABLE_MC"); const enableVISA = this.#getValueFromClassifier(store?.classifiers, "ENABLE_VISA"); const contactlessPayment = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_CTLS_IND"); const cardHighRisk = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_HIGH_RISK_IND"); const indicatorMC = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_MC_CARD_IND"); const indicatorVISA = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_VISA_CARD_IND"); const indicatorOTHER = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_OTHER_CARD_IND"); const roleTypeCode = this.#getValueFromStoreParameters(store?.contractParameters, "MWF_ROLE_CODE"); result = await this.m_conn?.executeAsync(`BEGIN PR_ACTUALIZA_DT_STORE(:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20, :p21); END;`, { p1: { val: store?.merchantId, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p2: { val: store?.contractName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p3: { val: store?.comment, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p4: { val: store?.mcc, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p5: { val: store?.address?.country, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p6: { val: city, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p7: { val: store?.address?.state, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p8: { val: canton, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p9: { val: store?.address.zipCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p10: { val: store?.address?.line1, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p11: { val: store?.address?.line2, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p12: { val: enableAmex, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p13: { val: enableMC, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p14: { val: enableVISA, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p15: { val: contactlessPayment, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p16: { val: cardHighRisk, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p17: { val: indicatorMC, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p18: { val: indicatorVISA, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p19: { val: indicatorOTHER, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p20: { val: roleTypeCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p21: { val: null, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR } }); } catch (ex) { result = new ADWError("DBO05", ex.message); this.m_debug?.log(`APIOB-DBO05. ${ex.message}`); } const end = process.hrtime.bigint(); this.m_debug?.log(`DB exec PR_ACTUALIZA_DT_STORE(${store?.merchantId}). ${(end - start) / 1000000n}ms`); return result; } /** * Execute DB store procedure PR_INSERTA_TERMINALES_COMERCIO_EXISTENTE(...) * * @param {Object} device * @param {String} device.registrationDate * @param {String} device.dateFrom * @param {String} device.clientNumber * @param {String} device.merchantId * @param {String} device.terminalId * @param {String} device.contractName * @param {String} device.comment * @param {String} device.productCode * @param {String} device.deviceType * @param {String} device.location * @param {String} device.transactionClass * @param {String} device.defaultCurrency * @param {String} device.timeOffset * @param {String} device.terminalActive * @param {String} device.requiredPresentCard * @param {Array} device.contractParameters * @param {Array} device.classifiers * @param {Array} device.deviceParameters * @param {Array} device.tariffs * @returns {Promise<Object|null>} */ async deviceCreateAsync(device) { const start = process.hrtime.bigint(); let result; try { const localAccountNumber = this.#getValueFromDeviceParameters(device?.contractParameters, "TGT_NUM_LOCAL"); const usdAccountNumber = this.#getValueFromDeviceParameters(device?.contractParameters, "TGT_NUM_USD"); const feeTPlan = this.#getValueFromDeviceParameters(device?.contractParameters, "FEE_T_PLAN"); const riskTPlan = this.#getValueFromDeviceParameters(device?.contractParameters, "RISK_T_PLAN"); const merchPaymentPeriod = this.#getValueFromClassifier(device?.classifiers, "MERCH_PAYM_PERIOD"); const tariffLocal = this.#getTariffFromDeviceTariffs(device?.tariffs, "IRO_ISV_S_LOCAL"); const tariffUSD = this.#getTariffFromDeviceTariffs(device?.tariffs, "IRO_ISV_S_USD"); const affiliationType = this.#getValueFromClassifier(device?.classifiers, "AFFILIATION_TYPE"); const tdsUrl = this.#getValueFromDeviceParameters(device?.deviceParameters, "TDS_URL"); const cardAuth = this.#getValueFromDeviceParameters(device?.deviceParameters, "EGW_CARDAUTH"); const tariffDateLocal = new Date(tariffLocal?.dateFrom); const tariffDateUSD = new Date(tariffUSD?.dateFrom); const registrationDate = new Date(device.registrationDate); const posModel = this.#getValueFromClassifier(device?.classifiers, "POS_MODEL"); const posWireless = this.#getValueFromClassifier(device?.classifiers, "POS_WIRELESS"); const posOpenKeyword = this.#getValueFromClassifier(device?.classifiers, "POS_OPEN_KEYWORD"); result = await this.m_conn?.executeAsync(`BEGIN PR_INSERTA_TERMINALES_COMERCIO_EXISTENTE(:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20, :p21, :p22, :p23, :p24, :p25, :p26, :p27, :p28, :p29, :p30, :p31, :p32, :p33, :p34, :p35, :p36, :p37); END;`, { p1: { val: device?.clientNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p2: { val: device?.merchantId, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p3: { val: device?.terminalId, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p4: { val: device?.contractName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p5: { val: device?.comment, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p6: { val: device?.productCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p7: { val: device?.deviceType, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p8: { val: device?.location, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p9: { val: device?.transactionClass, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p10: { val: device?.defaultCurrency, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p11: { val: device?.timeOffset, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p12: { val: device?.terminalActive, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p13: { val: device?.requiredPresentCard, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p14: { val: registrationDate, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_DATE }, p15: { val: localAccountNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p16: { val: usdAccountNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p17: { val: feeTPlan, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p18: { val: riskTPlan, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p19: { val: merchPaymentPeriod, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p20: { val: tariffLocal?.tariffCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p21: { val: tariffDateLocal, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_DATE }, p22: { val: tariffLocal?.feeBase, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p23: { val: tariffLocal?.feeMin, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p24: { val: tariffLocal?.feeMax, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p25: { val: tariffLocal?.feePcnt, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p26: { val: tariffUSD?.tariffCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p27: { val: tariffDateUSD, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_DATE }, p28: { val: tariffUSD?.feeBase, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p29: { val: tariffUSD?.feeMin, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p30: { val: tariffUSD?.feeMax, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p31: { val: tariffUSD?.feePcnt, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p32: { val: affiliationType, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p33: { val: tdsUrl, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p34: { val: cardAuth, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p35: { val: posModel, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p36: { val: posWireless, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p37: { val: posOpenKeyword, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR } }); } catch (ex) { result = new ADWError("DBO06", ex.message); this.m_debug?.log(`APIOB-DBO06. ${ex.message}`); } const end = process.hrtime.bigint(); this.m_debug?.log(`DB exec PR_INSERTA_TERMINALES_COMERCIO_EXISTENTE(${device?.clientNumber ?? ""}, ${device?.merchantId ?? ""}, ${device?.terminalId ?? ""}). ${(end - start) / 1000000n}ms`); return result; } /** * Execute DB store procedure PR_ACTUALIZA_DT_TERMINAL(...) * * @param {Object} device * @param {String} device.terminalId * @param {String} device.contractName * @param {String} device.comment * @param {String} device.productCode * @param {String} device.deviceType * @param {String} device.location * @param {String} device.transactionClass * @param {String} device.defaultCurrency * @param {String} device.timeOffset * @param {String} device.terminalActive * @param {String} device.requiredPresentCard * @param {Array} device.contractParameters * @param {Array} device.classifiers * @param {Array} device.deviceParameters * @param {Array} device.tariffs * @returns {Promise<Object|null>} */ async deviceEditAsync(device) { const start = process.hrtime.bigint(); let result; try { const localAccountNumber = this.#getValueFromDeviceParameters(device?.contractParameters, "TGT_NUM_LOCAL"); const usdAccountNumber = this.#getValueFromDeviceParameters(device?.contractParameters, "TGT_NUM_USD"); const feeTPlan = this.#getValueFromDeviceParameters(device?.contractParameters, "FEE_T_PLAN"); const riskTPlan = this.#getValueFromDeviceParameters(device?.contractParameters, "RISK_T_PLAN"); const merchPaymPeriod = this.#getValueFromClassifier(device?.classifiers, "MERCH_PAYM_PERIOD"); const tariffLocal = this.#getTariffFromDeviceTariffs(device?.tariffs, "IRO_ISV_S_LOCAL"); const tariffUSD = this.#getTariffFromDeviceTariffs(device?.tariffs, "IRO_ISV_S_USD"); const affiliationType = this.#getValueFromClassifier(device?.classifiers, "AFFILIATION_TYPE"); const tdsUrl = this.#getValueFromDeviceParameters(device?.deviceParameters, "TDS_URL"); const cardAuth = this.#getValueFromDeviceParameters(device?.deviceParameters, "EGW_CARDAUTH"); const tariffDateLocal = new Date(tariffLocal?.dateFrom); const tariffDateUSD = new Date(tariffUSD?.dateFrom); const posModel = this.#getValueFromClassifier(device?.classifiers, "POS_MODEL"); const posWireless = this.#getValueFromClassifier(device?.classifiers, "POS_WIRELESS"); const posOpenKeyword = this.#getValueFromClassifier(device?.classifiers, "POS_OPEN_KEYWORD"); result = await this.m_conn?.executeAsync(`BEGIN PR_ACTUALIZA_DT_TERMINAL(:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20, :p21, :p22, :p23, :p24, :p25, :p26, :p27, :p28, :p29, :p30, :p31, :p32, :p33); END;`, { p1: { val: device?.terminalId, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p2: { val: device?.contractName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p3: { val: device?.comment, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p4: { val: device?.deviceType, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p5: { val: device?.location, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p6: { val: device?.transactionClass, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p7: { val: device?.defaultCurrency, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p8: { val: device?.timeOffset, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p9: { val: device?.terminalActive, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p10: { val: device?.requiredPresentCard, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p11: { val: localAccountNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p12: { val: usdAccountNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p13: { val: feeTPlan, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p14: { val: riskTPlan, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p15: { val: merchPaymPeriod, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p16: { val: tariffLocal?.tariffCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p17: { val: tariffDateLocal, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_DATE }, p18: { val: tariffLocal?.feeBase, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p19: { val: tariffLocal?.feeMin, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p20: { val: tariffLocal?.feeMax, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p21: { val: tariffLocal?.feePcnt, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p22: { val: tariffUSD?.tariffCode, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p23: { val: tariffDateUSD, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_DATE }, p24: { val: tariffUSD?.feeBase, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p25: { val: tariffUSD?.feeMin, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p26: { val: tariffUSD?.feeMax, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p27: { val: tariffUSD?.feePcnt, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p28: { val: affiliationType, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p29: { val: tdsUrl, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p30: { val: cardAuth, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p31: { val: posModel, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p32: { val: posWireless, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p33: { val: posOpenKeyword, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR } }); } catch (ex) { result = new ADWError("DBO07", ex.message); this.m_debug?.log(`APIOB-DBO07. ${ex.message}`); } const end = process.hrtime.bigint(); this.m_debug?.log(`DB exec PR_ACTUALIZA_DT_TERMINAL(${device?.terminalId}). ${(end - start) / 1000000n}ms`); return result; } /** * Execute DB store procedure PR_INSERTA_TERMINALES_COMERCIO_EXISTENTE(...) * * @param {String} contractType * @param {String} contractNumber * @param {String} clientNumber - Set when contractType === 'client' * @returns {Promise<Object|String>} */ async getContractAsync(contractType, contractNumber, clientNumber) { const start = process.hrtime.bigint(); const query = this.#getQuery(contractType); const contract = contractType === SoapOps.ContractType.Client ? clientNumber : contractNumber; let result = { accountStatus: "", status: "" }; // Set for divisions try { if (query) { const row = await this.m_conn?.executeAsync(query, [ contract ], { outFormat: oracledb.OUT_FORMAT_OBJECT }); result = row?.rows[0]?.STATUS ? { accountStatus: row?.rows[0]?.STATUS, status: "Contract Complete" } : { accountStatus: "Account doesn't exist", status: "Contract Incomplete" }; } } catch (ex) { result = new ADWError("DBO08", ex.message); this.m_debug?.log(`APIOB-DBO08. ${ex.message}`); } const end = process.hrtime.bigint(); this.m_debug?.log(`DB exec query for ${contractType} contract ${contract}. ${(end - start) / 1000000n}ms`); return result; } /** * Execute DB store procedure PR_INSERTA_TERMINALES_COMERCIO_EXISTENTE(...) * * @param {String} contractType * @param {String} contractNumber * @param {String} clientNumber - Set when contractType === 'client' * @param {String} status * @returns {Promise<Object|null>} */ async setStatusAsync(contractType, contractNumber, clientNumber, status) { const start = process.hrtime.bigint(); const description = this.#getStatusDescription(status); const procedure = this.#getProcedure(contractType); const contract = contractType === SoapOps.ContractType.Client ? clientNumber : contractNumber; let result = null; try { if (procedure) { result = await this.m_conn?.executeAsync(`BEGIN ${procedure}(:p1, :p2, :p3); END;`, { p1: { val: contract, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p2: { val: status, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p3: { val: description, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR } }); } } catch (ex) { result = new ADWError("DBO09", ex.message); this.m_debug?.log(`APIOB-DBO09. ${ex.message}`); } const end = process.hrtime.bigint(); this.m_debug?.log(`DB exec ${procedure}(${contract}). ${(end - start) / 1000000n}ms`); return result; } /** * Generate and validate merchant ID and merchant AMEX against the DB * * @param {String} clientNumber - Client number * @param {String} registrationName - Store registration name * @param {String} merchantId - New merchant ID * @param {String|null} merchantAmex - New merchant AMEX * @returns {Promise<Boolean|ADWError>} */ async validateMerchantAmexAsync(clientNumber, registrationName, merchantId, merchantAmex) { const start = process.hrtime.bigint(); let result; try { let response = await this.m_conn.executeAsync(`BEGIN PR_VALIDA_MERCHANT_AMEX_WS(:p1, :p2, :p3, :p4, :p5, :p6, :p7); END;`, { p1: { val: env.bank_code, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p2: { val: clientNumber, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p3: { val: registrationName, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p4: { val: merchantId, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p5: { val: merchantAmex, dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR }, p6: { val: "Api Beep Onboarding", dir: oracledb.BIND_IN, type: oracledb.DB_TYPE_VARCHAR },