From b9a44f8600781515bfd9b3b955d9fa92efa032b3 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 | 47 ++++++++---- pos_pax/static/src/xml/pos_pax.xml | 5 +- 4 files changed, 147 insertions(+), 22 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 50302a72..28e21cad 100644 --- a/pos_pax/static/src/js/pos_pax.js +++ b/pos_pax/static/src/js/pos_pax.js @@ -28,11 +28,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], @@ -40,8 +47,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; @@ -54,6 +65,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(); }, @@ -64,11 +76,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)'); } } }); @@ -113,7 +126,7 @@ PaymentScreenWidget.include({ }, // Handler to manage the card reader string - pax_credit_transaction: function () { + pax_credit_transaction: function (tender_type) { var order = this.pos.get_order(); if(this.pos.getPAXOnlinePaymentJournals().length === 0) { @@ -137,7 +150,7 @@ PaymentScreenWidget.include({ } transaction = { - command: 'T00', + command: (tender_type == 'debit') ? 'T02' : 'T00', version: '1.28', transactionType: transactionType, amountInformation: { @@ -164,7 +177,7 @@ PaymentScreenWidget.include({ }); PAX.mDestinationIP = self.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) { @@ -177,6 +190,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(); @@ -211,7 +225,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: { @@ -226,7 +240,7 @@ PaymentScreenWidget.include({ } PAX.mDestinationIP = self.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}) @@ -283,7 +297,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',{ @@ -292,14 +306,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 401548bf..052bcc7b 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 +