Skip to content

Commit

Permalink
(NOBIDS) frontend: handle stripe-promo-codes when creating checkout-s…
Browse files Browse the repository at this point in the history
…essions (#2935)
  • Loading branch information
guybrush authored Aug 14, 2024
1 parent 9a4e4c4 commit 00aeeca
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions handlers/stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func StripeCreateCheckoutSession(w http.ResponseWriter, r *http.Request) {
var req struct {
Price string `json:"priceId"`
AddonQuantity int64 `json:"addonQuantity"`
PromotionCode string `json:"promotionCode"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -159,6 +160,14 @@ func StripeCreateCheckoutSession(w http.ResponseWriter, r *http.Request) {
}
}

if req.PromotionCode != "" {
params.Discounts = []*stripe.CheckoutSessionDiscountParams{
{
Coupon: stripe.String(req.PromotionCode),
},
}
}

s, err := session.New(params)
if err != nil {
logger.WithError(err).Error("failed to create a new stripe checkout session")
Expand Down

0 comments on commit 00aeeca

Please sign in to comment.