#Xcoder-webhook
1 messages · Page 1 of 1 (latest)
I have created a webhook.js
In api/
And i wanted to save my stripe data in firebase database
I have also added permission.js
Ok, is there a specific issue or error?
Its not working
I am not getting any error
But it's not working
I want to link my strip with firebase
So i can store my data in it
You'll need to share some more context. The code would be a good start
Okay
I'll share you my github repo
Can you share the specific file?
Ok, and there's no Firestore document or errors?
You'll need to add debugging/logs in your code to figure out at what point its failing and step through it
I'm not getting this type of text
payment_intent etc
When I run stripe listen --forward-to localhost:3000/api/webhook
I just get this text
Ready! You are using Stripe API Version [2020-08-27]. Your webhook signing secret is
..................
I think if I get this mssg it will work
So looking at your code you're using the checkout.session.completed event. Have you actually completed a Checkout Session to fire that event on your account?
yeah
Or you can simulate it with the CLI: stripe trigger checkout.session.completed
my checkout session is working
I'm getting data in my stripe dashboard
I have installed stripe cli
Right, but you just said the events aren't being forwarded to your local webhook via the CLI?
Forwarding to Stripe? You don't forward webhooks back to us
Are you able to log something out in your webhook handler when checkout.session.completed events fire?
Because you just told me you don't see anything extra to suggest they're being forwarded in the CLI
I'm getting transaction here
but not in firebase
Right, but the issue is in the webhook. You need to be sure that your webhook, where you create the Firestore documents, is actually receiving those checkout.session.completed events
Okay but how
Uncomment this log: https://github.com/4mohdisa/amazon-2.0-/blob/main/src/pages/api/webhook.js#L16
Is it ever logged in your terminal where Next.js is running?
I guess that's being triggered here: https://github.com/4mohdisa/amazon-2.0-/blob/68e0d0980025fbc1f63d06dc178486609411a314/src/pages/api/webhook.js#L47
Which means your webhook signing is failing
I can see that 🙂
I don't think you need this line: https://github.com/4mohdisa/amazon-2.0-/blob/68e0d0980025fbc1f63d06dc178486609411a314/src/pages/api/webhook.js#L38
Also, no idea what buffer from that micro library does. But in my experience in working with Next.js and Stripe webhooks you should do this:
async function buffer(readable) {
const chunks = []
for await (const chunk of readable) {
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)
}
return Buffer.concat(chunks)
}
async function handler(req, res) {
if (req.method === 'POST') {
const buf = await buffer(req)
const sig = req.headers['stripe-signature']
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET
let event
try {
if (!(sig || webhookSecret)) return
event = stripe.webhooks.constructEvent(buf, sig, webhookSecret)
} catch (err) {
console.log(`❌ Error message: ${err.message}`)
return res.status(400).send(`Webhook Error: ${err.message}`)
}
...
res.status(200).json({ received: true })
} else {
res.status(405).send()
}
}
DO you know what is this error about
Too difficult? 👉 Watch my REACT BASICS 101 class for FREE with 1 month FREE Skillshare access (First 1000 people): https://skl.sh/2Srfwuf
🚨 Join the world’s BEST developer community “Zero to Full Stack Hero” NOW: https://www.papareact.com/course
Join me on Day 4 of 5 of the 5-DAY AMAZON CHALLENGE where we build the following:
👉 Payment Proce...
I'm trying to help you with the above
I'm following this youtube video
Have you tried re-writing your code to what I shared?
1:10:48 Explaining Webhook
It's not working
Is it the same error?
don't think we can help you with that!