diff --git a/pos_payment_method_cashlogy_connectorplus/README.rst b/pos_payment_method_cashlogy_connectorplus/README.rst new file mode 100644 index 0000000000..90c24c640b --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/README.rst @@ -0,0 +1,101 @@ +=========================== +PoS Payment Method CashLogy +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a3170f9d49dd2327613e90b0cd189ffb647ef163951eb7c1a840b6c1a5d04d23 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/18.0/pos_payment_method_cashlogy_connectorplus + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-18-0/pos-18-0-pos_payment_method_cashlogy_connectorplus + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to make payments with a Cashlogy +(https://cashlogy.com/) terminal on the Point of Sale frontend. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To add a Cashlogy payment terminal: + +1. Go to *Point of Sale > Configuration > Payment Methods* +2. Choose a cash payment method or create a new one. +3. Select *Cashlogy* in the *Use a Payment Terminal* field. +4. Configure the Cashlogy terminal url and api key. +5. Configure the desired, Cashlogy terminal in the proper PoS + configurations. + +Note that if a single payment method was used for cash in different +stores, it should be splitted in as many phisical stores there are. + +Known issues / Roadmap +====================== + +- Add support for machines with credit card payment. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__ + + - Pedro M. Baeza + - Carlos Roca + - David Bañón + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_payment_method_cashlogy_connectorplus/__init__.py b/pos_payment_method_cashlogy_connectorplus/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_payment_method_cashlogy_connectorplus/__manifest__.py b/pos_payment_method_cashlogy_connectorplus/__manifest__.py new file mode 100644 index 0000000000..bc02515a2a --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2026 Tecnativa - David Bañón +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "PoS Payment Method CashLogy", + "summary": "Allows to pay with CashLogy Terminals on the Point of Sale", + "version": "18.0.1.0.1", + "category": "Point Of Sale", + "website": "https://github.com/OCA/pos", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": [ + "point_of_sale", + ], + "data": [ + "views/pos_payment_method_views.xml", + ], + "demo": ["demo/cashlogy_demo.xml"], + "assets": { + "point_of_sale._assets_pos": [ + "pos_payment_method_cashlogy_connectorplus/static/src/**/*" + ], + }, +} diff --git a/pos_payment_method_cashlogy_connectorplus/demo/cashlogy_demo.xml b/pos_payment_method_cashlogy_connectorplus/demo/cashlogy_demo.xml new file mode 100644 index 0000000000..e1f14684c5 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/demo/cashlogy_demo.xml @@ -0,0 +1,11 @@ + + + + http://localhost:3000 + testkey + cashlogy + Cashlogy + cash + terminal + + diff --git a/pos_payment_method_cashlogy_connectorplus/i18n/es.po b/pos_payment_method_cashlogy_connectorplus/i18n/es.po new file mode 100644 index 0000000000..75e9761307 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/i18n/es.po @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_method_cashlogy +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model.fields,help:pos_payment_method_cashlogy_connectorplus.field_pos_payment_method__cashlogy_api_key +msgid "Api key to authenticate with Cashogy ConnectorPlus" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model.fields,field_description:pos_payment_method_cashlogy_connectorplus.field_pos_payment_method__cashlogy_api_key +msgid "Cashlogy API key" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model.fields,field_description:pos_payment_method_cashlogy_connectorplus.field_pos_payment_method__cashlogy_url +msgid "Cashlogy Terminal URL" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#. odoo-javascript +#: code:addons/pos_payment_method_cashlogy_connectorplus/static/src/js/payment_cashlogy.esm.js:0 +msgid "Error" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model.fields,help:pos_payment_method_cashlogy_connectorplus.field_pos_payment_method__cashlogy_url +msgid "" +"Must be reachable by the PoS in the store and contain no trailing slash (/)" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#. odoo-javascript +#: code:addons/pos_payment_method_cashlogy_connectorplus/static/src/js/payment_cashlogy.esm.js:0 +msgid "Not implemented yet" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model,name:pos_payment_method_cashlogy_connectorplus.model_pos_payment_method +msgid "Point of Sale Payment Methods" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model,name:pos_payment_method_cashlogy_connectorplus.model_pos_session +msgid "Point of Sale Session" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model_terms:ir.ui.view,arch_db:pos_payment_method_cashlogy_connectorplus.pos_payment_method_view_form +msgid "http://somehost:3000" +msgstr "" diff --git a/pos_payment_method_cashlogy_connectorplus/i18n/pos_payment_method_cashlogy_connectorplus.pot b/pos_payment_method_cashlogy_connectorplus/i18n/pos_payment_method_cashlogy_connectorplus.pot new file mode 100644 index 0000000000..ecf384f306 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/i18n/pos_payment_method_cashlogy_connectorplus.pot @@ -0,0 +1,62 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_method_cashlogy_connectorplus +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model.fields,help:pos_payment_method_cashlogy_connectorplus.field_pos_payment_method__cashlogy_api_key +msgid "Api key to authenticate with Cashogy ConnectorPlus" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model.fields,field_description:pos_payment_method_cashlogy_connectorplus.field_pos_payment_method__cashlogy_api_key +msgid "Cashlogy API key" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model.fields,field_description:pos_payment_method_cashlogy_connectorplus.field_pos_payment_method__cashlogy_url +msgid "Cashlogy Terminal URL" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#. odoo-javascript +#: code:addons/pos_payment_method_cashlogy_connectorplus/static/src/js/payment_cashlogy.esm.js:0 +msgid "Error" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model.fields,help:pos_payment_method_cashlogy_connectorplus.field_pos_payment_method__cashlogy_url +msgid "" +"Must be reachable by the PoS in the store and contain no trailing slash (/)" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#. odoo-javascript +#: code:addons/pos_payment_method_cashlogy_connectorplus/static/src/js/payment_cashlogy.esm.js:0 +msgid "Not implemented yet" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model,name:pos_payment_method_cashlogy_connectorplus.model_pos_payment_method +msgid "Point of Sale Payment Methods" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model:ir.model,name:pos_payment_method_cashlogy_connectorplus.model_pos_session +msgid "Point of Sale Session" +msgstr "" + +#. module: pos_payment_method_cashlogy_connectorplus +#: model_terms:ir.ui.view,arch_db:pos_payment_method_cashlogy_connectorplus.pos_payment_method_view_form +msgid "http://somehost:3000" +msgstr "" diff --git a/pos_payment_method_cashlogy_connectorplus/models/__init__.py b/pos_payment_method_cashlogy_connectorplus/models/__init__.py new file mode 100644 index 0000000000..604d90cb18 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/models/__init__.py @@ -0,0 +1,2 @@ +from . import pos_payment_method +from . import pos_session diff --git a/pos_payment_method_cashlogy_connectorplus/models/pos_payment_method.py b/pos_payment_method_cashlogy_connectorplus/models/pos_payment_method.py new file mode 100644 index 0000000000..24a3ddcf79 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/models/pos_payment_method.py @@ -0,0 +1,48 @@ +# Copyright 2026 Tecnativa - David Bañón +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class PosPaymentMethod(models.Model): + _inherit = ["pos.payment.method", "pos.load.mixin"] + _name = "pos.payment.method" + + def _get_payment_terminal_selection(self): + return super()._get_payment_terminal_selection() + [("cashlogy", "cashlogy")] + + @api.model + def _load_pos_data_fields(self, config_id): + res = super()._load_pos_data_fields(config_id) + return res + ["cashlogy_url", "cashlogy_api_key"] + + cashlogy_url = fields.Char( + string="Cashlogy Terminal URL", + help=( + "Must be reachable by the PoS in the store" + " and contain no trailing slash (/)" + ), + ) + + cashlogy_api_key = fields.Char( + string="Cashlogy API key", + help="Api key to authenticate with Cashogy ConnectorPlus", + ) + + def _onchange_journal_id(self): + """Cash payment method force the `use_payment_terminal` to `False` as + it's assumed that a cash journal can't have a payment terminal. Let's keep + the method when it's needed""" + res = super()._onchange_journal_id() + if self.use_payment_terminal != "cashlogy" and not self.is_cash_count: + return res + self.use_payment_terminal = "cashlogy" + + def _compute_hide_use_payment_terminal(self): + """Now that we have the option to choose a payment terminal for the cashlogy + payments, we can show the terminal options for cash payment types.""" + cash_payment_types = self.filtered(lambda x: x.type == "cash") + cash_payment_types.hide_use_payment_terminal = False + return super( + PosPaymentMethod, self - cash_payment_types + )._compute_hide_use_payment_terminal() diff --git a/pos_payment_method_cashlogy_connectorplus/models/pos_session.py b/pos_payment_method_cashlogy_connectorplus/models/pos_session.py new file mode 100644 index 0000000000..98471ed67c --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/models/pos_session.py @@ -0,0 +1,12 @@ +# Copyright 2026 Tecnativa - David Bañón +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + + +class PosSession(models.Model): + _inherit = "pos.session" + + def _loader_params_pos_payment_method(self): + result = super()._loader_params_pos_payment_method() + result["search_params"]["fields"].extend(["cashlogy_url", "cashlogy_api_key"]) + return result diff --git a/pos_payment_method_cashlogy_connectorplus/pyproject.toml b/pos_payment_method_cashlogy_connectorplus/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/pos_payment_method_cashlogy_connectorplus/readme/CONFIGURE.md b/pos_payment_method_cashlogy_connectorplus/readme/CONFIGURE.md new file mode 100644 index 0000000000..ca10b9c024 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/readme/CONFIGURE.md @@ -0,0 +1,10 @@ +To add a Cashlogy payment terminal: + +1. Go to _Point of Sale \> Configuration \> Payment Methods_ +2. Choose a cash payment method or create a new one. +3. Select _Cashlogy_ in the _Use a Payment Terminal_ field. +4. Configure the Cashlogy terminal url and api key. +5. Configure the desired, Cashlogy terminal in the proper PoS configurations. + +Note that if a single payment method was used for cash in different stores, it should be +splitted in as many phisical stores there are. diff --git a/pos_payment_method_cashlogy_connectorplus/readme/CONTRIBUTORS.md b/pos_payment_method_cashlogy_connectorplus/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..1b24005284 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [Tecnativa](https://www.tecnativa.com) + - Pedro M. Baeza + - Carlos Roca + - David Bañón diff --git a/pos_payment_method_cashlogy_connectorplus/readme/DESCRIPTION.md b/pos_payment_method_cashlogy_connectorplus/readme/DESCRIPTION.md new file mode 100644 index 0000000000..9e84968bd0 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows to make payments with a Cashlogy () terminal +on the Point of Sale frontend. diff --git a/pos_payment_method_cashlogy_connectorplus/readme/ROADMAP.md b/pos_payment_method_cashlogy_connectorplus/readme/ROADMAP.md new file mode 100644 index 0000000000..8fb71c2013 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/readme/ROADMAP.md @@ -0,0 +1 @@ +- Add support for machines with credit card payment. diff --git a/pos_payment_method_cashlogy_connectorplus/static/description/icon.png b/pos_payment_method_cashlogy_connectorplus/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/pos_payment_method_cashlogy_connectorplus/static/description/icon.png differ diff --git a/pos_payment_method_cashlogy_connectorplus/static/description/index.html b/pos_payment_method_cashlogy_connectorplus/static/description/index.html new file mode 100644 index 0000000000..ecd3e1f9fa --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/static/description/index.html @@ -0,0 +1,451 @@ + + + + + +PoS Payment Method CashLogy + + + +
+

PoS Payment Method CashLogy

+ + +

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runboat

+

This module allows to make payments with a Cashlogy +(https://cashlogy.com/) terminal on the Point of Sale frontend.

+

Table of contents

+ +
+

Configuration

+

To add a Cashlogy payment terminal:

+
    +
  1. Go to Point of Sale > Configuration > Payment Methods
  2. +
  3. Choose a cash payment method or create a new one.
  4. +
  5. Select Cashlogy in the Use a Payment Terminal field.
  6. +
  7. Configure the Cashlogy terminal url and api key.
  8. +
  9. Configure the desired, Cashlogy terminal in the proper PoS +configurations.
  10. +
+

Note that if a single payment method was used for cash in different +stores, it should be splitted in as many phisical stores there are.

+
+
+

Known issues / Roadmap

+
    +
  • Add support for machines with credit card payment.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa
      +
    • Pedro M. Baeza
    • +
    • Carlos Roca
    • +
    • David Bañón
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/pos project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/pos_payment_method_cashlogy_connectorplus/static/description/logo.jpg b/pos_payment_method_cashlogy_connectorplus/static/description/logo.jpg new file mode 100644 index 0000000000..01531c1d5a Binary files /dev/null and b/pos_payment_method_cashlogy_connectorplus/static/description/logo.jpg differ diff --git a/pos_payment_method_cashlogy_connectorplus/static/src/app/debug/debug_widget.esm.js b/pos_payment_method_cashlogy_connectorplus/static/src/app/debug/debug_widget.esm.js new file mode 100644 index 0000000000..a15aa6d84e --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/static/src/app/debug/debug_widget.esm.js @@ -0,0 +1,12 @@ +import {DebugWidget} from "@point_of_sale/app/debug/debug_widget"; +import {patch} from "@web/core/utils/patch"; + +patch(DebugWidget.prototype, { + async cashlogyOpenBackOffice() { + for (const payment_method of this.pos._get_cashlogy_payment_methods()) { + await payment_method + ._cashlogy_request_open_back_office() + .catch(console.error); + } + }, +}); diff --git a/pos_payment_method_cashlogy_connectorplus/static/src/app/debug/debug_widget.xml b/pos_payment_method_cashlogy_connectorplus/static/src/app/debug/debug_widget.xml new file mode 100644 index 0000000000..34a01ca3c0 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/static/src/app/debug/debug_widget.xml @@ -0,0 +1,20 @@ + + + + + +
+
Cashlogy
+
    + +
+
+
+
+
+
diff --git a/pos_payment_method_cashlogy_connectorplus/static/src/app/payment/payment_cashlogy.esm.js b/pos_payment_method_cashlogy_connectorplus/static/src/app/payment/payment_cashlogy.esm.js new file mode 100644 index 0000000000..0ba2618f2d --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/static/src/app/payment/payment_cashlogy.esm.js @@ -0,0 +1,184 @@ +/* Copyright 2026 Tecnativa - David Bañón + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).*/ + +import { + AlertDialog, + ConfirmationDialog, +} from "@web/core/confirmation_dialog/confirmation_dialog"; +import {PaymentInterface} from "@point_of_sale/app/payment/payment_interface"; +import {_t} from "@web/core/l10n/translation"; +import {register_payment_method} from "@point_of_sale/app/store/pos_store"; +export class PaymentCashlogy extends PaymentInterface { + /** + * @override + */ + setup() { + super.setup(...arguments); + this.ongoing_payment_key = false; + this.ongoing_refund = false; + } + + /** + * @override + */ + async send_payment_reversal() { + super.send_payment_reversal(...arguments); + console.log("Payment reversal called"); + // TODO: Implement cashlogy reversal + this.env.services.dialog.add(AlertDialog, { + title: _t("Error"), + body: _t("Not implemented yet"), + }); + return false; + // Return this.cashlogy_send_refund_request(order); + } + + /** + * @override + */ + async send_payment_cancel() { + super.send_payment_cancel(...arguments); + // TODO: Implement cashlogy cancel request. + // ATM We can't send a request to the terminal to cancel an ongoing payment, so we must ask the user to do it. + if (this.ongoing_refund) { + this.env.services.dialog.add(AlertDialog, { + title: _t("Error"), + body: _t("Cash refunds can't be canceled!"), + }); + } else { + this.env.services.dialog.add(AlertDialog, { + body: _t("You must cancel the payment manually from the terminal."), + title: _t("Manual cancel required."), + }); + } + return false; + // Const order = this.pos.get_order(); + // const line = order.get_selected_paymentline(); + // line.set_payment_status("waitingCancel"); + // return this.cashlogy_send_payment_cancel_request(operation); + } + /** + * @override + */ + async send_payment_request() { + super.send_payment_request(...arguments); + const order = this.pos.get_order(); + const payment_line = order.get_selected_paymentline(); + const amount = Math.round(order.get_due(payment_line) * 100); + if (amount >= 0) { + return this.cashlogy_send_payment_request(amount, order, payment_line); + } + return this.cashlogy_send_dispense_request( + Math.abs(amount), + order, + payment_line + ); + } + + // -------------------------------------------------------------------------- + // Private + // -------------------------------------------------------------------------- + async cashlogy_check_payment_cancel(payment_line) { + // We can't tell the terminal to cancel a payment, + // so we must trust that the user does it manually. + // if the payment is cancelled from the machine first and not odoo we already + // handle it in _cashlogy_wait_payment_done + const method = this.payment_method_id; + if (!this.ongoing_payment_key) { + return true; + } + const payment_statuses = await method._cashlogy_get_payment_statuses(); + if ( + (payment_statuses?.[this.ongoing_payment_key] || "CANCELLED") in + ["CANCELLED", "SUCCESS"] + ) { + return true; + } + + return new Promise((resolve, reject) => { + this.env.services.dialog.add(ConfirmationDialog, { + body: _t("You must cancel the payment manually from the terminal."), + title: _t("Manual cancel required."), + confirmLabel: _t("Payment canceled."), + cancelLabel: _t("Continue payment."), + confirm: async () => { + // We call this again to prevent the dialog from closing if + // the payment hasn't been canceled on the terminal. + this.cashlogy_check_payment_cancel(payment_line); + }, + cancel: () => { + reject("Continue with payment"); + }, + }); + }); + } + async cashlogy_send_payment_request(amount, order, payment_line) { + // The payment is done in the following steps: + // 1. The POS send a payment request, to which the cashlogy respondes + // with an operation id. + // 2. Then the POS has to ask the cashlogy machine for the payment status + // until it returns "status": "FINISHED" and "result": "SUCCESS" + const method = this.payment_method_id; + const res = await method._cashlogy_request_payment_start(amount, order.name); + if (res.result === "FAILED_BUSY") { + payment_line.set_payment_status("retry"); + this.env.services.dialog.add(AlertDialog, { + title: _t("Error"), + body: _t( + "A payment/refund request is alredy ongoing on the Cashlogy Terminal!\n" + + "Please finish or cancel it before starting a new one" + ), + }); + return false; + } + if (res.result === "FAILED") { + payment_line.set_payment_status("retry"); + this.env.services.dialog.add(AlertDialog, { + title: _t("Error"), + body: _t("Unknown error when requesting payment start!"), + }); + return false; + } + payment_line.set_payment_status("waiting"); + this.ongoing_payment_key = res.id; + const result = await method._cashlogy_wait_payment_done( + this.ongoing_payment_key + ); + this.ongoing_payment_key = false; + return result; + } + async cashlogy_send_dispense_request(amount, order, payment_line) { + // Works like a payment, but with different endpoints + // 1. The POS send a dispense request + // 2. Then the POS has to ask the cashlogy machine for the dispense status + // until it returns "status": "FINISHED" and "result": "SUCCESS" + const method = this.payment_method_id; + const res = await method._cashlogy_request_dispense_start(amount, order.name); + if (res.result === "FAILED_BUSY") { + payment_line.set_payment_status("retry"); + this.env.services.dialog.add(AlertDialog, { + title: _t("Error"), + body: _t( + "A payment/refund request is alredy ongoing on the Cashlogy Terminal!\n" + + "Please finish or cancel it before starting a new one" + ), + }); + return false; + } + if (res.result === "FAILED") { + payment_line.set_payment_status("retry"); + this.env.services.dialog.add(AlertDialog, { + title: _t("Error"), + body: _t("Unknown error when requesting payment start!"), + }); + return false; + } + payment_line.set_payment_status("waiting"); + this.ongoing_refund = true; + const result = await method._cashlogy_wait_dispense_done(); + this.ongoing_refund = true; + return result; + } +} + +register_payment_method("cashlogy", PaymentCashlogy); diff --git a/pos_payment_method_cashlogy_connectorplus/static/src/app/payment/pos_payment_method.esm.js b/pos_payment_method_cashlogy_connectorplus/static/src/app/payment/pos_payment_method.esm.js new file mode 100644 index 0000000000..e2c0d29ae3 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/static/src/app/payment/pos_payment_method.esm.js @@ -0,0 +1,183 @@ +import {Base} from "@point_of_sale/app/models/related_models"; +import {registry} from "@web/core/registry"; + +export class PosPaymentMethod extends Base { + static pythonModel = "pos.payment.method"; + // Cashlogy machines need to be initialized when starting the POS + async cashlogy_init_session() { + // We first check if cashlogy terminal is initialized, + // If initialized, we do nothing, + // If idle, we init it. + // If initializing we wait for it to be readyy + const status_data = await this._cashlogy_request_init_status(); + if (status_data.status === "FINISHED") { + return true; + } + if (status_data.status === "IDLE") { + await this._cashlogy_request_init_session(); + } + // (status_data.status === "INITIALIZING") also leads here + await this._cashlogy_wait_init_done(); + return true; + } + async cashlogy_close_session() { + return await this._cashlogy_request_close_session(); + } + + // Request methods + _cashlogy_url() { + return `${this.cashlogy_url}/connectorPlus`; + } + async _cashlogy_request(url, method, data) { + const request_params = { + method: method, + }; + const headers = {"x-api-key": this.cashlogy_api_key}; + if (data && Object.keys(data).length > 0) { + request_params.body = JSON.stringify(data); + headers["content-type"] = "application/json"; + } + request_params.headers = headers; + console.info(`Sending request to ${url}`); + const response = await fetch(url, request_params); + if (!response.ok) { + return await response.text(); + } + return await response.json(); + } + async _cashlogy_request_init_session() { + const url = `${this._cashlogy_url()}/init`; + return await this._cashlogy_request(url, "POST", false); + } + async _cashlogy_request_close_session() { + const url = `${this._cashlogy_url()}/close`; + return await this._cashlogy_request(url, "POST", false); + } + async _cashlogy_request_init_status() { + const url = `${this._cashlogy_url()}/init/status`; + return await this._cashlogy_request(url, "GET", false); + } + async _cashlogy_request_payment_start(amount, ticket_num) { + const types = { + cash: "CASH", + bank: "CASHLESS", + }; + const data = { + price: amount, + ticketNumber: ticket_num, + machineCode: "machine-123", + secondScreen: false, + processManually: false, + screenVisible: true, + topMost: false, + // SELECTION, CASH, CASHLESS, tbd. + type: types[this.type] || "SELECTION", + peripheralId: "", + }; + const url = `${this._cashlogy_url()}/charge`; + return await this._cashlogy_request(url, "POST", data); + } + async _cashlogy_request_dispense_start(amount) { + const data = { + amount: amount, + onlyCoins: false, + screenVisible: true, + topMost: false, + }; + const url = `${this._cashlogy_url()}/dispense`; + return await this._cashlogy_request(url, "POST", data); + } + async _cashlogy_request_open_back_office() { + const data = { + operations: { + addChange: true, + giveChange: true, + closure: true, + withdrawCash: true, + collect: true, + completeEmpty: true, + cashlogyState: true, + recyclersSelfprotection: true, + accountingMismatch: true, + maintenance: true, + }, + topMost: true, + }; + const url = `${this._cashlogy_url()}/backOffice`; + return await this._cashlogy_request(url, "POST", data); + } + + async _cashlogy_request_payment_status() { + const url = `${this._cashlogy_url()}/charge/status`; + return await this._cashlogy_request(url, "GET", false); + } + async _cashlogy_request_dispense_status() { + const url = `${this._cashlogy_url()}/dispense/status`; + return await this._cashlogy_request(url, "GET", false); + } + + async _cashlogy_wait_init_done() { + const data = await this._cashlogy_request_init_status(); + if (data.result === "FINISHED") { + return data; + } + if (["INITIALIZING", "IN_PROGRESS"].includes(data.result)) { + throw new Error( + `Unexpected state when waiting for initialization to be done: ${data.result}` + ); + } + await new Promise((resolve) => setTimeout(resolve, 500)); + return await this._cashlogy_wait_init_done(); + } + async _cashlogy_wait_payment_done(payment_key) { + const data = await this._cashlogy_request_payment_status(); + if (!(payment_key in data)) { + console.log("Operation not found"); + } + if (data[payment_key].result === "SUCCESS") { + return data[payment_key]; + } + if (data[payment_key].result === "CANCELLED") { + return false; + } + if (data[payment_key].status in ["DISPENSE_FAILED", "ADD_CHARGE"]) { + // TODO: Add a warning to the user to show machine has no change. + } + if (data[payment_key].result !== "IN_PROGRESS") { + throw new Error( + `Unexpected state when waiting for payment to be done: ${data[payment_key].result}` + ); + } + await new Promise((resolve) => setTimeout(resolve, 1000)); + return await this._cashlogy_wait_payment_done(payment_key); + } + async _cashlogy_wait_dispense_done() { + const data = await this._cashlogy_request_dispense_status(); + if (data.result === "SUCCESS") { + return data; + } + + if (data.status in ["DISPENSE_FAILED", "ADD_CHARGE"]) { + // TODO: Add a warning to the user to show machine has no change. + } + if (data.result !== "IN_PROGRESS") { + throw new Error( + `Unexpected state when waiting for charge to be done: ${data.result}` + ); + } + await new Promise((resolve) => setTimeout(resolve, 1000)); + return await this._cashlogy_wait_dispense_done(); + } + async _cashlogy_get_payment_statuses() { + const data = await this._cashlogy_request_payment_status(); + const res = {}; + for (const [key, value] of Object.entries(data)) { + res[key] = value.result; + } + return res; + } +} + +registry + .category("pos_available_models") + .add(PosPaymentMethod.pythonModel, PosPaymentMethod); diff --git a/pos_payment_method_cashlogy_connectorplus/static/src/app/screens/close_pop_up.esm.js b/pos_payment_method_cashlogy_connectorplus/static/src/app/screens/close_pop_up.esm.js new file mode 100644 index 0000000000..b36d64c84a --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/static/src/app/screens/close_pop_up.esm.js @@ -0,0 +1,12 @@ +import {ClosePosPopup} from "@point_of_sale/app/navbar/closing_popup/closing_popup"; +import {patch} from "@web/core/utils/patch"; + +patch(ClosePosPopup.prototype, { + // Cashlogy machines need to be closed when the POS session is closed. + async closeSession(...args) { + for (const payment_method of this.pos._get_cashlogy_payment_methods()) { + await payment_method.cashlogy_close_session().catch(console.error); + } + return await super.closeSession(...args); + }, +}); diff --git a/pos_payment_method_cashlogy_connectorplus/static/src/app/screens/opening_control_popup.esm.js b/pos_payment_method_cashlogy_connectorplus/static/src/app/screens/opening_control_popup.esm.js new file mode 100644 index 0000000000..4d377de255 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/static/src/app/screens/opening_control_popup.esm.js @@ -0,0 +1,11 @@ +import {OpeningControlPopup} from "@point_of_sale/app/store/opening_control_popup/opening_control_popup"; +import {patch} from "@web/core/utils/patch"; + +patch(OpeningControlPopup.prototype, { + async confirm(...args) { + for (const payment_method of this.pos._get_cashlogy_payment_methods()) { + await payment_method.cashlogy_init_session().catch(console.error); + } + return await super.confirm(...args); + }, +}); diff --git a/pos_payment_method_cashlogy_connectorplus/static/src/app/store/pos_store.esm.js b/pos_payment_method_cashlogy_connectorplus/static/src/app/store/pos_store.esm.js new file mode 100644 index 0000000000..37aad375b4 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/static/src/app/store/pos_store.esm.js @@ -0,0 +1,13 @@ +import {PosStore} from "@point_of_sale/app/store/pos_store"; +import {patch} from "@web/core/utils/patch"; + +patch(PosStore.prototype, { + _get_cashlogy_payment_methods() { + return this.config.payment_method_ids.filter( + (m) => m.use_payment_terminal === "cashlogy" + ); + }, + hasCashlogyPaymentMethod() { + return Object.keys(this._get_cashlogy_payment_methods()).length; + }, +}); diff --git a/pos_payment_method_cashlogy_connectorplus/views/pos_payment_method_views.xml b/pos_payment_method_cashlogy_connectorplus/views/pos_payment_method_views.xml new file mode 100644 index 0000000000..995df00be0 --- /dev/null +++ b/pos_payment_method_cashlogy_connectorplus/views/pos_payment_method_views.xml @@ -0,0 +1,23 @@ + + + + pos.payment.method + + + + + + + + +