From fbfca5b5a3ad6d8cfed628d8aea53a20c5134c22 Mon Sep 17 00:00:00 2001 From: Patrick Pfeiffer Date: Wed, 14 Aug 2024 10:58:16 +0200 Subject: [PATCH] (NOBIDS) frontend: handle stripe-promo-codes when creating checkout-sessions --- handlers/stripe.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/handlers/stripe.go b/handlers/stripe.go index a118439feb..667ec01722 100644 --- a/handlers/stripe.go +++ b/handlers/stripe.go @@ -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) @@ -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")