diff options
| author | Joren Van Onder <jov@odoo.com> | 2019-08-19 12:30:39 -0700 |
|---|---|---|
| committer | Joren Van Onder <jov@odoo.com> | 2019-08-23 13:33:28 -0700 |
| commit | cd4b10b004f69098b6cf8193a171bb3c14f22b97 (patch) | |
| tree | 17c2e6f89f39408aa37b6b00196c6d19fabc85f8 /addons/point_of_sale/static/src/js/payment.js | |
| parent | 296c2ea13d206a10adb868b143120896d46e3519 (diff) | |
[IMP] point_of_sale: generic electronic payment interface
This is an interface that can be implemented to support some
electronic payment method in the POS. It's extracted from the existing
pos_iot code.
To implement a payment method you:
- Python: add a selection to the use_payment_terminal field in Python
- JS: implement the PaymentInterface class
- JS: register your PaymentInterface in point_of_sale.models:
models.register_payment_method(
'use_payment_terminal_selection_value', ImplementedPaymentInterface
);
See the documentation of PaymentInterface for details on what each
method does and when it is called.
Co-authored-by: Antoine Prieels <anp@odoo.com>
Diffstat (limited to 'addons/point_of_sale/static/src/js/payment.js')
| -rw-r--r-- | addons/point_of_sale/static/src/js/payment.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/addons/point_of_sale/static/src/js/payment.js b/addons/point_of_sale/static/src/js/payment.js new file mode 100644 index 00000000000..ae73f552604 --- /dev/null +++ b/addons/point_of_sale/static/src/js/payment.js @@ -0,0 +1,95 @@ +odoo.define('point_of_sale.PaymentInterface', function (require) { +"use strict"; + +var core = require('web.core'); + +/** + * Implement this interface to support a new payment method in the POS: + * + * var PaymentInterface = require('point_of_sale.PaymentInterface'); + * var MyPayment = PaymentInterface.extend({ + * ... + * }) + * + * To connect the interface to the right payment methods register it: + * + * var models = require('point_of_sale.models'); + * models.register_payment_method('my_payment', MyPayment); + * + * my_payment is the technical name of the added selection in + * use_payment_terminal. + * + * If necessary new fields can be loaded on any model: + * + * models.load_fields('pos.payment.method', ['new_field1', 'new_field2']); + */ +var PaymentInterface = core.Class.extend({ + init: function (pos, payment_method) { + this.pos = pos; + this.payment_method = payment_method; + this.supports_reversals = false; + }, + + /** + * Call this function to enable UI elements that allow a user to + * reverse a payment. This requires that you implement + * send_payment_reversal. + */ + enable_reversals: function () { + this.supports_reversals = true; + }, + + /** + * Called when a user clicks the "Send" button in the + * interface. This should initiate a payment request and return a + * Promise that resolves when the final status of the payment line + * is set with set_payment_status. + * + * For successful transactions set_receipt_info() should be used + * to set info that should to be printed on the receipt. You + * should also set card_type and transaction_id on the line for + * successful transactions. + * + * @param {string} cid - The id of the paymentline + * @returns {Promise} resolved with a boolean that is false when + * the payment should be retried. Rejected when the status of the + * paymentline will be manually updated. + */ + send_payment_request: function (cid) {}, + + /** + * Called when a user removes a payment line that's still waiting + * on send_payment_request to complete. Should execute some + * request to ensure the current payment request is + * cancelled. This is not to refund payments, only to cancel + * them. The payment line being cancelled will be deleted + * automatically after the returned promise resolves. + * + * @param {} order - The order of the paymentline + * @param {string} cid - The id of the paymentline + * @returns {Promise} + */ + send_payment_cancel: function (order, cid) {}, + + /** + * This is an optional method. When implementing this make sure to + * call enable_reversals() in the constructor of your + * interface. This should reverse a previous payment with status + * 'done'. The paymentline will be removed based on returned + * Promise. + * + * @param {string} cid - The id of the paymentline + * @returns {Promise} returns true if the reversal was successful. + */ + send_payment_reversal: function (cid) {}, + + /** + * Called when the payment screen in the POS is closed (by + * e.g. clicking the "Back" button). Could be used to cancel in + * progress payments. + */ + close: function () {}, +}); + +return PaymentInterface; +}); |
