[FIX] payment_stripe: prevent enabling test mode for connected accounts
The Stripe Connect onboarding only allows to create production accounts. This is problematic because, before this commit, it was possible to set the state of an acquirer linked to a connected account to 'test', even though the payments would actually be made on the live environment of Stripe. Additionally, this commit fixes a minor display issue that caused the "Connect" button to be shown when an API key was set, while it should be hidden as soon as an API key is set. closes odoo/odoo#85444 X-original-commit: 4f9b19b9a9891cb0c39dcb88991de174be60cef9 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
This commit is contained in:
@@ -6,8 +6,8 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 15.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2022-01-11 09:46+0000\n"
|
||||
"PO-Revision-Date: 2022-01-11 09:46+0000\n"
|
||||
"POT-Creation-Date: 2022-02-22 14:45+0000\n"
|
||||
"PO-Revision-Date: 2022-02-22 14:45+0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
@@ -191,6 +191,14 @@ msgid ""
|
||||
"You cannot create a Stripe Webhook if your Stripe Secret Key is not set."
|
||||
msgstr ""
|
||||
|
||||
#. module: payment_stripe
|
||||
#: code:addons/payment_stripe/models/payment_acquirer.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You cannot set the acquirer to Test Mode while it is linked with your Stripe"
|
||||
" account."
|
||||
msgstr ""
|
||||
|
||||
#. module: payment_stripe
|
||||
#: code:addons/payment_stripe/models/payment_acquirer.py:0
|
||||
#, python-format
|
||||
|
||||
@@ -6,7 +6,7 @@ import uuid
|
||||
import requests
|
||||
from werkzeug.urls import url_join, url_encode
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from odoo.addons.payment_stripe.const import API_VERSION, PROXY_URL, WEBHOOK_HANDLED_EVENTS
|
||||
@@ -32,6 +32,41 @@ class PaymentAcquirer(models.Model):
|
||||
"authenticate the messages sent from Stripe to Odoo.",
|
||||
groups='base.group_system')
|
||||
|
||||
#=== CONSTRAINT METHODS ===#
|
||||
|
||||
@api.constrains('state', 'stripe_publishable_key', 'stripe_secret_key')
|
||||
def _check_state_of_connected_account_is_never_test(self):
|
||||
""" Check that the acquirer of a connected account can never been set to 'test'.
|
||||
|
||||
This constraint is defined in the present module to allow the export of the translation
|
||||
string of the `ValidationError` that can be raised by the internal module responsible for
|
||||
Stripe Connect, although this constraint depends on a field that is defined in that external
|
||||
module.
|
||||
Additionally, having the field defined in the external module prevents from using it
|
||||
as a trigger for this constraint. This is however not a problem because the field `state` is
|
||||
used as trigger, and we always write on `state` when we write on the internal field.
|
||||
|
||||
:return: None
|
||||
"""
|
||||
for acquirer in self:
|
||||
if acquirer.state == 'test' and acquirer._stripe_has_connected_account():
|
||||
raise ValidationError(_(
|
||||
"You cannot set the acquirer to Test Mode while it is linked with your Stripe "
|
||||
"account."
|
||||
))
|
||||
|
||||
def _stripe_has_connected_account(self):
|
||||
""" Return whether the acquirer is linked to a connected Stripe account.
|
||||
|
||||
Note: This method is overridden by the internal module responsible for Stripe Connect.
|
||||
Note: self.ensure_one()
|
||||
|
||||
:return: Whether the acquirer is linked to a connected Stripe account
|
||||
:rtype: bool
|
||||
"""
|
||||
self.ensure_one()
|
||||
return False
|
||||
|
||||
# === ACTION METHODS === #
|
||||
|
||||
def action_stripe_connect_account(self, menu_id=None):
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<xpath expr="//group[@name='acquirer']" position="before">
|
||||
<group invisible="context.get('stripe_onboarding', False)"
|
||||
name="stripe_onboarding_group"
|
||||
attrs="{'invisible': ['|', ('provider', '!=', 'stripe'), '&', ('stripe_secret_key', '!=', False), ('stripe_publishable_key', '!=', False)]}">
|
||||
attrs="{'invisible': ['|', '|', ('provider', '!=', 'stripe'), ('stripe_secret_key', '!=', False), ('stripe_publishable_key', '!=', False)]}">
|
||||
<button string="Connect Stripe"
|
||||
type="object"
|
||||
name="action_stripe_connect_account"
|
||||
|
||||
Reference in New Issue
Block a user