Skip to content

Commit

Permalink
BUG: fix coupon fetch for discount creation
Browse files Browse the repository at this point in the history
  • Loading branch information
otistamp committed Mar 7, 2017
1 parent dceb089 commit e04f68d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pinax/stripe/actions/customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def sync_customer(customer, cu=None):
customer.save()
if cu.get("discount", None):
try:
coupon = models.Coupon.objects.get(stripe_id=cu["discount"]["id"])
coupon = models.Coupon.objects.get(stripe_id=cu["discount"]["coupon"]["id"])
except models.Coupon.DoesNotExist:
raise models.Coupon.DoesNotExist("Sync coupons before syncing customers.")
start = utils.convert_tstamp(cu["discount"]["start"])
Expand Down
6 changes: 5 additions & 1 deletion pinax/stripe/actions/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ def sync_subscription_from_stripe_data(customer, subscription):
if subscription.get("discount", None):
start = utils.convert_tstamp(subscription["discount"]["start"])
end = utils.convert_tstamp(subscription["discount"]["end"]) if subscription["discount"]["end"] else None
models.Discount.objects.get_or_create(subscription=sub, start=start, end=end)
try:
coupon = models.Coupon.objects.get(stripe_id=subscription["discount"]["coupon"]["id"])
except models.Coupon.DoesNotExist:
raise models.Coupon.DoesNotExist("Sync coupons before syncing subscriptions.")
models.Discount.objects.get_or_create(subscription=sub, coupon=coupon, start=start, end=end)
return sub


Expand Down

0 comments on commit e04f68d

Please sign in to comment.