#pastyghost_best-practices

1 messages ¡ Page 1 of 1 (latest)

foggy ravineBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1326936173708443659

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

rustic sun
#

So, you'd need to restrict by customer on your end

#

Or only share coupon with a specific customer

karmic jolt
#

Gotcha - so "once" just really means "once per purchase"?

rustic sun
#

It means it can only be used once period

karmic jolt
#

Per customer or across my entire store?

rustic sun
#

entire store

#

You can't restrict a coupon to a customer

karmic jolt
#

OK - so does that mean every customer can use it only once, or that it can only ever be used once?

rustic sun
#

Oh sorry I linked the wrong param

#

^ would mean it can only ever be used once

#

So you'd create 1 coupon per each customer

karmic jolt
#

Okay, I think we're talking past each other here. What I'd like to do is create 1 coupon that can only be used once per purchase.

#

Any number of customers can use it, but only once per purchase.

rustic sun
#

Are these one-time or subscription purchases?

#

Because duration does do this but only for subscription

karmic jolt
#

They're one-time purchases.

#

I just don't know how many customers I'm going to have, and I just want to have one code to give out.

rustic sun
#

Do you only want the coupon to be used for a customer's first time purchase? Or is it a possibility that they've paid before without the coupon and you want them to be able to use it on their 3rd purchase, for example?

karmic jolt
#

First time purchase.

rustic sun
karmic jolt
#

Gotcha, thank you!

#

I have a follow-on question about applying that coupon via the API. Should I create a separate thread for that?

rustic sun
#

No you can ask in here

karmic jolt
#

So I want the coupon to be optional.

#

I want them to have to enter the coupon code.

rustic sun
#

How are you accepting payments?

karmic jolt
#

But it looks like this:

params := &stripe.CheckoutSessionParams{
  PaymentMethodTypes: stripe.StringSlice([]string{
    "card",
  }),
  LineItems: []*stripe.CheckoutSessionLineItemParams{
      &stripe.CheckoutSessionLineItemParams{
          Price: stripe.String("{{PRICE_ID}}"),
          Quantity: stripe.Int64(1),
      },
  },
  Mode: stripe.String("subscription"),
  Discounts: []*stripe.CheckoutSessionDiscountParams{
      &stripe.CheckoutSessionDiscountParams{
          Coupon: stripe.String("{{COUPON_ID}}"),
      },
  },
  SuccessURL: stripe.String("https://example.com/success"),
  CancelURL: stripe.String("https://example.com/cancel"),
}
#

auto applies it.

#

CheckoutSessions.

rustic sun
#

Yeah don't pass it there

#

One sec

#

The will allow them to enter the promo code

#

Note coupon represents the discount in Stripe

#

Promo code represents the code the customer enters

#

You need to create a promo code for a coupon

#

And the promo code is what they'll enter

#

And that is what will have the first time purchase restriction

karmic jolt
#

Gotcha, thank you!

rustic sun
#

No problem

karmic jolt
#

So this is my code:

if (lineItems.ShippingID == "") {
        params = &stripe.CheckoutSessionParams{
            UIMode: stripe.String("embedded"),
            ReturnURL: stripe.String(domain + "/success?session_id={CHECKOUT_SESSION_ID}"),
            LineItems: []*stripe.CheckoutSessionLineItemParams{
                {
                    Price: stripe.String((lineItems.ItemID)),
                    Quantity: stripe.Int64(1),
                },
            },
            Mode: stripe.String(string(stripe.CheckoutSessionModePayment)),
            AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{Enabled: stripe.Bool(true)},
            AllowPromotionCodes: stripe.Bool(true),
        }
    } else {
        params = &stripe.CheckoutSessionParams{
            UIMode: stripe.String("embedded"),
            ReturnURL: stripe.String(domain + "/success?session_id={CHECKOUT_SESSION_ID}"),
            LineItems: []*stripe.CheckoutSessionLineItemParams{
                {
                    Price: stripe.String((lineItems.ItemID)),
                    Quantity: stripe.Int64(1),
                },
            },
            ShippingOptions: []*stripe.CheckoutSessionShippingOptionParams{
                 {
                    ShippingRate: &lineItems.ShippingID,
                 },
            },
            Mode: stripe.String(string(stripe.CheckoutSessionModePayment)),
            AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{Enabled: stripe.Bool(true)},
            AllowPromotionCodes: stripe.Bool(true),
        }
    }
#

But I'm not seeing a field to enter my promotion code.

#

ope, nvm

#

looking in the wrong place.