#paulc-webhooks

1 messages ยท Page 1 of 1 (latest)

primal merlin
#

hello, give me a sec

flint badger
#

Hi ! Sure !

primal merlin
#

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?

flint badger
#

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

primal merlin
#

so "IM IN THE HOOK" is not logging, right?

flint badger
#

yep

primal merlin
#

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

flint badger
#

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

primal merlin
#

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

flint badger
#

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 !

primal merlin
#

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)

flint badger
#

hahah , just to double check : using the CLI is "okay" not to see it , even tough I did see it with curl

primal merlin
#

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

flint badger
#

Okay , then could you please let me know what do you think is wrong ?

primal merlin
#

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?

flint badger
#

Yes , exactly

primal merlin
#

well let's start here - how do you run your webserver locally? something like node start or similar?

flint badger
#

npm start

#

with babel node

#

"start": "nodemon --exec babel-node src/index.js",

primal merlin
#

ok so you have that terminal window open separately

then in a new terminal window, you start the CLI listen command, right?

flint badger
#

yes

#

in the powershell to be more precise

primal merlin
#

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?

flint badger
#

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.

primal merlin
#

the other CLI window

#

not the one where you do trigger

#

the one where you have listen ongoing

flint badger
#

The other one doesnt log anything

#

No status code , nothing

primal merlin
#

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

flint badger
#

no , I do not see that

#

how can I fix this ?

primal merlin
#

one sec (I'm answering across multiple threads)

flint badger
#

sure

summer drum
#

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

flint badger
#

yes

#

It logs "Got successful response from Stripe" followed by many sending and receibing mesages

#

sent and received messages*

summer drum
#

Can you paste the output here?

flint badger
#

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

summer drum
#

Have you also re-run the stripe trigger command?

flint badger
#

no

#

should I run it first ?

summer drum
#

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

flint badger
#

Okay , thanks for being clear

summer drum
#

Interesting.... is that all of it? It looks like it's receiving the event, but not doing anything with it afterwards

flint badger
#

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

summer drum
#

And you still have the listen command running right? nothing else coming through?

flint badger
#

yes exactly

summer drum
#

In a separate window can you run stripe -v to get the version of the CLI that you're on?

flint badger
#

1.7.8

summer drum
#

Let me try and reproduce on my end - give me a few minutes

flint badger
#

sure

#

Thanks !

#

Any updates ? ...

summer drum
#

I'm trying, but I don't see the same before on my end when I'm on the same version of the CLI

flint badger
#

What can be the reasoning as to why it works with curl but not the cli ?

summer drum
#

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

flint badger
#

If I leave it open for more it throws more messages

#

is just that discord doesnt let me paste everything here

summer drum
#

Ah! That changes things!

flint badger
#

Hope for the better :))

summer drum
#

Yes, definitely for the better! Give me a few more minutes to dig around

flint badger
#

okay thanks !

summer drum
#

Can you do the following:

  • Cancel (ctrl+c) the currently running stripe listen command
  • Start up your webserver
  • Run stripe listen --forward-to localhost:8000/webhook --log-level debug in one window
  • Run stripe trigger payment_intent.succeeded in another window
flint badger
#

Finally hit the endpoint

#

What is different now ?

summer drum
#

I'm gonna be completely honest - I don't know

flint badger
#

:)))

summer drum
#

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

flint badger
#

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 *

summer drum
#

๐Ÿ‘ Yeah if you see this come up again definitely let us know!