#Mahesh K
1 messages · Page 1 of 1 (latest)
Hi 👋
What's your question?
i have question in webhooks
Okay, what about webhooks?
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?
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?
yes but iam getting the following error
Can you share the request ID for the API request that triggers the error?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
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
Can you try assigning the STRIPE_SECRET_KEY to a variable and logging that value first?
sorry i didn't get you
e.g.
const stripeKey = process.env.STRIPE_SECRET_KEY
ok
but?
this is working
event = stripe.webhooks.constructEvent(payload, sig, signingsecret)
means my stripe secret key is applying
Okay can you share the event ID for the webhook event?
ok
But essentially you just want to do this: https://stripe.com/docs/api/payment_intents/retrieve?lang=node right?
This is a confirmation request, not a retrieve
wait a sec
The account logs default to only POST requests. You have to change the filters to see the GET requests
ok
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
hi karbi!!
Did you log the secret key const stripeKey = process.env.STRIPE_SECRET_KEY like snufkin mentioned earlier?
yup i'm here
you're logging this right before your code that's retrieving the Payment Intent right?
yes
is it correct?
Can you show me more of your code? I just want to see your full webhook event handler
I want to see exactly how you're initializing stripe all the way to the request that's failing
gotcha
haa
and you're absolutely sure that the PaymentIntent retrieve code is what's failing?
yes
Okay can you show me what you get when you add console.log(stripe._api) right before your payment intent retrieval code?
Yes, that exactly
{
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???
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?
yes😢
i am getting undefined
but why?
if i log the same in other files i am able to get the secret key
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)
Ok Thank you!
another one..
did you have any references for handling the failed invoice payments ?
What do you mean by that?
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?
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
We don't have a ton of docs on this but here's what I found:
ok