changeset 78f8fb75f310 in modules/account_payment_stripe:6.2
details:
https://hg.tryton.org/modules/account_payment_stripe?cmd=changeset&node=78f8fb75f310
description:
Expand sources from customer when needed
issue11717
review421741003
(grafted from 1ab113a47dc2f6aae828f882437ac7aa859be6e4)
diffstat:
payment.py | 7 ++++---
tests/scenario_account_payment_stripe.rst | 3 ++-
2 files changed, 6 insertions(+), 4 deletions(-)
diffs (42 lines):
diff -r 730f547fbddb -r 78f8fb75f310 payment.py
--- a/payment.py Mon Nov 01 17:19:35 2021 +0100
+++ b/payment.py Sun Sep 25 20:26:21 2022 +0200
@@ -1497,13 +1497,14 @@
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))
@@ -1513,7 +1514,7 @@
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 -r 730f547fbddb -r 78f8fb75f310 tests/scenario_account_payment_stripe.rst
--- a/tests/scenario_account_payment_stripe.rst Mon Nov 01 17:19:35 2021 +0100
+++ b/tests/scenario_account_payment_stripe.rst Sun Sep 25 20:26:21 2022 +0200
@@ -241,7 +241,8 @@
>>> 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'))