#Mahesh K

1 messages · Page 1 of 1 (latest)

floral masonBOT
bold moss
#

Hi 👋

What's your question?

gaunt onyx
#

i have question in webhooks

bold moss
#

Okay, what about webhooks?

gaunt onyx
#

i am able to catch the event

#

payment invoice success

#

once i catch the event i trying to retrive the payment intent by using the payment id from the event response.

#

then i am getting an error

#

is it possible?

bold moss
#

So you are receiving the Event object for an invoice.succeeded event and you want to retrieve the Payment Intent from the API?

#

This is pretty straightforward. What is the error you are receiving?

gaunt onyx
#

yes but iam getting the following error

bold moss
gaunt onyx
#

this is the error msg i am getting in my console

#

and i required stripe pkg like this

#

const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY)

#

which makes it global

bold moss
#

Can you try assigning the STRIPE_SECRET_KEY to a variable and logging that value first?

gaunt onyx
#

sorry i didn't get you

bold moss
#

e.g.

const stripeKey = process.env.STRIPE_SECRET_KEY
gaunt onyx
#

ok

#

but?

#

this is working

#

event = stripe.webhooks.constructEvent(payload, sig, signingsecret)

#

means my stripe secret key is applying

bold moss
#

Okay can you share the event ID for the webhook event?

gaunt onyx
#

ok

bold moss
gaunt onyx
#

yes

#

which is in comments now

#

req_No0mf6oZtpuVw8

#

the request id is 200 ok

bold moss
#

This is a confirmation request, not a retrieve

gaunt onyx
#

wait a sec

bold moss
#

The account logs default to only POST requests. You have to change the filters to see the GET requests

gaunt onyx
#

ok

floral masonBOT
gaunt onyx
#

just a min i will create another error😅

#

i am unable to find the request

left musk
#

Popping in here since snufkin has to head out soon

#

event = stripe.webhooks.constructEvent(payload, sig, signingsecret) working does not mean that your secret key is correct - we don't need the secret key at all to do signature verification

gaunt onyx
#

hi karbi!!

left musk
#

Did you log the secret key const stripeKey = process.env.STRIPE_SECRET_KEY like snufkin mentioned earlier?

gaunt onyx
#

nope..

#

wait a min

#

i will do now

#

yes its logging

#

mr.karbi...are you there?

left musk
#

yup i'm here

#

you're logging this right before your code that's retrieving the Payment Intent right?

gaunt onyx
#

yes

gaunt onyx
left musk
#

Can you show me more of your code? I just want to see your full webhook event handler

gaunt onyx
#

ok

#

means invoice payment event handler?

#

or other events too?

left musk
#

I want to see exactly how you're initializing stripe all the way to the request that's failing

gaunt onyx
#

ok

#

you can find the payment intent retrive where i tick

left musk
#

gotcha

gaunt onyx
#

haa

left musk
#

and you're absolutely sure that the PaymentIntent retrieve code is what's failing?

gaunt onyx
#

yes

left musk
#

Okay can you show me what you get when you add console.log(stripe._api) right before your payment intent retrieval code?

gaunt onyx
#

console.log(stripe._api)

#

i have to include exact this?

left musk
#

Yes, that exactly

gaunt onyx
#

{
auth: null,
host: 'api.stripe.com',
port: '443',
protocol: 'https',
basePath: '/v1/',
version: null,
timeout: 80000,
maxNetworkRetries: 0,
agent: null,
httpClient: NodeHttpClient { _agent: undefined },
dev: false,
stripeAccount: null
}

#

i am getting this

#

mr.karbi???

left musk
#

I'm still here - I respond to multiple folks at once so sometimes it just takes a couple of minutes

#

Yeah so from that output the API key is clearly not being set correctly - if you log process.env.STRIPE_SECRET_KEY right before you initialize stripe do you still get the API key back?

gaunt onyx
#

yes😢

#

i am getting undefined

#

but why?

#

if i log the same in other files i am able to get the secret key

left musk
#

Yeah you need to debug that on your end - it really could be any number of things (maybe how your directory is structured, maybe somethign is slightly different about this file, etc)

gaunt onyx
#

Ok Thank you!

#

another one..

#

did you have any references for handling the failed invoice payments ?

left musk
#

What do you mean by that?

gaunt onyx
#

like if i get the invoice payement failed event from the webhooks.

#

after failure what can i do. can i share the same payment url or is there other process?

left musk
#

You can use the same payment URL, but really there's a ton of different ways to handle this and it'll depend on what you want to do

gaunt onyx
#

can i have some references please?

#

as you said there are tons of ways.

gaunt onyx
#

ok