From 893ef3ea23187ab061404d96bad8d06cf2142801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 25 Sep 2022 20:26:21 +0200 Subject: [PATCH] Expand sources from customer when needed issue11717 review421741003 (grafted from 1ab113a47dc2f6aae828f882437ac7aa859be6e4) --HG-- branch : 6.0 --- payment.py | 7 ++++--- tests/scenario_account_payment_stripe.rst | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/payment.py b/payment.py index 574601ae65..2aedda538f 100644 --- a/payment.py +++ b/payment.py @@ -1580,13 +1580,14 @@ class Customer(CheckoutMixin, DeactivableMixin, ModelSQL, ModelView): customer.save() Transaction().commit() - def retrieve(self): + def retrieve(self, **params): if not self.stripe_customer_id: return try: return stripe.Customer.retrieve( api_key=self.stripe_account.secret_key, - id=self.stripe_customer_id) + id=self.stripe_customer_id, + **params) except (stripe.error.RateLimitError, stripe.error.APIConnectionError) as e: logger.warning(str(e)) @@ -1596,7 +1597,7 @@ class Customer(CheckoutMixin, DeactivableMixin, ModelSQL, ModelView): if sources is not None: return sources sources = [] - customer = self.retrieve() + customer = self.retrieve(expand=['sources']) if customer: for source in customer.sources: name = source.id diff --git a/tests/scenario_account_payment_stripe.rst b/tests/scenario_account_payment_stripe.rst index 5778b59d40..3200a68019 100644 --- a/tests/scenario_account_payment_stripe.rst +++ b/tests/scenario_account_payment_stripe.rst @@ -241,7 +241,8 @@ Detach source:: >>> detach.form.source = source_id >>> detach.execute('detach') - >>> cus = stripe.Customer.retrieve(stripe_customer.stripe_customer_id) + >>> cus = stripe.Customer.retrieve( + ... stripe_customer.stripe_customer_id, expand=['sources']) >>> len(cus.sources) 0 >>> len(stripe.PaymentMethod.list(customer=cus.id, type='card'))