From c81863894e18a46be11172c7c1743c563ff6fc31 Mon Sep 17 00:00:00 2001 From: Janusz Kamienski Date: Wed, 6 Feb 2019 13:52:16 +0100 Subject: [PATCH] fix charges/invoices listing by using stripe API as suggested in https://github.com/pinax/pinax-stripe/issues/623\#issuecomment-455814540 --- pinax/stripe/actions/charges.py | 2 +- pinax/stripe/actions/invoices.py | 2 +- pinax/stripe/tests/test_actions.py | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pinax/stripe/actions/charges.py b/pinax/stripe/actions/charges.py index 375f8ffda..f781a8fc2 100644 --- a/pinax/stripe/actions/charges.py +++ b/pinax/stripe/actions/charges.py @@ -160,7 +160,7 @@ def sync_charges_for_customer(customer): Args: customer: a pinax.stripe.models.Customer object """ - for charge in customer.stripe_customer.charges().data: + for charge in stripe.Charge.auto_paging_iter(customer=customer.stripe_id): sync_charge_from_stripe_data(charge) diff --git a/pinax/stripe/actions/invoices.py b/pinax/stripe/actions/invoices.py index 100b621c7..943d90b8e 100644 --- a/pinax/stripe/actions/invoices.py +++ b/pinax/stripe/actions/invoices.py @@ -131,7 +131,7 @@ def sync_invoices_for_customer(customer): Args: customer: the customer for whom to synchronize all invoices """ - for invoice in customer.stripe_customer.invoices().data: + for invoice in stripe.Invoice.auto_paging_iter(customer=customer.stripe_id): sync_invoice_from_stripe_data(invoice, send_receipt=False) diff --git a/pinax/stripe/tests/test_actions.py b/pinax/stripe/tests/test_actions.py index 4d5dc1b40..e52cd2a9b 100644 --- a/pinax/stripe/tests/test_actions.py +++ b/pinax/stripe/tests/test_actions.py @@ -1666,17 +1666,17 @@ def test_sync_customer_purged_remotely_not_locally(self, RetrieveMock, SyncPayme self.assertFalse(SyncSubscriptionMock.called) self.assertTrue(PurgeLocalMock.called) - @patch("pinax.stripe.actions.invoices.sync_invoice_from_stripe_data") + @patch("stripe.Invoice.auto_paging_iter") @patch("stripe.Customer.retrieve") - def test_sync_invoices_for_customer(self, RetreiveMock, SyncMock): - RetreiveMock().invoices().data = [Mock()] + def test_sync_invoices_for_customer(self, RetrieveMock, SyncMock): + RetrieveMock.return_value = [Mock()] invoices.sync_invoices_for_customer(self.customer) self.assertTrue(SyncMock.called) - @patch("pinax.stripe.actions.charges.sync_charge_from_stripe_data") + @patch("stripe.Charge.auto_paging_iter") @patch("stripe.Customer.retrieve") - def test_sync_charges_for_customer(self, RetreiveMock, SyncMock): - RetreiveMock().charges().data = [Mock()] + def test_sync_charges_for_customer(self, RetrieveMock, SyncMock): + RetrieveMock.return_value = [Mock()] charges.sync_charges_for_customer(self.customer) self.assertTrue(SyncMock.called)