diff --git a/addons/payment_adyen/controllers/main.py b/addons/payment_adyen/controllers/main.py index 1f8cf0afce3..917361c5314 100644 --- a/addons/payment_adyen/controllers/main.py +++ b/addons/payment_adyen/controllers/main.py @@ -246,7 +246,7 @@ class AdyenController(http.Controller): # Redirect the user to the status page return request.redirect('/payment/status') - @http.route(_webhook_url, type='json', auth='public') + @http.route(_webhook_url, type='http', methods=['POST'], auth='public', csrf=False) def adyen_webhook(self): """ Process the data sent by Adyen to the webhook based on the event code. @@ -256,7 +256,7 @@ class AdyenController(http.Controller): :return: The '[accepted]' string to acknowledge the notification :rtype: str """ - data = request.dispatcher.jsonrequest + data = request.get_json_data() for notification_item in data['notificationItems']: notification_data = notification_item['NotificationRequestItem'] @@ -291,7 +291,7 @@ class AdyenController(http.Controller): except ValidationError: # Acknowledge the notification to avoid getting spammed _logger.exception("unable to handle the notification data; skipping to acknowledge") - return '[accepted]' # Acknowledge the notification + return request.make_json_response('[accepted]') # Acknowledge the notification @staticmethod def _verify_notification_signature(notification_data, tx_sudo): diff --git a/addons/payment_adyen/tests/test_adyen.py b/addons/payment_adyen/tests/test_adyen.py index d7db2ce0dac..93bf94bcb9c 100644 --- a/addons/payment_adyen/tests/test_adyen.py +++ b/addons/payment_adyen/tests/test_adyen.py @@ -470,7 +470,7 @@ class AdyenTest(AdyenCommon, PaymentHttpCommon): ): response = self._make_json_request(url, data=payload).json() self.assertEqual( - response['result'], '[accepted]', msg="The webhook should always respond '[accepted]'", + response, '[accepted]', msg="The webhook should always respond '[accepted]'", ) @mute_logger('odoo.addons.payment_adyen.controllers.main') diff --git a/addons/payment_stripe/controllers/main.py b/addons/payment_stripe/controllers/main.py index 0b94f44a01c..84c3630e5dd 100644 --- a/addons/payment_stripe/controllers/main.py +++ b/addons/payment_stripe/controllers/main.py @@ -81,14 +81,14 @@ class StripeController(http.Controller): # Redirect the user to the status page return request.redirect('/payment/status') - @http.route(_webhook_url, type='json', auth='public') + @http.route(_webhook_url, type='http', methods=['POST'], auth='public', csrf=False) def stripe_webhook(self): """ Process the notification data sent by Stripe to the webhook. :return: An empty string to acknowledge the notification :rtype: str """ - event = json.loads(request.httprequest.data) + event = request.get_json_data() _logger.info("notification received from Stripe with data:\n%s", pprint.pformat(event)) try: if event['type'] in HANDLED_WEBHOOK_EVENTS: @@ -143,7 +143,8 @@ class StripeController(http.Controller): refund_tx_sudo = self._create_refund_tx_from_refund(tx_sudo, refund) self._include_refund_in_notification_data(refund, data) refund_tx_sudo._handle_notification_data('stripe', data) - return '' # Don't handle the notification data for the source transaction. + # Don't handle the notification data for the source transaction. + return request.make_json_response('') elif event['type'] == 'charge.refund.updated': # Refund operation (with update). # A refund was updated by Stripe after it was already processed (possibly to # cancel it). This can happen when the customer's payment method can no longer @@ -155,7 +156,7 @@ class StripeController(http.Controller): tx_sudo._handle_notification_data('stripe', data) except ValidationError: # Acknowledge the notification to avoid getting spammed _logger.exception("unable to handle the notification data; skipping to acknowledge") - return '' + return request.make_json_response('') @staticmethod def _include_payment_intent_in_notification_data(payment_intent, notification_data):