Skip to content

Commit

Permalink
Catch InvalidRequestError thrown by invoices.create
Browse files Browse the repository at this point in the history
I've been getting "Nothing to invoice for customer" thrown by the
create(customer) call, and this small change fixes the error.
  • Loading branch information
meshy committed Mar 9, 2017
1 parent ec14b69 commit 5ffd66a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pinax/stripe/actions/invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def create_and_pay(customer):
Returns:
True, if invoice was created, False if there was an error
"""
invoice = create(customer)
try:
invoice = create(customer)
if invoice.amount_due > 0:
invoice.pay()
return True
Expand Down
5 changes: 5 additions & 0 deletions pinax/stripe/tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ def test_create_and_pay_invalid_request_error(self, CreateMock):
self.assertFalse(invoices.create_and_pay(Mock()))
self.assertTrue(invoice.pay.called)

@patch("stripe.Invoice.create")
def test_create_and_pay_invalid_request_error_on_create(self, CreateMock):
CreateMock.side_effect = stripe.InvalidRequestError("Bad", "error")
self.assertFalse(invoices.create_and_pay(Mock()))


class RefundsTests(TestCase):

Expand Down

0 comments on commit 5ffd66a

Please sign in to comment.