diff options
Diffstat (limited to 'addons/pos_restaurant_adyen/models')
| -rw-r--r-- | addons/pos_restaurant_adyen/models/__init__.py | 6 | ||||
| -rw-r--r-- | addons/pos_restaurant_adyen/models/pos_order.py | 16 | ||||
| -rw-r--r-- | addons/pos_restaurant_adyen/models/pos_payment.py | 32 | ||||
| -rw-r--r-- | addons/pos_restaurant_adyen/models/pos_payment_method.py | 17 |
4 files changed, 71 insertions, 0 deletions
diff --git a/addons/pos_restaurant_adyen/models/__init__.py b/addons/pos_restaurant_adyen/models/__init__.py new file mode 100644 index 00000000..71dd1190 --- /dev/null +++ b/addons/pos_restaurant_adyen/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import pos_order +from . import pos_payment +from . import pos_payment_method diff --git a/addons/pos_restaurant_adyen/models/pos_order.py b/addons/pos_restaurant_adyen/models/pos_order.py new file mode 100644 index 00000000..f3b8553c --- /dev/null +++ b/addons/pos_restaurant_adyen/models/pos_order.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class PosOrder(models.Model): + _inherit = 'pos.order' + + def action_pos_order_paid(self): + res = super(PosOrder, self).action_pos_order_paid() + if not self.config_id.set_tip_after_payment: + payment_lines = self.payment_ids.filtered(lambda line: line.payment_method_id.use_payment_terminal == 'adyen') + for payment_line in payment_lines: + payment_line._adyen_capture() + return res diff --git a/addons/pos_restaurant_adyen/models/pos_payment.py b/addons/pos_restaurant_adyen/models/pos_payment.py new file mode 100644 index 00000000..4c62cacf --- /dev/null +++ b/addons/pos_restaurant_adyen/models/pos_payment.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import json +import requests + +from odoo import models + +TIMEOUT = 10 + + +class PosPayment(models.Model): + _inherit = 'pos.payment' + + def _update_payment_line_for_tip(self, tip_amount): + """Capture the payment when a tip is set.""" + res = super(PosPayment, self)._update_payment_line_for_tip(tip_amount) + if self.payment_method_id.use_payment_terminal == 'adyen': + self._adyen_capture() + return res + + def _adyen_capture(self): + data = { + 'originalReference': self.transaction_id, + 'modificationAmount': { + 'value': int(self.amount * 10**self.currency_id.decimal_places), + 'currency': self.currency_id.name, + }, + 'merchantAccount': self.payment_method_id.adyen_merchant_account, + } + + return self.payment_method_id.proxy_adyen_request(data, 'capture') diff --git a/addons/pos_restaurant_adyen/models/pos_payment_method.py b/addons/pos_restaurant_adyen/models/pos_payment_method.py new file mode 100644 index 00000000..e40b6e08 --- /dev/null +++ b/addons/pos_restaurant_adyen/models/pos_payment_method.py @@ -0,0 +1,17 @@ +# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class PosPaymentMethod(models.Model): + _inherit = 'pos.payment.method' + + adyen_merchant_account = fields.Char(help='The POS merchant account code used in Adyen') + + def _get_adyen_endpoints(self): + return { + **super(PosPaymentMethod, self).get_adyen_endpoints(), + 'adjust': 'https://pal-%s.adyen.com/pal/servlet/Payment/v52/adjustAuthorisation', + 'capture': 'https://pal-%s.adyen.com/pal/servlet/Payment/v52/capture', + } |
