summaryrefslogtreecommitdiff
path: root/addons/pos_six/static/src
diff options
context:
space:
mode:
authorAntoine Prieels <anp@odoo.com>2020-03-02 14:35:00 +0000
committerAntoine Prieels <anp@odoo.com>2020-03-23 09:29:52 +0000
commit12fd8c37fd993ea79db1fba1eae1acb345893c52 (patch)
tree85b067b63b48749ecd20ce54a0a62924d1832eb2 /addons/pos_six/static/src
parent6413ef6955ccd1323e207050548696d63fc1d9b9 (diff)
[ADD] pos_six: Six payment terminals with TIM
Deprecate MPD integration for Six payment terminals and replace it with TIM because: - MPD broadcasts connection messages to the network so having multiple terminals and MPD servers in the same network results in connection issues - TIM has a JS SDK so it doesn't require an IoT Box. - MPD supports only Yomani and Yoximo terminals while TIM also supports Ingenico. closes odoo/odoo#46789 Taskid: 2188566 Related: odoo/upgrade#903 Related: odoo/enterprise#8994 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons/pos_six/static/src')
-rw-r--r--addons/pos_six/static/src/js/models.js9
-rw-r--r--addons/pos_six/static/src/js/payment_six.js134
2 files changed, 143 insertions, 0 deletions
diff --git a/addons/pos_six/static/src/js/models.js b/addons/pos_six/static/src/js/models.js
new file mode 100644
index 00000000000..cf00744239c
--- /dev/null
+++ b/addons/pos_six/static/src/js/models.js
@@ -0,0 +1,9 @@
+odoo.define('pos_six.models', function (require) {
+
+var models = require('point_of_sale.models');
+var PaymentSix = require('pos_six.payment');
+
+models.register_payment_method('six', PaymentSix);
+models.load_fields('pos.payment.method', ['six_terminal_ip']);
+
+});
diff --git a/addons/pos_six/static/src/js/payment_six.js b/addons/pos_six/static/src/js/payment_six.js
new file mode 100644
index 00000000000..15bbcb6745d
--- /dev/null
+++ b/addons/pos_six/static/src/js/payment_six.js
@@ -0,0 +1,134 @@
+odoo.define('pos_six.payment', function (require) {
+"use strict";
+
+var core = require('web.core');
+var PaymentInterface = require('point_of_sale.PaymentInterface');
+
+var _t = core._t;
+
+var PaymentSix = PaymentInterface.extend({
+
+ //--------------------------------------------------------------------------
+ // Public
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ */
+ init: function () {
+ this._super.apply(this, arguments);
+ this.enable_reversals();
+
+ var settings = new timapi.TerminalSettings();
+ settings.connectionMode = timapi.constants.ConnectionMode.onFixIp;
+ settings.connectionIPString = this.payment_method.six_terminal_ip;
+ settings.connectionIPPort = "80";
+
+ this.terminal = new timapi.Terminal(settings);
+ this.terminal.posId = this.pos.pos_session.name;
+ this.terminal.userId = this.pos.pos_session.user_id[0];
+
+ this.terminalListener = new timapi.DefaultTerminalListener();
+ this.terminalListener.transactionCompleted = this._onTransactionComplete.bind(this);
+ this.terminal.addListener(this.terminalListener);
+
+ var recipients = [timapi.constants.Recipient.merchant, timapi.constants.Recipient.cardholder];
+ var options = [];
+ _.forEach(recipients, (recipient) => {
+ var option = new timapi.PrintOption(
+ recipient,
+ timapi.constants.PrintFormat.normal,
+ 45,
+ [timapi.constants.PrintFlag.suppressHeader, timapi.constants.PrintFlag.suppressEcrInfo]
+ );
+ options.push(option);
+ });
+ this.terminal.printOptions = options;
+ },
+
+ /**
+ * @override
+ */
+ send_payment_cancel: function () {
+ this._super.apply(this, arguments);
+ this.terminal.cancel();
+ return Promise.resolve();
+ },
+
+ /**
+ * @override
+ */
+ send_payment_request: function () {
+ this._super.apply(this, arguments);
+ this.pos.get_order().selected_paymentline.set_payment_status('waitingCard');
+ return this._sendTransaction(timapi.constants.TransactionType.purchase);
+ },
+
+ /**
+ * @override
+ */
+ send_payment_reversal: function () {
+ this._super.apply(this, arguments);
+ this.pos.get_order().selected_paymentline.set_payment_status('reversing');
+ return this._sendTransaction(timapi.constants.TransactionType.reversal);
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ _onTransactionComplete: function (event, data) {
+ timapi.DefaultTerminalListener.prototype.transactionCompleted(event, data);
+
+ if (event.exception) {
+ this.pos.gui.show_popup('error', {
+ title: _t('Terminal Error'),
+ body: _t('Transaction was not processed correctly'),
+ });
+
+ this.transactionResolve();
+ } else {
+ if (data.printData){
+ this._printReceipts(data.printData.receipts)
+ }
+
+ // Store Transaction Data
+ var transactionData = new timapi.TransactionData();
+ transactionData.transSeq = data.transactionInformation.transSeq;
+ this.terminal.transactionData = transactionData;
+
+ this.transactionResolve(true);
+ }
+ },
+
+ _printReceipts: function (receipts) {
+ _.forEach(receipts, (receipt) => {
+ var value = receipt.value.replace(/\n/g, "<br />");
+ if (receipt.recipient === timapi.constants.Recipient.merchant && this.pos.proxy.printer) {
+ this.pos.proxy.printer.print_receipt(
+ "<div class='pos-receipt'><div class='pos-payment-terminal-receipt'>" +
+ value +
+ "</div></div>"
+ );
+ } else if (receipt.recipient === timapi.constants.Recipient.cardholder) {
+ this.pos.get_order().selected_paymentline.set_receipt_info(value);
+ }
+ });
+ },
+
+ _sendTransaction: function (transactionType) {
+ var amount = new timapi.Amount(
+ this.pos.get_order().selected_paymentline.amount,
+ timapi.constants.Currency[this.pos.currency.name]
+ );
+
+ return new Promise((resolve) => {
+ this.transactionResolve = resolve;
+ this.terminal.transactionAsync(transactionType, amount);
+ });
+ },
+});
+
+return PaymentSix;
+
+});