#ilya | dappstep
1 messages ยท Page 1 of 1 (latest)
๐ happy to help
Hey! Take a look on the quesiton below with the code snippet
would you mind moving the other messages within the thread please?
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
sure! Done
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
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
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?
Give me a few minutes to look into this.
The Payment Link you shared has allow_promotion_codes: "true" and I guess they used a promo code in the URL, as described here https://stripe.com/docs/payments/payment-links
Doesn't seem like a payment link to me. the domain is checkout.stripe.com
Payment link creates buy.stripe.com link
@pearl citrus
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?
This is not my checkout - this is what I want to achieve
I want it to be removable
But I can't do it. Hold on a sec I'll share what I get
This is what I get
@regal zinc
Stop using mentions please, I'm with you.
lol, sorry
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;
Ah let me do some tests then
I think I answered your Q on Stack Overflow: https://stackoverflow.com/questions/75371447/how-to-make-subscription-session-with-prefilled-removable-promotion-code-or-disc
What you want to do isn't possible with Checkout
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
Can you clarify?
Yes, on payment link the prefilled email is still editable
Yep, that's because you can't use pre-existing Customer objects with Payment Links
While on checkout it's not - which is what i want
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
If you can share the cs_xxx ID then I can confirm that's expected
So the combination of both worlds: disabled email field + ability to remove prefilled code and enter another code will be perfect