From de782a680de8e5a2d7c89b982c485ca29da34b3a Mon Sep 17 00:00:00 2001 From: Saurabh Choraria Date: Mon, 3 Jul 2023 06:57:15 +0000 Subject: [PATCH] [FIX] payment_stripe: handle error for unsupported country while stripe setup Currently, When a user tries to set up a stripe account but his country is not supported by stripe then he receives a error message at backend side and a ValidationError ("Stripe Proxy: An error occurred when communicating with the proxy.") on frontend side. After applying this commit the error message will be updated to a warning level which will reduce the noise in sentry. I have also added a condition in 'action_stripe_connect_account' method to check whether the country is supported by stripe or not and if it is not supported the user will be redirected to other payment providers page. sentry-3935758343 closes odoo/odoo#128140 X-original-commit: c7b0d8eebe686d9c38f9f5c71577c80718ffb791 Signed-off-by: Antoine Vandevenne (anv) --- addons/payment_stripe/i18n/payment_stripe.pot | 16 ++++++++++++++++ addons/payment_stripe/models/payment_provider.py | 14 ++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/addons/payment_stripe/i18n/payment_stripe.pot b/addons/payment_stripe/i18n/payment_stripe.pot index ea5878a13e7..42cb9bfd6e9 100644 --- a/addons/payment_stripe/i18n/payment_stripe.pot +++ b/addons/payment_stripe/i18n/payment_stripe.pot @@ -49,6 +49,13 @@ msgstr "" msgid "No transaction found matching reference %s." msgstr "" +#. module: payment_stripe +#. odoo-python +#: code:addons/payment_stripe/models/payment_provider.py:0 +#, python-format +msgid "Other Payment Providers" +msgstr "" + #. module: payment_stripe #: model:ir.model,name:payment_stripe.model_payment_acquirer msgid "Payment Acquirer" @@ -113,6 +120,15 @@ msgstr "" msgid "Stripe" msgstr "" +#. module: payment_stripe +#. odoo-python +#: code:addons/payment_stripe/models/payment_provider.py:0 +#, python-format +msgid "" +"Stripe Connect is not available in your country, please use another payment " +"provider." +msgstr "" + #. module: payment_stripe #: model:ir.model.fields,field_description:payment_stripe.field_payment_transaction__stripe_payment_intent msgid "Stripe Payment Intent ID" diff --git a/addons/payment_stripe/models/payment_provider.py b/addons/payment_stripe/models/payment_provider.py index 0e7a803b87c..5fa2b26856d 100644 --- a/addons/payment_stripe/models/payment_provider.py +++ b/addons/payment_stripe/models/payment_provider.py @@ -7,7 +7,7 @@ import requests from werkzeug.urls import url_encode, url_join, url_parse from odoo import _, api, fields, models -from odoo.exceptions import UserError, ValidationError +from odoo.exceptions import RedirectWarning, UserError, ValidationError from odoo.addons.payment_stripe import utils as stripe_utils from odoo.addons.payment_stripe import const @@ -133,6 +133,16 @@ class PaymentProvider(models.Model): """ self.ensure_one() + if self.env.company.country_id.code not in const.SUPPORTED_COUNTRIES: + raise RedirectWarning( + _( + "Stripe Connect is not available in your country, please use another payment" + " provider." + ), + self.env.ref('payment.action_payment_provider').id, + _("Other Payment Providers"), + ) + if self.state == 'enabled': self.env['onboarding.onboarding.step'].action_validate_step_payment_provider() action = {'type': 'ir.actions.act_window_close'} @@ -415,7 +425,7 @@ class PaymentProvider(models.Model): response_content = response.json() if response_content.get('error'): # An exception was raised on the proxy error_data = response_content['error']['data'] - _logger.error("request forwarded with error: %s", error_data['message']) + _logger.warning("request forwarded with error: %s", error_data['message']) raise ValidationError(_("Stripe Proxy error: %(error)s", error=error_data['message'])) return response_content.get('result', {})