#tibo1002

1 messages ยท Page 1 of 1 (latest)

somber meadowBOT
reef summit
#

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 (by url) 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

dreamy hazel
#

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 ?

reef summit
#

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

dreamy hazel
#

So in the success_url I put the url of the checkout page ?
Where do I put the call to the webhooks ?

reef summit
somber meadowBOT
dreamy hazel
#

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 ?

reef summit
#

You do call it, we do, by sending it events as requests

#

You respond/react when we do that

dreamy hazel
#

So I just have to create the endpoint and register it ?

tall herald
#

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

dreamy hazel
#

And I just have to do my Prisma update in the desired event type.
Thanks a lot for taking your time explaining me this ๐Ÿ‘๐Ÿ‘๐Ÿ‘