Skip to content

Commit

Permalink
Correct creating charges
Browse files Browse the repository at this point in the history
  • Loading branch information
poxip committed Dec 13, 2017
1 parent 31f74a4 commit 9b0a615
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
5 changes: 1 addition & 4 deletions aa_stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,7 @@ def charge(self):
stripe.api_key = stripe_settings.API_KEY
customer = StripeCustomer.get_latest_active_customer_for_user(self.user)
self.customer = customer
if not customer.default_card:
raise ValidationError(_("Customer must have a default_card set to create charge at Stripe"))

if customer:
if customer and customer.default_card:
try:
stripe_charge = stripe.Charge.create(
amount=self.amount,
Expand Down
8 changes: 0 additions & 8 deletions tests/test_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,3 @@ def test_refund(self, refund_create_mocked):
with self.assertRaises(StripeMethodNotAllowed):
charge.refund()
self.assertTrue(charge.is_refunded)

def test_no_default_card(self):
# make sure charging with no default card set is disallowed
self._create_customer()
self.assertEqual(StripeCard.objects.count(), 0)
charge = StripeCharge.objects.create(user=self.user, amount=10, customer=self.customer, description="ABC")
with self.assertRaises(ValidationError):
charge.charge()

0 comments on commit 9b0a615

Please sign in to comment.