#Lesc
1 messages · Page 1 of 1 (latest)
No I want it so stripe sends events to my server if something happens like when a subscription was created or something. How would I trigger the events? I want to receive them when they happen
Yeah, I mean in order to test, you need to do some action in order that Stripe triggers the event as a result.
In order to test that express endpoint, you can run it locally
use Stripe cli in order to forward event to your local endpoint when they occure:
stripe listen --forward-to http://localhost:4242
https://stripe.com/docs/cli/listen#listen-forward-to
And then simulate triggering some events, e.g. stripe trigger checkout.session.completed
https://stripe.com/docs/webhooks/test
Well I create subscriptions for example like this:
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{
price: priceId,
}],
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
});
This works. The subscription is created but I don't receive the event over the webhook
Is this express deployed in a server or you are running it locally ? in other words you want to receive the event in your server or locally for test first ?
Right now I run it locally
Oh wait so it doesn't work like that locally?
So locally I need to do this stripe listen --forward-to thing but when I host it on a server I don't need to do that right?
Yes when you are on server you need to follow this guide:
https://stripe.com/docs/webhooks/go-live
Ok thank you I will try that later
Welcome!