diff --git a/addons/payment_mercado_pago/models/payment_transaction.py b/addons/payment_mercado_pago/models/payment_transaction.py index 847e1fbb94c..5d6fd9e22f7 100644 --- a/addons/payment_mercado_pago/models/payment_transaction.py +++ b/addons/payment_mercado_pago/models/payment_transaction.py @@ -2,6 +2,7 @@ import logging import pprint +from urllib.parse import quote as url_quote from werkzeug import urls @@ -58,8 +59,9 @@ class PaymentTransaction(models.Model): """ base_url = self.provider_id.get_base_url() return_url = urls.url_join(base_url, MercadoPagoController._return_url) + sanitized_reference = url_quote(self.reference) webhook_url = urls.url_join( - base_url, f'{MercadoPagoController._webhook_url}/{self.reference}' + base_url, f'{MercadoPagoController._webhook_url}/{sanitized_reference}' ) # Append the reference to identify the transaction from the webhook notification data. # In the case where we are issuing a preference request in CLP or COP, we must ensure that diff --git a/addons/payment_mercado_pago/tests/test_payment_transaction.py b/addons/payment_mercado_pago/tests/test_payment_transaction.py index 28e40935413..a92649d4443 100644 --- a/addons/payment_mercado_pago/tests/test_payment_transaction.py +++ b/addons/payment_mercado_pago/tests/test_payment_transaction.py @@ -1,6 +1,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from unittest.mock import patch +from urllib.parse import quote as url_quote from odoo.tests import tagged from odoo.tools import mute_logger @@ -19,6 +20,7 @@ class TestPaymentTransaction(MercadoPagoCommon, PaymentHttpCommon): self.maxDiff = 10000 # Allow comparing large dicts. return_url = self._build_url('/payment/mercado_pago/return') webhook_url = self._build_url('/payment/mercado_pago/webhook') + sanitized_reference = url_quote(tx.reference) self.assertDictEqual(request_payload, { 'auto_return': 'all', 'back_urls': { @@ -33,7 +35,7 @@ class TestPaymentTransaction(MercadoPagoCommon, PaymentHttpCommon): 'title': tx.reference, 'unit_price': tx.amount, }], - 'notification_url': f'{webhook_url}/{tx.reference}', + 'notification_url': f'{webhook_url}/{sanitized_reference}', 'payer': { 'address': {'street_name': tx.partner_address, 'zip_code': tx.partner_zip}, 'email': tx.partner_email,