From f9e88b2fd3717295630bb4acba619ee618a02604 Mon Sep 17 00:00:00 2001 From: Chris Streeter Date: Tue, 4 Dec 2018 20:34:01 -0800 Subject: [PATCH] Do not call deprecated method on stripe.Customer The invoices method was removed on the stripe.Customer object in https://github.com/stripe/stripe-python/commit/d416e9e68c8eba804535541ce29d2d8f2d22b08c This replaces that same logic to fetch the invoices and sync them and does it within the method itself. This should be backwards compatible with stripe-python < 2.0 as well as the 2.0 and up release. Fixes https://github.com/pinax/pinax-stripe/issues/582 --- pinax/stripe/actions/invoices.py | 4 +++- pinax/stripe/tests/test_actions.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pinax/stripe/actions/invoices.py b/pinax/stripe/actions/invoices.py index 100b621c7..47e16d435 100644 --- a/pinax/stripe/actions/invoices.py +++ b/pinax/stripe/actions/invoices.py @@ -131,7 +131,9 @@ def sync_invoices_for_customer(customer): Args: customer: the customer for whom to synchronize all invoices """ - for invoice in customer.stripe_customer.invoices().data: + stripe_customer = customer.stripe_customer + stripe_invoices = stripe.Invoice.list(customer=stripe_customer.id) + for invoice in stripe_invoices.data: 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..6b459cbe8 100644 --- a/pinax/stripe/tests/test_actions.py +++ b/pinax/stripe/tests/test_actions.py @@ -1667,9 +1667,11 @@ def test_sync_customer_purged_remotely_not_locally(self, RetrieveMock, SyncPayme self.assertTrue(PurgeLocalMock.called) @patch("pinax.stripe.actions.invoices.sync_invoice_from_stripe_data") + @patch("stripe.Invoice.list") @patch("stripe.Customer.retrieve") - def test_sync_invoices_for_customer(self, RetreiveMock, SyncMock): + def test_sync_invoices_for_customer(self, RetreiveMock, InvoicesMock, SyncMock): RetreiveMock().invoices().data = [Mock()] + InvoicesMock().data = [Mock()] invoices.sync_invoices_for_customer(self.customer) self.assertTrue(SyncMock.called)