Skip to content

Commit

Permalink
add additional attribute check for applies_to before checking product…
Browse files Browse the repository at this point in the history
… id when redeeming gift subscriptions
  • Loading branch information
Moggach committed Jul 18, 2024
1 parent 4c68afb commit 248331a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/utils/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,14 @@ 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 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 248331a

Please sign in to comment.