Skip to content

Commit

Permalink
Merge pull request #477 from commonknowledge/fix-bug-redeeming-gift-s…
Browse files Browse the repository at this point in the history
…ubscriptions

Fix bug preventing redemption of gift subscriptions
  • Loading branch information
Moggach authored Jul 18, 2024
2 parents 4c68afb + 36ca2af commit a9b6ca3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/utils/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,17 @@ def create_gift_recipient_subscription(
promo_code = stripe.PromotionCode.retrieve(
promo_code_id, expand=["coupon.applies_to"]
)
if product_id in promo_code.coupon.applies_to.products:
# the gift card is fit for purpose
if (
hasattr(promo_code.coupon, 'applies_to') and
hasattr(promo_code.coupon.applies_to, 'products') and
product_id in promo_code.coupon.applies_to.products
): # the gift card is fit for purpose
discount_args = {"promotion_code": promo_code_id}

else:
# if they're in this situation of the gift card being for an old product
# get the right coupon for the target product
# if they're in this situation of the gift card being for an old product
# get the right coupon for the target product
coupon = get_gift_card_coupon(product_id)

# invalidate the gift card's promo code so it can't be used again
promo_code = stripe.PromotionCode.modify(promo_code_id, active=False)

Expand Down

0 comments on commit a9b6ca3

Please sign in to comment.