#ilya | dappstep

1 messages ยท Page 1 of 1 (latest)

sick nimbusBOT
subtle mesa
#

๐Ÿ‘‹ happy to help

inner hinge
#

Hey! Take a look on the quesiton below with the code snippet

subtle mesa
#

would you mind moving the other messages within the thread please?

inner hinge
#

I've managed to create a checkout page with promotion code like this

  const sessionParams: Stripe.Checkout.SessionCreateParams = {
    customer_email: user.email,
    mode: 'subscription',
    line_items: [
      {
        price: process.env.STRIPE_PRICE_CODE,
        quantity: 1,
      },
    ],
    metadata: {
      userId: user.userId,
    },
    // {CHECKOUT_SESSION_ID} is a string literal; do not change it!
    // the actual Session ID is returned in the query parameter when your customer
    // is redirected to the success page.
    success_url: `${origin}/account/download-app?session_id={CHECKOUT_SESSION_ID}`,
    cancel_url: `${origin}/account/plan-preview`,
  };

  if (req.query.coupon === 'special-access') {
    sessionParams.allow_promotion_codes = true;
  } else {
    sessionParams.discounts = [{ promotion_code: '***' }];
  }

  const session = await stripe.checkout.sessions.create(sessionParams);

But I've noticed that user can't remove the promo code and add his custom code. enter image description here

I see other companies checkouts that they do have prefilled promo code with an X to remove it and add their own enter image description here

I've tried using discount object with allow_promotion_codes: true, but it seems not allowed by the API.
Here is what I have

#

Here is what I want it to be

pearl citrus
#

Hi! I'm taking over this thread.

#

Where is the second screenshot coming from? Another Checkout Session?

#

You have two options for promo code in Checkout Session:

  • You set the code directly with the API, and in this case it cannot be removed by the user
  • Or you allow user to enter their own promo code, and in this case they can remove it after their entered it themselves
pearl citrus
#

Interesting. Give me a few minutes to look into this.

#

The link you shared is actually for a Payment Link, so promo code might work differently there

inner hinge
#

So it's a diffrent code to create it?

#

But it's also a subscription plan and it's created programmatically

#

Do you have an idea how I create this kind of links programmatically?

pearl citrus
#

Give me a few minutes to look into this.

inner hinge
#

@pearl citrus

regal zinc
#

Hey! Taking over for my colleague. Let me catch up.

#

But I've noticed that user can't remove the promo code and add his custom code. enter image description here
Can you share a checkout session id for this?

regal zinc
#

It's removable for me

#

you want it not removable ?

regal zinc
#

Stop using mentions please, I'm with you.

inner hinge
#

lol, sorry

regal zinc
#

I see in your code having:

  if (req.query.coupon === 'special-access') {
    sessionParams.allow_promotion_codes = true;
  } else {
    sessionParams.discounts = [{ promotion_code: '***' }];
  }

When applying discounts keep allowing promotions codes too... try something like this:

  if (req.query.coupon !== 'special-access') {
    sessionParams.discounts = [{ promotion_code: '***' }];
  }
    sessionParams.allow_promotion_codes = true;
inner hinge
#

No it doesn't work that way

regal zinc
#

Ah let me do some tests then

hidden belfry
#

What you want to do isn't possible with Checkout

inner hinge
#

Yeah, it's me ๐Ÿ˜„

#

But I have a comment there

hidden belfry
#

The session you shared there was generated via a Payment Link

#

I guess with the prefilled_promo_code param I mentioned

#

Using both the discounts hash and allow_promotion_codes param together is feedback we've heard before, I'll bump that with your request internally

inner hinge
#

Awesome thank you!

#

What's missing for me on payment link is that use can edit email

hidden belfry
#

Can you clarify?

inner hinge
#

Yes, on payment link the prefilled email is still editable

hidden belfry
#

Yep, that's because you can't use pre-existing Customer objects with Payment Links

inner hinge
#

While on checkout it's not - which is what i want

hidden belfry
#

If the Customer already has a valid email set, the email will be prefilled and not editable in Checkout. If the Customer does not have a valid email, Checkout will set the email entered during the session on the Customer.
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer

#

If you can share the cs_xxx ID then I can confirm that's expected

inner hinge
#

So the combination of both worlds: disabled email field + ability to remove prefilled code and enter another code will be perfect