From 3abe5f6fc5e44d3515fb8221d50f0ce91ee69d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 22 Aug 2024 18:33:39 +0200 Subject: [PATCH] Add button to update Stripe customer Closes #13468 --- modules/account_payment_stripe/CHANGELOG | 1 + modules/account_payment_stripe/payment.py | 7 +++++++ modules/account_payment_stripe/payment.xml | 5 +++++ modules/account_payment_stripe/view/customer_form.xml | 1 + modules/account_payment_stripe/view/customer_list.xml | 1 + 5 files changed, 15 insertions(+) diff --git a/modules/account_payment_stripe/CHANGELOG b/modules/account_payment_stripe/CHANGELOG index 140b9876e6..9597b81aea 100644 --- a/modules/account_payment_stripe/CHANGELOG +++ b/modules/account_payment_stripe/CHANGELOG @@ -1,3 +1,4 @@ +* Add button to update customer * Add Stripe pull button to payment * Warn when changing credential diff --git a/modules/account_payment_stripe/payment.py b/modules/account_payment_stripe/payment.py index afb8b3553b..b900681237 100644 --- a/modules/account_payment_stripe/payment.py +++ b/modules/account_payment_stripe/payment.py @@ -1459,6 +1459,10 @@ class Customer(CheckoutMixin, DeactivableMixin, ModelSQL, ModelView): 'invisible': ~Eval('stripe_checkout_needed', False), 'depends': ['stripe_checkout_needed'], }, + 'stripe_update': { + 'invisible': ~Eval('stripe_customer_id'), + 'depends': ['stripe_customer_id'], + }, 'detach_source': { 'invisible': ~Eval('stripe_customer_id'), 'depends': ['stripe_customer_id'], @@ -1572,8 +1576,11 @@ class Customer(CheckoutMixin, DeactivableMixin, ModelSQL, ModelView): } @classmethod + @ModelView.button def stripe_update(cls, customers): for customer in customers: + if not customer.stripe_customer_id: + continue try: stripe.Customer.modify( customer.stripe_customer_id, diff --git a/modules/account_payment_stripe/payment.xml b/modules/account_payment_stripe/payment.xml index be4eec4c86..95d7af04b2 100644 --- a/modules/account_payment_stripe/payment.xml +++ b/modules/account_payment_stripe/payment.xml @@ -273,6 +273,11 @@ this repository contains the full copyright notices and license terms. --> stripe_checkout Add Card + + account.payment.stripe.customer + stripe_update + Update + account.payment.stripe.customer detach_source diff --git a/modules/account_payment_stripe/view/customer_form.xml b/modules/account_payment_stripe/view/customer_form.xml index f9f58fc0cd..bc94c319dd 100644 --- a/modules/account_payment_stripe/view/customer_form.xml +++ b/modules/account_payment_stripe/view/customer_form.xml @@ -13,6 +13,7 @@ this repository contains the full copyright notices and license terms. -->