#Robin020
1 messages · Page 1 of 1 (latest)
It should not. Have you timed the Stripe calls and saw that they took 20 seconds? Or is this the time from a user clicking a button on your page to being redirected?
yeah i timed it myself as well
To set up the first session normally takes around 15 seconds
How long should it take?
Do you have the ID of a specific checkout session that took this long? (cs_test_1234)
I can check the end to end time from our side and look at it overall.
Not immediately sure on the average time but that does sound long
Can I send node JS code here?
👋 stepping in
app.post("/create-checkout-session", async (req, res) => {
const { prod, id, email, startDatum, coupon } = req.body;
console.log("Create checkout session...");
const couponEdit = coupon.toLowerCase().trim();
let activeCoupon;
switch (couponEdit) {
case "first50":
activeCoupon = prod ? "NRKitQnJ" : "123456";
break;
case "first100":
activeCoupon = "first100";
break;
default:
break;
}
try {
const YOUR_DOMAIN = prod
? "https://hulpmethuren.nl/activeren"
: "http://127.0.0.1:5173/activeren";
const SUCCESS = prod
? "https://hulpmethuren.nl/welkom"
: "http://127.0.0.1:5173/welkom";
const customer = await stripe.customers.create({
metadata: {
id,
email,
startDatum,
},
});
const session = await stripe.checkout.sessions.create({
billing_address_collection: "auto",
line_items: [
{
price: prod
? "price_1MQme0FM0KvL0X1JsXhSJlJU"
: "price_1MQZowFM0KvL0X1Ju1THqKR8",
// For metered billing, do not pass quantity
quantity: 1,
},
],
subscription_data: {
trial_period_days: 7,
},
discounts: [
{
coupon: activeCoupon,
},
],
mode: "subscription",
customer: customer.id,
success_url: `${SUCCESS}/?success=true&session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${YOUR_DOMAIN}?canceled=true`,
});
res.send(session);
} catch (error) {
console.error(error);
res
.status(500)
.send(
"Error creating checkout session. Please try again later." +
error.message
);
}
});
Put the code between 3 backticks helps for readability. Like this
Oh sorry lol
All good
const { prod, id, email, startDatum, coupon } = req.body;
console.log("Create checkout session...");
const couponEdit = coupon.toLowerCase().trim();
let activeCoupon;
switch (couponEdit) {
case "first50":
activeCoupon = prod ? "NRKitQnJ" : "123456";
break;
case "first100":
activeCoupon = "first100";
break;
default:
break;
}
try {
const YOUR_DOMAIN = prod
? "https://hulpmethuren.nl/activeren"
: "http://127.0.0.1:5173/activeren";
const SUCCESS = prod
? "https://hulpmethuren.nl/welkom"
: "http://127.0.0.1:5173/welkom";
const customer = await stripe.customers.create({
metadata: {
id,
email,
startDatum,
},
});
const session = await stripe.checkout.sessions.create({
billing_address_collection: "auto",
line_items: [
{
price: prod
? "price_1MQme0FM0KvL0X1JsXhSJlJU"
: "price_1MQZowFM0KvL0X1Ju1THqKR8",
// For metered billing, do not pass quantity
quantity: 1,
},
],
subscription_data: {
trial_period_days: 7,
},
discounts: [
{
coupon: activeCoupon,
},
],
mode: "subscription",
customer: customer.id,
success_url: `${SUCCESS}/?success=true&session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${YOUR_DOMAIN}?canceled=true`,
});
res.send(session);
} catch (error) {
console.error(error);
res
.status(500)
.send(
"Error creating checkout session. Please try again later." +
error.message
);
}
});
I am creating a customer, and getting a notification on my phone with customer created with ID 123...
-
is it even necessasry to create a customer? This way I am creating customers also when they dont finish checkout
-
How do I arrange that I receive the name of the customer instead of the ID
- is it even necessasry to create a customer? This way I am creating customers also when they dont finish checkout
Yes you need a Customer in order to have a Subscription, however you can have the Checkout Session create the Customer if you so desire. That is up to you really.
- How do I arrange that I receive the name of the customer instead of the ID
The name associated with the Customer will be a property on the Customer object: https://stripe.com/docs/api/customers/object#customer_object-name
Are you asking how you see this on your phone?
Are you getting a push notification from Stripe here or is this your own integration sending your phone a message?
Push from Stripe
I'm not familiar with our push notifications
Oke
Ah okay I doubt those are customizable, but that would be a better question for our Support team: https://support.stripe.com/contact/login
Alright, so then for the first question
Can I remove the create customer function
And pass in my own id as customer (property)
in the line below mode: subscription
No you can't use your own ID
That has to be a Stripe Customer ID
If you don't pass the customer parameter there at all then we will create a Customer for you
Any benefits or risks in there?
Said anotherway: If I leave both the create customer function and the customer paramter out
Stripe will create a customer when someone finish their checkout session