Debian Codegraph @

addons/point_of_sale/static/src/app/utils/payment/payment_interface.js

raw
1 /**
2 * Implement this interface to support a new payment method in the POS:
3 *
4 * import { PaymentInterface } from "@point_of_sale/app/utils/payment/payment_interface";
5 * class MyPayment extends PaymentInterface {}
6 *
7 * To connect the interface to the right payment methods register it:
8 *
9 * import { register_payment_method } models from "@point_of_sale/app/store/pos_store";
10 * register_payment_method('my_payment', MyPayment);
11 *
12 * my_payment is the technical name of the added selection in
13 * use_payment_terminal.
14 *
15 * If necessary new fields can be loaded on any model:
16 * by overriding the loader_params of the models in the back end
17 * in the `pos.session` model
18 */
19 export class PaymentInterface {
20 constructor(pos, payment_method_id) {
21 this.setup(pos, payment_method_id);
22 }
23
24 setup(pos, payment_method_id) {
25 this.env = pos.env;
26 this.pos = pos;
27 this.payment_method_id = payment_method_id;
28 this.supports_reversals = false;
29 }
30
31 /**
32 * This getter determines if send_payment_request
33 * is called automatically upon selecting the payment method.
34 * Overriding this to false allows manual input of an amount
35 * before sending the request to the terminal.
36 */
37 get fastPayments() {
38 return true;
39 }
40
41 /**
42 * Called when a user clicks the "Send" button in the
43 * interface. This should initiate a payment request and return a
44 * Promise that resolves when the final status of the payment line
45 * is set with setPaymentStatus.
46 *
47 * For successful transactions setReceiptInfo() should be used
48 * to set info that should to be printed on the receipt. You
49 * should also set card_type and transaction_id on the line for
50 * successful transactions.
51 *
52 * @param {string} uuid - The uuid of the paymentline
53 * @returns {Promise} resolved with a boolean that is false when
54 * the payment should be retried. Rejected when the status of the
55 * paymentline will be manually updated.
56 */
57 sendPaymentRequest(uuid) {}
58
59 /**
60 * Called when a user removes a payment line that's still waiting
61 * on send_payment_request to complete. Should execute some
62 * request to ensure the current payment request is
63 * cancelled. This is not to refund payments, only to cancel
64 * them. The payment line being cancelled will be deleted
65 * automatically after the returned promise resolves.
66 *
67 * @param {} order - The order of the paymentline
68 * @param {string} uuid - The id of the paymentline
69 * @returns {Promise}
70 */
71 sendPaymentCancel(order, uuid) {}
72
73 /**
74 * This is an optional method. When implementing this make sure to
75 * call enable_reversals() in the constructor of your
76 * interface. This should reverse a previous payment with status
77 * 'done'. The paymentline will be removed based on returned
78 * Promise.
79 *
80 * @param {string} uuid - The id of the paymentline
81 * @returns {Promise} returns true if the reversal was successful.
82 */
83 sendPaymentReversal(uuid) {}
84
85 /**
86 * Called when the payment screen in the POS is closed (by
87 * e.g. clicking the "Back" button). Could be used to cancel in
88 * progress payments.
89 */
90 close() {}
91 }