From 5739d29466ef0efd12d13d24e3cfca5978221c5e Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Tue, 29 Dec 2020 10:48:27 -0800 Subject: [PATCH] [IMP] pos_pax: implement low level and UI for Debit cards. --- pos_pax/static/src/css/pos_pax.css | 8 +- pos_pax/static/src/js/pax_device.js | 109 +++++++++++++++++++++++++++- pos_pax/static/src/js/pos_pax.js | 68 +++++++++-------- pos_pax/static/src/xml/pos_pax.xml | 5 +- 4 files changed, 154 insertions(+), 36 deletions(-) diff --git a/pos_pax/static/src/css/pos_pax.css b/pos_pax/static/src/css/pos_pax.css index 6b64ca39..cea148c8 100644 --- a/pos_pax/static/src/css/pos_pax.css +++ b/pos_pax/static/src/css/pos_pax.css @@ -6,12 +6,14 @@ box-shadow: 0px 0px 0px 3px rgb(239, 153, 65); } -.pos .paymentline .pax_send_transaction { +.pos .paymentline .pax_send_transaction, +.pos .paymentline .pax_send_transaction_debit { cursor: pointer !important; border: 1px solid rgba(255, 255, 255, 0.5); background-color: rgba(255,255,255, 0.2); - display: block; + display: inline-block; text-align: center; - margin: 6px 0 0 0; + margin: 6px 5px 0 0; padding: 2px 5px; + min-width: 100px; } diff --git a/pos_pax/static/src/js/pax_device.js b/pos_pax/static/src/js/pax_device.js index 14879313..55bf0b03 100644 --- a/pos_pax/static/src/js/pax_device.js +++ b/pos_pax/static/src/js/pax_device.js @@ -7,6 +7,7 @@ odoo.define('pos_pax.pax_device', function (require) { // Additions and Fixes: // 2020-11-12 Fixed variable i and ii in getLRC // 2020-11-12 Fixed/added 'fail' mechanisms for XHR + // 2020-11-23 Added new DoDebit method //HEX TO BASE64 function hexToBase64(str) { @@ -79,7 +80,8 @@ odoo.define('pos_pax.pax_device', function (require) { "Initialize":120*1000, "GetSignature":120*1000, "DoSignature":120*1000, - "DoCredit":120*1000 + "DoCredit":120*1000, + "DoDebit":120*1000, }, //Set ip and port @@ -150,7 +152,7 @@ odoo.define('pos_pax.pax_device', function (require) { var hex = StringToHex(response).slice(0,len).split(/02|1c/); console.log(hex); - if(commandType == "DoCredit"){ + if(commandType == "DoCredit" || commandType == "DoDebit"){ var subHex=[], subPacketInfo=[]; for(var i=0; i"+customData+""); + // } + + + var url = this.mDestinationIP + '?' + final_b64; + console.log("URL: " + url); + + this.HttpCommunication('DoDebit',url,function(response){ + callback(response); + },PAX.timeout.DoDebit,fail); + }, }; return PAX; diff --git a/pos_pax/static/src/js/pos_pax.js b/pos_pax/static/src/js/pos_pax.js index 905c0a2e..a49fbd24 100644 --- a/pos_pax/static/src/js/pos_pax.js +++ b/pos_pax/static/src/js/pos_pax.js @@ -43,11 +43,18 @@ pos_model.PosModel = pos_model.PosModel.extend({ }, decodePAXResponse: function (data) { - console.log(data); - if (data[5] == 'ABORTED') { - console.log('aborted'); + var status = data[5]; + if (status == 'ABORTED') { return {fail: 'Transaction Aborted'}; - } else if (data[5] == 'OK') { + } else if (status == 'DECLINE') { + return {fail: 'Transaction Declined or not Allowed'}; + } else if (status == 'COMM ERROR') { + return {fail: 'Communication Error (e.g. could be your CC processor or internet)'} + } else if (status == 'DEBIT ONLY, TRY ANOTHER TENDER') { + return {fail: 'Card does not support Debit. Use Credit or switch cards.'} + } else if (status == 'RECEIVE ERROR') { + return {fail: 'Error receiving response. Try again?'} + } else if (status == 'OK') { return { success: true, approval: data[6][2], @@ -55,8 +62,12 @@ pos_model.PosModel = pos_model.PosModel.extend({ card_num: '***' + data[9][0], } } - return {fail: 'Unknown Response. ' + data}; - } + var response = 'Not handled response: ' + status; + if (this.debug) { + response += ' --------- Debug Data: ' + data; + } + return {fail: response}; + }, }); var _paylineproto = pos_model.Paymentline.prototype; @@ -69,6 +80,7 @@ pos_model.Paymentline = pos_model.Paymentline.extend({ this.pax_card_number = json.pax_card_number; this.pax_approval = json.pax_approval; this.pax_txn_id = json.pax_txn_id; + this.pax_tender_type = json.pax_tender_type; this.set_credit_card_name(); }, @@ -79,11 +91,12 @@ pos_model.Paymentline = pos_model.Paymentline.extend({ pax_card_number: this.pax_card_number, pax_approval: this.pax_approval, pax_txn_id: this.pax_txn_id, + pax_tender_type: this.pax_tender_type, }); }, set_credit_card_name: function () { if (this.pax_card_number) { - this.name = this.pax_card_number; + this.name = this.pax_card_number + ((this.pax_tender_type == 'debit') ? ' (Debit)' : ' (Credit)'); } } }); @@ -128,7 +141,7 @@ PaymentScreenWidget.include({ }, // Handler to manage the card reader string - pax_credit_transaction: function (old_deferred, retry_nr) { + pax_credit_transaction: function (tender_type) { var order = this.pos.get_order(); if(this.pos.getPAXOnlinePaymentJournals().length === 0) { @@ -152,7 +165,7 @@ PaymentScreenWidget.include({ } transaction = { - command: 'T00', + command: (tender_type == 'debit') ? 'T02' : 'T00', version: '1.28', transactionType: transactionType, amountInformation: { @@ -167,23 +180,16 @@ PaymentScreenWidget.include({ }, } - var def = old_deferred || new $.Deferred(); - retry_nr = retry_nr || 0; - - // show the transaction popup. - // the transaction deferred is used to update transaction status - // if we have a previous deferred it indicates that this is a retry - if (! old_deferred) { - self.gui.show_popup('pax-payment-transaction', { - transaction: def - }); - def.notify({ - message: _t('Handling transaction...'), - }); - } + var def = new $.Deferred(); + self.gui.show_popup('pax-payment-transaction', { + transaction: def + }); + def.notify({ + message: _t('Handling transaction...'), + }); PAX.mDestinationIP = this.pos.config.pax_endpoint; - PAX.DoCredit(transaction, function (response) { + PAX[(tender_type == 'debit') ? 'DoDebit' : 'DoCredit'](transaction, function (response) { console.log(response); var parsed_response = self.pos.decodePAXResponse(response); if (parsed_response.fail) { @@ -196,6 +202,7 @@ PaymentScreenWidget.include({ pending_line.pax_txn_id = parsed_response.txn_id; pending_line.pax_approval = parsed_response.approval; pending_line.pax_txn_pending = false; + pending_line.pax_tender_type = tender_type; pending_line.set_credit_card_name(); self.order_changes(); self.reset_input(); @@ -230,7 +237,7 @@ PaymentScreenWidget.include({ }); transaction = { - command: 'T00', + command: (line.pax_tender_type == 'debit') ? 'T02' : 'T00', version: '1.28', transactionType: (line.get_amount() > 0) ? '17' : '18', // V/SALE, V/RETURN cashierInformation: { @@ -245,7 +252,7 @@ PaymentScreenWidget.include({ } PAX.mDestinationIP = this.pos.config.pax_endpoint; - PAX.DoCredit(transaction, function (response) { + PAX[(line.pax_tender_type == 'debit') ? 'DoDebit' : 'DoCredit'](transaction, function (response) { var parsed_response = self.pos.decodePAXResponse(response); if (parsed_response.fail) { def.resolve({message: parsed_response.fail}) @@ -308,7 +315,7 @@ PaymentScreenWidget.include({ } }, - click_pax_send_transaction: function (id) { + click_pax_send_transaction: function (tender_type) { var pending_txn_line = this._get_pax_txn_pending_line(); if (!pending_txn_line) { this.gui.show_popup('error',{ @@ -317,14 +324,17 @@ PaymentScreenWidget.include({ }); return; } - this.pax_credit_transaction(); + this.pax_credit_transaction(tender_type); }, render_paymentlines: function() { this._super(); var self = this; self.$('.paymentlines-container').on('click', '.pax_send_transaction', function(){ - self.click_pax_send_transaction(); + self.click_pax_send_transaction('credit'); + }); + self.$('.paymentlines-container').on('click', '.pax_send_transaction_debit', function(){ + self.click_pax_send_transaction('debit'); }); }, diff --git a/pos_pax/static/src/xml/pos_pax.xml b/pos_pax/static/src/xml/pos_pax.xml index 3126f3b5..d6aa2f2d 100644 --- a/pos_pax/static/src/xml/pos_pax.xml +++ b/pos_pax/static/src/xml/pos_pax.xml @@ -20,7 +20,10 @@ - Send +
+ Credit + Debit +