1# -*- coding: utf-8 -*- 2 3import json 4import logging 5import pprint 6import werkzeug 7 8from odoo import http 9from odoo.http import request 10 11_logger = logging.getLogger(__name__) 12 13 14class AdyenController(http.Controller): 15 _return_url = '/payment/adyen/return/' 16 17 @http.route([ 18 '/payment/adyen/return', 19 ], type='http', auth='public', csrf=False) 20 def adyen_return(self, **post): 21 _logger.info('Beginning Adyen form_feedback with post data %s', pprint.pformat(post)) # debug 22 if post.get('authResult') not in ['CANCELLED']: 23 request.env['payment.transaction'].sudo().form_feedback(post, 'adyen') 24 return werkzeug.utils.redirect('/payment/process') 25 26 @http.route([ 27 '/payment/adyen/notification', 28 ], type='http', auth='public', methods=['POST'], csrf=False) 29 def adyen_notification(self, **post): 30 tx = post.get('merchantReference') and request.env['payment.transaction'].sudo().search([('reference', 'in', [post.get('merchantReference')])], limit=1) 31 if post.get('eventCode') in ['AUTHORISATION'] and tx: 32 states = (post.get('merchantReference'), post.get('success'), tx.state) 33 if (post.get('success') == 'true' and tx.state == 'done') or (post.get('success') == 'false' and tx.state in ['cancel', 'error']): 34 _logger.info('Notification from Adyen for the reference %s: received %s, state is %s', states) 35 else: 36 _logger.warning('Notification from Adyen for the reference %s: received %s but state is %s', states) 37 return '[accepted]' 38