Merge branch 'imp/11.0/pos_pax__debit' into '11.0'

imp/11.0/pos_pax__debit into 11.0

See merge request hibou-io/hibou-odoo/suite!755
This commit is contained in:
Jared Kipe
2020-12-29 19:17:30 +00:00
4 changed files with 154 additions and 36 deletions

View File

@@ -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;
}

View File

@@ -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<hex.length; i++){
if(hex[i] != ""){
@@ -471,7 +473,108 @@ odoo.define('pos_pax.pax_device', function (require) {
this.HttpCommunication('DoCredit',url,function(response){
callback(response);
},PAX.timeout.DoCredit,fail);
}
},
//DoDebit
DoDebit : function(doDebitInfo,callback,fail){
var amountInformation,accountInformation,traceInformation,avsInformation,cashierInformation,commercialInformation,motoEcommerce,additionalInformation;
var params = [this.mStx.hex,doDebitInfo.command, this.mFS.hex, doDebitInfo.version];
params.push(this.mFS.hex);
// if(doDebitInfo.transactionType != ''){
params.push(doDebitInfo.transactionType);
// }
params.push(this.mFS.hex);
params = this.PushParams(params,"amountInformation",doDebitInfo.amountInformation);
params.push(this.mFS.hex);
params = this.PushParams(params,"accountInformation",doDebitInfo.accountInformation);
params.push(this.mFS.hex);
params = this.PushParams(params,"traceInformation",doDebitInfo.traceInformation);
// params.push(this.mFS.hex);
// params = this.PushParams(params,"avsInformation",doCreditInfo.avsInformation);
params.push(this.mFS.hex);
params = this.PushParams(params,"cashierInformation",doDebitInfo.cashierInformation);
// params.push(this.mFS.hex);
// params = this.PushParams(params,"commercialInformation",doCreditInfo.commercialInformation);
//
// params.push(this.mFS.hex);
// params = this.PushParams(params,"motoEcommerce",doCreditInfo.motoEcommerce);
params.push(this.mFS.hex);
params = this.PushParams(params,"additionalInformation",doDebitInfo.additionalInformation);
params.push(this.mEtx.hex);
var lrc = this.getLRC(params);
console.log(params);
//prepare for base64 encoding.
var command_hex = base64ToHex($.base64.btoa(doDebitInfo.command));
var version_hex = base64ToHex($.base64.btoa(doDebitInfo.version));
var transactionType_hex = base64ToHex($.base64.btoa(doDebitInfo.transactionType));
var amountInformation_hex = base64ToHex($.base64.btoa(doDebitInfo.amountInformation));
var accountInformation_hex = base64ToHex($.base64.btoa(doDebitInfo.accountInformation));
var traceInformation_hex = base64ToHex($.base64.btoa(doDebitInfo.traceInformation));
var avsInformation_hex = base64ToHex($.base64.btoa(doDebitInfo.avsInformation));
var cashierInformation_hex = base64ToHex($.base64.btoa(doDebitInfo.cashierInformation));
var commercialInformation_hex = base64ToHex($.base64.btoa(doDebitInfo.commercialInformation));
var motoEcommerce_hex = base64ToHex($.base64.btoa(doDebitInfo.motoEcommerce));
var additionalInformation_hex = base64ToHex($.base64.btoa(doDebitInfo.additionalInformation));
//var elements = [this.mStx.code, command_hex, this.mFS.code, version_hex, this.mFS.code, uploadFlag_hex, this.mFS.code, timeout, this.mEtx.code, base64ToHex($.base64.btoa(lrc))];
var elements = [this.mStx.code];
elements.push(command_hex);
elements.push(this.mFS.code);
elements.push(version_hex);
elements.push(this.mFS.code);
if(transactionType_hex != ''){
elements.push(transactionType_hex);
}
elements.push(this.mFS.code);
elements = this.AddBase64(elements,"amountInformation",doDebitInfo.amountInformation);
elements.push(this.mFS.code);
elements = this.AddBase64(elements,"accountInformation",doDebitInfo.accountInformation);
elements.push(this.mFS.code);
elements = this.AddBase64(elements,"traceInformation",doDebitInfo.traceInformation);
// elements.push(this.mFS.code);
// elements = this.AddBase64(elements,"avsInformation",doCreditInfo.avsInformation);
elements.push(this.mFS.code);
elements = this.AddBase64(elements,"cashierInformation",doDebitInfo.cashierInformation);
// elements.push(this.mFS.code);
// elements = this.AddBase64(elements,"commercialInformation",doCreditInfo.commercialInformation);
// elements.push(this.mFS.code);
// elements = this.AddBase64(elements,"motoEcommerce",doCreditInfo.motoEcommerce);
elements.push(this.mFS.code);
elements = this.AddBase64(elements,"additionalInformation",doDebitInfo.additionalInformation);
elements.push(this.mEtx.code);
elements.push(base64ToHex($.base64.btoa(lrc)));
console.log("elements");
console.log(elements);
var final_string = elements.join(" ");
var final_b64 = hexToBase64(final_string);
console.log("LRC: " + lrc);
console.log("Base64: " + final_b64);
// if(customData != ''){
// final_b64 = hexToBase64(final_string+"&custom_data=<PAX>"+customData+"</PAX>");
// }
var url = this.mDestinationIP + '?' + final_b64;
console.log("URL: " + url);
this.HttpCommunication('DoDebit',url,function(response){
callback(response);
},PAX.timeout.DoDebit,fail);
},
};
return PAX;

View File

@@ -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');
});
},

View File

@@ -20,7 +20,10 @@
<t t-esc='line.name' />
</t>
<t t-else="">
<span class="btn btn-small pax_send_transaction">Send</span>
<div>
<span class="btn btn-small pax_send_transaction">Credit</span>
<span class="btn btn-small pax_send_transaction_debit">Debit</span>
</div>
</t>
</t>
<t t-if="line.cashregister.journal.type !== 'bank'">