diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/pos_adyen/controllers/main.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/pos_adyen/controllers/main.py')
| -rw-r--r-- | addons/pos_adyen/controllers/main.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/addons/pos_adyen/controllers/main.py b/addons/pos_adyen/controllers/main.py new file mode 100644 index 00000000..ec988da3 --- /dev/null +++ b/addons/pos_adyen/controllers/main.py @@ -0,0 +1,32 @@ +# coding: utf-8 +import logging +import pprint +import json +from odoo import fields, http +from odoo.http import request + +_logger = logging.getLogger(__name__) + + +class PosAdyenController(http.Controller): + @http.route('/pos_adyen/notification', type='json', methods=['POST'], auth='none', csrf=False) + def notification(self): + data = json.loads(request.httprequest.data) + + # ignore if it's not a response to a sales request + if not data.get('SaleToPOIResponse'): + return + + _logger.info('notification received from adyen:\n%s', pprint.pformat(data)) + terminal_identifier = data['SaleToPOIResponse']['MessageHeader']['POIID'] + payment_method = request.env['pos.payment.method'].sudo().search([('adyen_terminal_identifier', '=', terminal_identifier)], limit=1) + + if payment_method: + # These are only used to see if the terminal is reachable, + # store the most recent ID we received. + if data['SaleToPOIResponse'].get('DiagnosisResponse'): + payment_method.adyen_latest_diagnosis = data['SaleToPOIResponse']['MessageHeader']['ServiceID'] + else: + payment_method.adyen_latest_response = json.dumps(data) + else: + _logger.error('received a message for a terminal not registered in Odoo: %s', terminal_identifier) |
