[FIX] payment_adyen: back-port of 3dafb19

opw-672504
This commit is contained in:
Denis Ledoux 2016-03-21 13:01:40 +01:00
parent cc335879a7
commit 037257b887
1 changed files with 15 additions and 1 deletions

View File

@ -18,7 +18,7 @@ class AdyenController(http.Controller):
_return_url = '/payment/adyen/return/'
@http.route([
'/payment/adyen/return/',
'/payment/adyen/return',
], type='http', auth='none')
def adyen_return(self, **post):
_logger.info('Beginning Adyen form_feedback with post data %s', pprint.pformat(post)) # debug
@ -29,3 +29,17 @@ class AdyenController(http.Controller):
custom = json.loads(post.pop('merchantReturnData', '{}'))
return_url = custom.pop('return_url', '/')
return werkzeug.utils.redirect(return_url)
@http.route([
'/payment/adyen/notification',
], type='http', auth='none', methods=['POST'])
def adyen_notification(self, **post):
tx_id = post.get('merchantReference') and request.registry['payment.transaction'].search(request.cr, SUPERUSER_ID, [('reference', 'in', [post.get('merchantReference')])], limit=1, context=request.context)
if post.get('eventCode') in ['AUTHORISATION'] and tx_id:
tx = request.registry['payment.transaction'].browse(request.cr, SUPERUSER_ID, tx_id, context=request.context)
states = (post.get('merchantReference'), post.get('success'), tx.state)
if (post.get('success') == 'true' and tx.state == 'done') or (post.get('success') == 'false' and tx.state in ['cancel', 'error']):
_logger.info('Notification from Adyen for the reference %s: received %s, state is %s', states)
else:
_logger.warning('Notification from Adyen for the reference %s: received %s but state is %s', states)
return '[accepted]'