#tibo1002
1 messages ยท Page 1 of 1 (latest)
The problem is that the examples always show this part in another file but I need to use it right after the creation of the session in the same file.
You can't, and this doesn't really make sense. After the session is created, your customer needs to be redirected to the Checkout session (byurl) in order to complete payment.
After they finish the Checkout flow, they are redirected to your success_url and we send the checkout.session.completed webhook to your endpoint
Yes I have this:
const checkoutSession = await axios.post(Routes.API.CHECKOUT, body);
const result = await stripe.redirectToCheckout({
sessionId: checkoutSession.data.id,
});
return result;
So instead of returning the result I do a new axios.post to a webhook page ?
No, there are two different things
I'd also suggest using your own redirect to the session url instead of redirectToCheckout but that's not required.
The steps are
1/ Create a session
2/ redirect your customer to that session
3/ Customer completed the session
4a/ we send the webhook event to your endpoint
4b/ the customer is redirected back to your sucess url
So in the success_url I put the url of the checkout page ?
Where do I put the call to the webhooks ?
You don't put a "call to webhooks" anywhere, stripe sends that to you automatically. You need to register an endpoint, though.
I suggest reading up on our webhooks starting here: https://stripe.com/docs/webhooks
And looking at the integration example here: https://stripe.com/docs/webhooks#example-endpoint
Ok so in my app I create an endpoint (for example 'checkoutWebhook') and I register it in my Stripe dashboard.
What I don't understand is how I call the webhook ? Can't I do an axios.post ?
You do call it, we do, by sending it events as requests
You respond/react when we do that
So I just have to create the endpoint and register it ?
Yes
Once you create a route on your server and register it as webhook endpoint, Stripe will make a request to it for the events
And I just have to do my Prisma update in the desired event type.
Thanks a lot for taking your time explaining me this ๐๐๐