UNPKG

api-beep-onboarding

Version:

Oracle OCI FaaS for Api Beep Onboarding library

340 lines (254 loc) 9.88 kB
/** * * BeePay 2.023-2.024 - Oracle OCI fn-functions for Api Beep Onboarding * Web services operations * * Changes: * jlugo: 2024-apr-26. File creation. * Separate web service operations from soap layer */ /* RGVzYXJyb2xsYWRvIHBvciBKb25hdGhhbiBMdWdv */ import { WSSoapError, WSSoapClient } from "./soap-cli.js"; import { WSClientCreateRequest, WSClientEditRequest, WSDivisionCreateRequest, WSDivisionEditRequest, WSStoreCreateRequest, WSStoreEditRequest, WSStoreConfigRequest, WSDeviceCreateRequest, WSDeviceEditRequest, WSDeviceConfigRequest, WSContractRequest, WSStatusRequest } from "./soap-request.js"; import { WSClientCreateResponse, WSDivisionCreateResponse, WSStoreCreateResponse, WSStoreConfigResponse, WSDeviceCreateResponse, WSDeviceConfigResponse, WSEditResponse, WSContractResponse, WSStatusResponse } from "./soap-response.js"; /** * Web services onboarding operations */ export class SoapOps { m_cli; m_debug; static ClientType = { M_RES: "M_RES" }; static ProductCode = { ACQ_V1_CORP: "ACQ_V1_CORP", ACQ_V1_DIV: "ACQ_V1_DIV", ACQ_V1_STORE: "ACQ_V1_STORE", ACQ_V1_ECOM: "ACQ_V1_ECOM", ACQ_V1_POS: "ACQ_V1_POS" }; static AddressType = { REG_ADDR: "REG_ADDR", OWS_PS: "OWS_PS" }; static DeliveryType = { EMAIL: "EMAIL" }; static DeviceType = { ECOMM_POS: "ECOMM_POS", DEVICE_H2H: "Device H2H", PC: "PC" }; static ContractStatus = { ContractOK: "00", ContractClosed: "14" }; static ContractType = { Client: "client", Division: "division", Store: "store", Device: "device" }; /** * * @param {WSSoapClient} cli - Injected from main program * @param {Object} debug - node.js console object */ constructor(cli, debug) { this.m_cli = cli; this.m_debug = debug; } /** * * @param {Object} client * @returns {Promise<WSClientCreateResponse|WSSoapError>} */ async clientCreateAsync(client) { const start = process.hrtime.bigint(); const req = new WSClientCreateRequest(client); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS create client ${(end - start) / 1000000n}ms`); return res.ok ? new WSClientCreateResponse(res.body) : new WSSoapError(res.body); } /** * * @param {Object} client - From request * @returns {Promise<WSEditResponse|WSSoapError>} */ async clientEditAsync(client) { const start = process.hrtime.bigint(); const req = new WSClientEditRequest(client); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS edit client ${(end - start) / 1000000n}ms`); return res.ok ? new WSEditResponse(res.body) : new WSSoapError(res.body); } /** * * @param {Object} division * @returns {Promise<WSDivisionCreateResponse|WSSoapError>} */ async divisionCreateAsync(division) { const start = process.hrtime.bigint(); const req = new WSDivisionCreateRequest(division); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS create division ${(end - start) / 1000000n}ms`); return res.ok ? new WSDivisionCreateResponse(res.body) : new WSSoapError(res.body); } /** * * @param division * @returns {Promise<WSEditResponse|WSSoapError>} */ async divisionEditAsync(division) { const start = process.hrtime.bigint(); const req = new WSDivisionEditRequest(division); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS edit division ${(end - start) / 1000000n}ms`); return res.ok ? new WSEditResponse(res.body) : new WSSoapError(res.body); } /** * * @param {Object} store * @returns {Promise<WSStoreCreateResponse|WSSoapError>} */ async storeCreateAsync(store) { const start = process.hrtime.bigint(); const req = new WSStoreCreateRequest(store); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS create store ${(end - start) / 1000000n}ms`); return res.ok ? new WSStoreCreateResponse(res.body) : new WSSoapError(res.body); } /** * * @param {Object} store - From request * @param {Boolean} isAmex - Create AMEX parameters? * @returns {Promise<WSEditResponse|WSSoapError|string>} */ async storeEditAsync(store, isAmex) { const start = process.hrtime.bigint(); const req = new WSStoreEditRequest(store, isAmex); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS edit store ${(end - start) / 1000000n}ms`); return res.ok ? new WSEditResponse(res.body) : new WSSoapError(res.body); } /** * * @param {Object} store - Store from request * @param {Boolean} isAmex - Edit AMEX parameters? * @returns {Promise<WSStoreConfigResponse|WSSoapError>} */ async storeConfigAsync(store, isAmex) { const start = process.hrtime.bigint(); const req = new WSStoreConfigRequest(store, isAmex); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS store config ${(end - start) / 1000000n}ms`); return res.ok ? new WSStoreConfigResponse(res.body) : new WSSoapError(res.body); } /** * * @param {Object} device - From request * @returns {Promise<WSDeviceCreateResponse|WSSoapError>} */ async deviceCreateAsync(device) { const start = process.hrtime.bigint(); const req = new WSDeviceCreateRequest(device); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS create device ${(end - start) / 1000000n}ms`); return res.ok ? new WSDeviceCreateResponse(res.body) : new WSSoapError(res.body); } /** * * @param {Object} device - From request * @returns {Promise<WSEditResponse|WSSoapError>} */ async deviceEditAsync(device) { const start = process.hrtime.bigint(); const req = new WSDeviceEditRequest(device); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS edit device ${(end - start) / 1000000n}ms`); return res.ok ? new WSEditResponse(res.body) : new WSSoapError(res.body); } /** * * @param {Object} device - From request * @returns {Promise<WSDeviceConfigResponse|WSSoapError>} */ async deviceConfigAsync(device) { const start = process.hrtime.bigint(); const req = new WSDeviceConfigRequest(device); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS device config ${(end - start) / 1000000n}ms`); return res.ok ? new WSDeviceConfigResponse(res.body) : new WSSoapError(res.body); } /** * * @param {String} contractNumber - Contract number for client or merchantID or terminal ID * @returns {Promise<WSContractResponse|WSSoapError>} */ async getContractAsync(contractNumber) { const start = process.hrtime.bigint(); const req = new WSContractRequest(contractNumber); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS get contract info ${(end - start) / 1000000n}ms`); return res.ok ? new WSContractResponse(res.body) : new WSSoapError(res.body); } /** * * @param {String} contractType - Contract type (client|division|store|terminal) * @param {String} contractNumber - Contract number for a client, merchantID or terminal ID * @param {String} status - Contract new status * @returns {Promise<WSStatusResponse|WSSoapError>} */ async setStatusAsync(contractType, contractNumber, status) { const start = process.hrtime.bigint(); const req = new WSStatusRequest(contractType, contractNumber, status); const xml = req.getRequestBody(); const res = await this.m_cli.callSoapWSAsync(xml); const end = process.hrtime.bigint(); this.m_debug?.log(`Exec WS set contract status ${(end - start) / 1000000n}ms`); return res.ok ? new WSStatusResponse(res.body) : new WSSoapError(res.body); } } export default SoapOps;