#esW
1 messages ยท Page 1 of 1 (latest)
Hi ๐ I don't have much experience with the Firebase Extension, so I'm not entirely certain. Is there a guide you've been following so far that I could look through?
Hi Toby
๐ฉ Want coding problems (with solutions!) delivered to your inbox daily!?
Sign Up Here: https://www.papareact.com/universityofcode
๐จ Join the worldโs BEST developer community โZero to Full Stack Heroโ NOW: https://www.papareact.com/course
โ๏ธAmazon Starter Template: https://github.com/sonnysangha/Amazon-starter-template-nextjs
Join me as I buil...
i followed this tutorial
to implement my webhook with firebase and stripe
๐ Hopping in here!
i debugged up to the point that
i found out it is due to the stripe listener
watching for the event
but i can only run it locally
cuz when the listener is running locally on my machine, it will populate the firebase db
๐
i am using nextjs, firebase, tailwind, stripe and going to implement contentful
export default async function webhookHandler(req, res) {
console.log("Payment intent");
let event;
if (req.method === "POST") {
const buf = await buffer(req);
const signature = req.headers["stripe-signature"];
// Get the signature sent by Stripe
try {
if (!signature || !webhookSecret) return;
event = stripe.webhooks.constructEvent(buf, signature, webhookSecret);
} catch (err) {
console.log(`โ ๏ธ Webhook signature verification failed.`, err.message);
return res.status(404).send("webhook error");
}
console.log(event.type);
res.status(200).send();
}
const session = event.data.object
// Handle the event
switch (event.type) {
case "payment_intent.succeeded":
break;
case "payment_intent.created":
break;
case "checkout.session.completed":
return await fulfillOrder(session)
.then(() => res.status(200))
.then(() => {})
.catch((err) => res.status(400).send("Webhook Error"));
case "charge.succeeded":
break;
default:
console.log(`Unhandled event type ${event.type}`);
}
}
this is my webhook handler though
i didn't follow their guide completely
fulfill order is essentially the post request to firebase to populate the docs and collections
You need to follow the guide completely - I assume that guide includes additional steps on deploying the app, at which point you'd need to create a webhook endpoint based on where you deployed your app too + change the webhook secret environment variable to match the new endpoint as well
Yeah, i followed it completely but it was outdated, this is my code which is the closest ive gotten
yeah i created the endpoint for webhook at /api/webhook
that code is the handler when that webhook route is hit
Is your issue with your webhook event handler code not working, or that you don't have a production webhook set up?
but it isn't listening for that deployed
yes!
no production webhook
set up
because locally with stripe listen --forward-to localhost:3000
with that part it will push to my db
without it, i only get checkout session but no data population
Sorry, I am fairly new to programming. I try to be as specific as possible at times but it may confuse
Did you deploy your app?
yes
checkout will only work if you are signed in
so it will error you if u checkout without a user
I don't know what exact endpoint you need to set it to because I don't know the specific guide you're following, but generally you'll want to add a new webhook endpoint to the dashboard here (https://dashboard.stripe.com/test/webhooks) which will give you the endpoint secret you'll need to set as your environment variable
I assume the rest of the guide you linked to covers this
oh...
i think this webhook i didnt set..
i set the firebase side
and not stripe...
let me test
redeploying
hopefully this is all it takes...
thank you so much for ur time karbi!!!
it still isn't working :/
:/
i replaced the signing secret env
Yeah but what specifically isn't working - you need to be giving way more specifics. Are you getting errors in your logs? Have you checked to see that the events are going to your endpoint? Is the signature verification failing?
adding another endpoint
no logs
the event isnt being found ?
it says error rate 100%
:/
thats pretty sad
i am listening for checkout.session.completed
You don't need to add a new endpoint - you need to debug what's wrong with the endpoint you have
Did you confirm that the endpoint secret is correct by logging it?
Is it the correct secret though? Does it match what you have in the dashboard?
yes
whsec_ohVshMyZ70TspJdQZ6uBjBPv897p8MWf
for next js
i mean vercel
same for stripe
webhook
ohhh
i think i got it wrong
newtype-starfish-gt4whjz07-requiem-of-zero.vercel.app
i have deployment url
and domain url
i put the domain url?
maybe?
Again, I don't know the guide you're using so I don't know which exact URL you need to put where, but no matter what you need to make sure the URL you're using matches the secret for the webhook endpoint URL
๐
wait
karbi
i got the 200 ok
but my firebase still nothing?
oh thats at 2:18
Have you checked your firebase logs to see if anything stands out there?
Where specifically are you seeing that?
metadata": {
"email": "theesamwong@gmail.com",
"items_id_quantity": "["2, 1","3, 1","4, 1","5, 1","11, 1"]"
on my stripe webhook
it is hitting my endpoint now
Yes, but where? In the dashboard looking at the webhook event? In your server logs?
Can you share the event ID you're seeing that with? Should be something like evt_123
I'm not seeing any 200s for that event at all - did you configure one of your endpoints to redirect to somewhere else? If so, that won't work - stripe webhooks don't follow redirects
i have my host set as a environment variable
POST /v1/webhook_endpoints/we_1MvS5jF4hmr5JS7oZ2K0EMu7
Status
200 OK
hahaha
i didnt understand this post
but i guess thats the post to stripe
and the logs
That's the request to create the webhook endpoint - that's unrelated to actually getting your endpoint to work and accept eents
i see...
Try one thing for me really quick though - Change your https://newtype-starfish-gt4whjz07-requiem-of-zero.vercel.app/api/webhook/ webhook endpoint to https://newtype-starfish-gt4whjz07-requiem-of-zero.vercel.app/api/webhook (remove the last / from the URL) in the stripe dashboard
ok
nothing!!! :/
wait
i think it may be my webhook file
:/
i love programming
fix one thing
break 10
โค๏ธ
unlimited questing
I think now with that change (removing that last /) you're back to both failing with "webhook error", which based on your code is either because of signature verification or because of an error from your fulfillOrder function, so you need to do some debugging to figure out which it is