From d3ef6761072d4204d319f3f818afd878007843f4 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Mon, 19 Aug 2024 12:27:55 -0400 Subject: [PATCH 1/2] feat: improve connection flow --- src/pos.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pos.js b/src/pos.js index 24bf443..499a615 100644 --- a/src/pos.js +++ b/src/pos.js @@ -171,18 +171,23 @@ export class TransbankPOSWebSocket extends EventEmitter { async doSale(amount, ticket, callback = null) { let params = { amount: amount, ticket: ticket } - if (typeof callback === 'function') { + + if (typeof callback === 'function' && this.socket !== null) { this.socket.on('sale_status.response', callback) } + let response = await this.send("sale", params) this.socket.off('sale_status.response', callback) return response; } + async doMulticodeSale(amount, ticket, commerceCode = '0', callback = null) { let params = { amount: amount, ticket: ticket, commerceCode: commerceCode } - if (typeof callback === 'function') { + + if (typeof callback === 'function' && this.socket !== null) { this.socket.on('multicode_sale_status.response', callback) } + let response = await this.send("multicodeSale", params) this.socket.off('multicode_sale_status.response', callback) return response; From de2afa193aab9a7aac09d19781c7b12794132dca Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Mon, 19 Aug 2024 13:18:34 -0400 Subject: [PATCH 2/2] feat: improve validation in sale command when agent is not connected --- src/pos.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pos.js b/src/pos.js index 499a615..a5c9fbb 100644 --- a/src/pos.js +++ b/src/pos.js @@ -79,7 +79,7 @@ export class TransbankPOSWebSocket extends EventEmitter { let ts = Date.now(); let eventName = method + ".response" + ts; - if (!this.isConnected && this.socket!==null) { + if (!this.isConnected || this.socket == null) { reject("Debe conectarse para poder enviar mensajes: Puede conectarse con POS.connect()") return }