diff --git a/pinax/stripe/actions/customers.py b/pinax/stripe/actions/customers.py index 0f57a50c2..0263e8a61 100644 --- a/pinax/stripe/actions/customers.py +++ b/pinax/stripe/actions/customers.py @@ -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"]) diff --git a/pinax/stripe/actions/subscriptions.py b/pinax/stripe/actions/subscriptions.py index 16b9b4786..cfb45fe25 100644 --- a/pinax/stripe/actions/subscriptions.py +++ b/pinax/stripe/actions/subscriptions.py @@ -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