#paulc-webhooks
1 messages ยท Page 1 of 1 (latest)
Hi ! Sure !
is this relevant to the fact that the console doesnt log anything ?
not sure I understand, but I'm reading that as your webhook endpoint is not being hit?
yes exactly
This is the callback function
const webHookStripe = async (req, res) => {
console.log("IM IN THE HOOK")
const sig = req.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
}
catch (err) {
res.status(400).send(`Webhook Error: ${err.message}`);
}
switch (event.type) {
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
//DB queries
res.send(paymentIntent)
break;
default:
console.log("payment was attempted")
}
return res.json({ received: true })
}
and I have done all the fun cli stuff : stripe login -> stripe listen --forward-to localhost:8000/webhook
->stripe trigger payment_intent.succeeded
so "IM IN THE HOOK" is not logging, right?
yep
yeah so some issue in that your endpoint is not getting hit, this would be a few different things but I'd verify that you can locally hit your endpoint by just making a request to localhost:8000/webhook like via Postman ro curl
alright Ill do curl rn
Throwd this "Webhook Error: endpointSecret is not defined"
throws*
I know that as soon as you start listening to a route stripe responds with the webhook signing secret , but at this point in the docs where I am at it does not show how to use it
so the point of curl was to verify your endpoint is up, which it is
the error isn't relevant right now but you still need to copy paste that into your webhook code
the endpointSecret
it is static so you can just copy and paste that to your code
Is it needed only in production ? And, subsequently, only in production will I be able to see the console.log?
Seems like it did log it actually, for some reason I just didnt check the console .
Thank you hmunoz !
Is it needed only in production ?
test or production
will I be able to see the console.log?
no your problem is not solved, you should see the log in test mode too
ah your problem is solved (read your next msg)
hahah , just to double check : using the CLI is "okay" not to see it , even tough I did see it with curl
using the CLI is "okay" not to see it
you should still see it in CLI, in where-ever you start your webserver terminal window
Okay , then could you please let me know what do you think is wrong ?
well let's take a step back, what is wrong?
you said
Seems like it did log it actually, for some reason I just didnt check the console .
did you mean that only works for curl and not CLi?
Yes , exactly
well let's start here - how do you run your webserver locally? something like node start or similar?
ok so you have that terminal window open separately
then in a new terminal window, you start the CLI listen command, right?
ok so with CLI and your webserver running, you should still expect Stripe CLI to forward that event to your local /webhook endpoint and your other window log out that console log
in your CLI window, do you see the payment_intent.succeeded window being sent? does it show some HTTP status code next to it? like a 200 or a 500 or something?
after " stripe trigger payment_intent.succeeded"
I get : Setting up fixture for: payment_intent
Running fixture for: payment_intent
Trigger succeeded! Check dashboard for event details.
the other CLI window
not the one where you do trigger
the one where you have listen ongoing
do you not see a ----> payment_intent.succeeded event there ?
if not then the event isn't being received by the CLI
so it has nothing to forward to your endpoint
one sec (I'm answering across multiple threads)
sure
Can you try re-running your stripe listen command and include --log-level=debug? That should hopefully give us a better indication of what's going on
yes
It logs "Got successful response from Stripe" followed by many sending and receibing mesages
sent and received messages*
Can you paste the output here?
stripe listen --log-level=debug
. Getting ready... [Thu, 11 Nov 2021 19:31:20 CET] DEBUG stripeauth.client.Authorize: Authenticating with Stripe...
o Getting ready... [Thu, 11 Nov 2021 19:31:21 CET] DEBUG stripeauth.Client.Authorize: Got successful response from Stripe default_version=2020-08-27 display_connect_filter_warning=false latest_version=2020-08-27 reconnect_delay=233 websocket_authorized_feature=webhook-payloads websocket_id=cliws_{5086}_Dm0xcYYsOm1LCNDHsn3t8yeXoAWoN6fSURj3bvKpiR1cXn70xH websocket_url=wss://stripe-cli.stripe.com/subscribe/acct_1I3LzQA3jSMal6iv
[Thu, 11 Nov 2021 19:31:21 CET] DEBUG websocket.client.Run: Attempting to connect to Stripe
[Thu, 11 Nov 2021 19:31:21 CET] DEBUG websocket.Client.connect: Dialing websocket url=wss://stripe-cli.stripe.com/subscribe/acct_1I3LzQA3jSMal6iv?websocket_feature=webhook-payloads
o Getting ready... [Thu, 11 Nov 2021 19:31:21 CET] DEBUG websocket.client.connect: Connected!
Ready! You are using Stripe API Version [2020-08-27]. Your webhook signing secret is whsec_XZG47iV9nu9Ye6sXijoBTJiJSQGyB31z (^C to quit)
[Thu, 11 Nov 2021 19:31:23 CET] DEBUG websocket.Client.writePump: Sending ping message
[Thu, 11 Nov 2021 19:31:23 CET] DEBUG websocket.Client.readPump: Received pong message
[Thu, 11 Nov 2021 19:31:25 CET] DEBUG websocket.Client.writePump: Sending ping message
[Thu, 11 Nov 2021 19:31:25 CET] DEBUG websocket.Client.readPump: Received pong message
[Thu, 11 Nov 2021 19:31:27 CET] DEBUG websocket.Client.writePump: Sending ping message
[Thu, 11 Nov 2021 19:31:27 CET] DEBUG websocket.Client.readPump: Received pong message
Have you also re-run the stripe trigger command?
I want to see the output from stripe listen --log-level=debug running in one terminal, when you run stripe trigger payment_intent.succeeded in a separate window
Interesting.... is that all of it? It looks like it's receiving the event, but not doing anything with it afterwards
I think this may be relevant as well
ransfer_data": null,\n "transfer_group": null\n }\n },\n "livemode": false,\n "pending_webhooks": 2,\n "request": {\n "id": "req_FvQ9Fk5FFvECuz",\n "idempotency_key": "0694a345-6748-4d31-85bd-bf5cf08b2409"\n },\n "type": "charge.succeeded"\n}","http_headers":{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-cache","User-Agent":"Stripe/1.0 (+https://stripe.com/docs/webhooks)","Accept":"/; q=0.5, application/xml","Stripe-Signature":"t=1636655770,v1=1126ea5dc64c3fe8291f6358530136ee3ce56e1749d2840bf5b8aaef83bc7bd0,v0=0a951d8486ca6381499bc353cb23d46519935d82718771304020a373438f066b"},"endpoint":{"api_version":"2020-08-27"},"type":"webhook_event"}
This is the end of it
And you still have the listen command running right? nothing else coming through?
yes exactly
In a separate window can you run stripe -v to get the version of the CLI that you're on?
1.7.8
Let me try and reproduce on my end - give me a few minutes
I'm trying, but I don't see the same before on my end when I'm on the same version of the CLI
What can be the reasoning as to why it works with curl but not the cli ?
It's not working with the CLI because the CLI is failling at a step BEFORE forwarding the event to the endpoint you specified. It's not even processing the incoming message has come in correctly, so it doesn't even get the chance to attempt to forward it
Typically, I'd expect way more logs coming in from the stripe listen command after the incoming message log
If I leave it open for more it throws more messages
is just that discord doesnt let me paste everything here
The full log
Ah! That changes things!
Hope for the better :))
Yes, definitely for the better! Give me a few more minutes to dig around
okay thanks !
Can you do the following:
- Cancel (ctrl+c) the currently running
stripe listencommand - Start up your webserver
- Run
stripe listen --forward-to localhost:8000/webhook --log-level debugin one window - Run
stripe trigger payment_intent.succeededin another window
I'm gonna be completely honest - I don't know
:)))
The specific reason why your endpoint wasn't getting the events is what I explained earlier (where the CLI wasn't processing the events it was receiving and didn't even attempt to forward), but I don't know WHY it was actually failing to do so
I see
Thank you so much karbi !
If I will have problems with the I will ask in the chat , if you dont mind
in the following days *
๐ Yeah if you see this come up again definitely let us know!