#rishsane_webhooks

1 messages ยท Page 1 of 1 (latest)

pastel deltaBOT
#

๐Ÿ‘‹ 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/1392289593969344552

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

wicked sky
#

Hi! It sounds like you have multiple questions in there; can you help me understand what you're looking to solve?

placid raptor
#

Thansk for reaching out

#

So I am trying to make robust stripe payment.

#

Even user completed checkout, but in some rare cases, webhook didn't catch that checkout due to several unexpected reasons like network errors.

#

Our webhook is designed so that if user completed the checkout, update the user's database to isSubscribed: true ...

#

But what should I do in case webhook didn't work.

#

Webhook didn't work but in the stripe account, a new subscription is generated.

#

I've tried to fetch subscriptions using customer ID but finally noticed that in every checkout new customer ID is generated

#

It's what we store in the database

#

"subscription": {
"customerId": "cus_SdxGyrenVfOKkq",
"isSubscribed": true,
"plan": "basic",
"billing": "monthly",
"expiresAt": "2025-08-08T17:30:55.000Z",
"subscriptionId": "sub_1RifM5GaMCR5nxHDXomM80iz",
"priceId": "price_1RggCqGaMCR5nxHDPXdzUzEq",
"status": "active",
"lastSyncedAt": "2025-07-08T17:31:03.502Z"
},

#

This is checkout form

placid raptor
wicked sky
#

Yep, thank you. Which Event did your Webhook Endpoint not receive? Can you share the ID with me?

#

evt_1RifM6GaMCR5nxHDpUngPjTo ?

placid raptor
#

You mean, when generating checkout link, we can add customer ID?

#

const response = await fetch('https://api.stripe.com/v1/checkout/sessions', {
method: 'POST',
headers: {
'Authorization': Bearer ${process.env.STRIPE_SECRET_KEY},
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
'payment_method_types[0]': 'card',
'line_items[0][price]': body.priceId,
'line_items[0][quantity]': '1',
'mode': 'subscription',
'success_url': ${request.nextUrl.origin}/dashboard/settings/billing?success=true,
'cancel_url': ${request.nextUrl.origin}/pricing?canceled=true,
'metadata[user_id]': userId,
'subscription_data[metadata][user_id]': userId,
}),
});

wicked sky
#

You're not providing an existing Stripe Customer ID in there.

#

Otherwise it will always make a new one, because it won't know there's an existing one.

placid raptor
#

Gocha

wicked sky
#

Which Event did you expect to be delivered, but which was not?

placid raptor
#

const response = await fetch('https://api.stripe.com/v1/checkout/sessions', {
method: 'POST',
headers: {
'Authorization': Bearer ${process.env.STRIPE_SECRET_KEY},
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
'payment_method_types[0]': 'card',
'line_items[0][price]': body.priceId,
'line_items[0][quantity]': '1',
'mode': 'subscription',
'success_url': ${request.nextUrl.origin}/dashboard/settings/billing?success=true,
'cancel_url': ${request.nextUrl.origin}/pricing?canceled=true,
'metadata[user_id]': userId,
'subscription_data[metadata][user_id]': userId,
'customer': customerId, // Add the existing Stripe customer ID here <-----------
}),
});
like this you mean.

placid raptor
pastel deltaBOT
wicked sky
#

What is the ID of that Event from yor Dashboard? The one that didn't get delivered?

bleak ginkgo
#

@placid raptor ๐Ÿ‘‹ taking over here. Could you share the corresponding Checkout Session Id cs_test_xxx? Want to double check if an Invoice was actually created

summer creek
#

@placid raptor You need to link the Stripe customer ID on the user account record on your end and use that ID for all future Stripe API calls that accept a customer.id, otherwise the Stripe API will create a new customer every time. Email addresses in Stripe are not unique so you end up with multiple customer records with the same email, name etc.

When you first create a checkout session for a customer that doesn't exist in Stripe, you would use the customer_email parameter along with metadata that will allow you to identify the customer on your end once you start receiving responses/events from Stripe.

Always a good idea to listen to the customer.created event and link up those IDs.

You can then continue making Stripe checkout API calls but instead of customer_email, you now use customer and provide the Stripe customer ID which you now have on your end.

pastel deltaBOT
placid raptor
#

Thanks very much @wicked sky @bleak ginkgo @summer creek

#

Yes by adding customer ID, I could stop generating new customers in every cycle.

#

Now I could check correctly if webhook failed or not.