[FIX] website_payment: fix Stripe payment base URL configuration
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 <vcr@odoo.com>
This commit is contained in:
committed by
Valentin Chevalier
parent
9f24bb72ec
commit
3b569aed65
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user