diff --git a/addons/payment_stripe/const.py b/addons/payment_stripe/const.py index 04fea034957..c16820983b2 100644 --- a/addons/payment_stripe/const.py +++ b/addons/payment_stripe/const.py @@ -42,3 +42,53 @@ HANDLED_WEBHOOK_EVENTS = [ 'charge.refunded', # A refund has been issued. 'charge.refund.updated', # The refund status has changed, possibly from succeeded to failed. ] + +# The countries supported by Stripe. See https://stripe.com/global page. +SUPPORTED_COUNTRIES = { + 'AE', + 'AT', + 'AU', + 'BE', + 'BG', + 'BR', + 'CA', + 'CH', + 'CY', + 'CZ', + 'DE', + 'DK', + 'EE', + 'ES', + 'FI', + 'FR', + 'GB', + 'GI', # Beta + 'GR', + 'HK', + 'HR', # Beta + 'HU', + 'ID', # Beta + 'IE', + 'IT', + 'JP', + 'LI', # Beta + 'LT', + 'LU', + 'LV', + 'MT', + 'MX', + 'MY', + 'NL', + 'NO', + 'NZ', + 'PH', # Beta + 'PL', + 'PT', + 'RO', + 'SE', + 'SG', + 'SI', + 'SK', + 'TH', # Beta + 'US', +} diff --git a/addons/website_payment/__manifest__.py b/addons/website_payment/__manifest__.py index 0e3927baed2..e286ab7acd6 100644 --- a/addons/website_payment/__manifest__.py +++ b/addons/website_payment/__manifest__.py @@ -15,6 +15,7 @@ This is a bridge module that adds multi-website support for payment acquirers. ], 'data': [ 'data/donation_data.xml', + 'data/ir_action_data.xml', 'views/payment_acquirer.xml', 'views/res_config_settings_views.xml', 'views/donation_templates.xml', diff --git a/addons/website_payment/data/ir_action_data.xml b/addons/website_payment/data/ir_action_data.xml new file mode 100644 index 00000000000..0faf1568c16 --- /dev/null +++ b/addons/website_payment/data/ir_action_data.xml @@ -0,0 +1,14 @@ + + + + Connect to Stripe + + + code + +stripe = env.ref('payment.payment_acquirer_stripe') +menu_id = env.ref('website.menu_website_website_settings').id +action = stripe.action_stripe_connect_account(menu_id=menu_id) + + + diff --git a/addons/website_payment/models/__init__.py b/addons/website_payment/models/__init__.py index 8d2fcd92b39..fbe573108f2 100644 --- a/addons/website_payment/models/__init__.py +++ b/addons/website_payment/models/__init__.py @@ -5,3 +5,4 @@ from . import account_payment from . import payment_acquirer from . import payment_transaction from . import res_config_settings +from . import res_country diff --git a/addons/website_payment/models/res_config_settings.py b/addons/website_payment/models/res_config_settings.py index 8f2d7275c37..65eececbc71 100644 --- a/addons/website_payment/models/res_config_settings.py +++ b/addons/website_payment/models/res_config_settings.py @@ -18,6 +18,8 @@ class ResConfigSettings(models.TransientModel): compute='_compute_acquirers_state') module_payment_paypal = fields.Boolean( string='Paypal - Express Checkout') + is_stripe_supported_country = fields.Boolean( + related='company_id.country_id.is_stripe_supported_country') def _get_activated_acquirers(self): self.ensure_one() @@ -46,14 +48,13 @@ class ResConfigSettings(models.TransientModel): config.acquirers_state = 'none' def action_activate_stripe(self): + self.ensure_one() + if not self.is_stripe_supported_country: + return False stripe = self.env.ref('payment.payment_acquirer_stripe') stripe.button_immediate_install() - if stripe.state == 'disabled': - stripe.state = 'test' - return { - 'type': 'ir.actions.client', - 'tag': 'reload', - } + # This will make sure that a new request is made between the installation and the call to `action_stripe_connect_account`. + return self.env['ir.actions.actions']._for_xml_id('website_payment.action_stripe_connect_account') def action_configure_first_provider(self): self.ensure_one() diff --git a/addons/website_payment/models/res_country.py b/addons/website_payment/models/res_country.py new file mode 100644 index 00000000000..a47d7d47f9a --- /dev/null +++ b/addons/website_payment/models/res_country.py @@ -0,0 +1,15 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models +from odoo.addons.payment_stripe.const import SUPPORTED_COUNTRIES as STRIPE_SUPPORTED_COUNTRIES + + +class ResCountry(models.Model): + _inherit = 'res.country' + + is_stripe_supported_country = fields.Boolean(compute='_compute_is_stripe_supported_country') + + @api.depends('code') + def _compute_is_stripe_supported_country(self): + for country in self: + country.is_stripe_supported_country = country.code in STRIPE_SUPPORTED_COUNTRIES diff --git a/addons/website_payment/views/res_config_settings_views.xml b/addons/website_payment/views/res_config_settings_views.xml index e2d2c96cbe3..be1b3122596 100644 --- a/addons/website_payment/views/res_config_settings_views.xml +++ b/addons/website_payment/views/res_config_settings_views.xml @@ -18,7 +18,13 @@
-