Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix charges/invoices listing by using stripe API #630

Open
wants to merge 1 commit into
base: original
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pinax/stripe/actions/charges.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion pinax/stripe/actions/invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
12 changes: 6 additions & 6 deletions pinax/stripe/tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is correct. I believe that stripe.Customer.retrieve isn't actually called anymore. You would need to keep the @patch("pinax.stripe.actions.invoices.sync_invoice_from_stripe_data") and remove the @patch("stripe.Customer.retrieve") patch, which would mean that stripe.Invoice.auto_paging_iter is set to the RetrieveMock and pinax.stripe.actions.invoices.sync_invoice_from_stripe_data is set to the SyncMock.

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above should also apply here.

RetrieveMock.return_value = [Mock()]
charges.sync_charges_for_customer(self.customer)
self.assertTrue(SyncMock.called)

Expand Down