From 3b569aed65bbefbffa928049f51d8e8710bf0ee3 Mon Sep 17 00:00:00 2001 From: "Mehdi Outagant (MOU)" Date: Tue, 16 Jan 2024 09:29:05 +0000 Subject: [PATCH] [FIX] website_payment: fix Stripe payment base URL configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - Configure a non-ASCII custom domain (Punycode encoded) on a database (e.g. `test-môu.com` <> `xn--test-mu-y0a.com`). - Setup test API keys on a Stripe account ("Publishable" & "Secret"). - Install and activate the Stripe payment acquirer (in "Test Mode"). - Go to the Stripe Odoo config (Invoicing > Payment Acquirers > Stripe). - Configure Stripe API keys and click on the button to "GENERATE YOUR WEBHOOK" > traceback: `Invalid URL: Non-ASCII characters in URLs must be percent-encoded in order for the URL to be valid`. The same error occurs in every interaction with the Stripe API. The `get_base_url()` refactoring (exactly [1]) introduced a way to get the most suited URL for a record in the following order: `record.website_id` > `record.company_id.website_id` > The ICP: `web.base.url`. For payment acquirers, and to handle multi-website scenarios, the code uses the base URL: `httprequest.url_root` which explains why the error occurs even when the domain name is configured in punycode. The goal of this commit is to fix this behavior by correctly encoding the returned base URL. [1] https://github.com/odoo/odoo/commit/92175d3341b576676a550c60db7c759f71cb17ea opw-3619608 closes odoo/odoo#149947 X-original-commit: ffb19d0481f623c969266b14dce2b78127ec2391 Signed-off-by: Valentin Chevalier --- addons/website_payment/models/payment_provider.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/website_payment/models/payment_provider.py b/addons/website_payment/models/payment_provider.py index 7da47039c63..694d2fc0bf6 100644 --- a/addons/website_payment/models/payment_provider.py +++ b/addons/website_payment/models/payment_provider.py @@ -1,5 +1,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. +from werkzeug.urls import iri_to_uri + from odoo import api, fields, models from odoo.http import request @@ -34,5 +36,9 @@ class PaymentProvider(models.Model): def get_base_url(self): # Give priority to url_root to handle multi-website cases if request and request.httprequest.url_root: - return request.httprequest.url_root + # Some domain names can use non-Latin script or alphabet or the Latin + # alphabet-based characters with diacritics or ligatures. They are + # stored as ASCII strings using Punycode transcription in the DNS + # system and need to be converted to send to external APIs. + return iri_to_uri(request.httprequest.url_root) return super().get_base_url()