changeset 1ab113a47dc2 in modules/account_payment_stripe:default
details: 
https://hg.tryton.org/modules/account_payment_stripe?cmd=changeset&node=1ab113a47dc2
description:
        Expand sources from customer when needed

        issue11717
        review421741003
diffstat:

 payment.py                                |  9 +++++----
 tests/scenario_account_payment_stripe.rst |  3 ++-
 2 files changed, 7 insertions(+), 5 deletions(-)

diffs (51 lines):

diff -r 2348d81854fc -r 1ab113a47dc2 payment.py
--- a/payment.py        Mon Sep 19 21:25:55 2022 +0200
+++ b/payment.py        Sun Sep 25 20:26:21 2022 +0200
@@ -1539,13 +1539,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))
@@ -1555,7 +1556,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
@@ -1723,7 +1724,7 @@
             Transaction().commit()
 
     def fetch_fingeprints(self):
-        customer = self.retrieve()
+        customer = self.retrieve(expand=['sources'])
         if customer:
             for source in customer.sources:
                 if hasattr(source, 'fingerprint'):
diff -r 2348d81854fc -r 1ab113a47dc2 tests/scenario_account_payment_stripe.rst
--- a/tests/scenario_account_payment_stripe.rst Mon Sep 19 21:25:55 2022 +0200
+++ 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'))

Reply via email to