#esW

1 messages ยท Page 1 of 1 (latest)

vernal bronzeBOT
scenic falcon
#

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?

vernal bronzeBOT
limber crystal
#

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...

โ–ถ Play video
#

i followed this tutorial

#

to implement my webhook with firebase and stripe

fast kiln
#

๐Ÿ‘‹ Hopping in here!

limber crystal
#

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

limber crystal
#

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

fast kiln
#

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

limber crystal
#

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

fast kiln
#

Is your issue with your webhook event handler code not working, or that you don't have a production webhook set up?

limber crystal
#

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

fast kiln
#

Did you deploy your app?

limber crystal
#

yes

#

checkout will only work if you are signed in

#

so it will error you if u checkout without a user

fast kiln
#

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

limber crystal
#

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

fast kiln
#

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?

limber crystal
#

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

fast kiln
#

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?

limber crystal
#

how do i log it

#

locally right

#

console log the secret is there

fast kiln
#

Is it the correct secret though? Does it match what you have in the dashboard?

limber crystal
#

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?

fast kiln
#

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

limber crystal
#

okay thank you for your time for now

#

i will look into it

#

thank you!!

fast kiln
#

๐Ÿ‘

limber crystal
#

wait

#

karbi

#

i got the 200 ok

#

but my firebase still nothing?

#

oh thats at 2:18

fast kiln
#

Have you checked your firebase logs to see if anything stands out there?

limber crystal
#

Nothing ๐Ÿ˜ฆ

#

Redirecting to /api/webhook (308)

#

thats what i get on stripe

fast kiln
#

Where specifically are you seeing that?

limber crystal
#

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

fast kiln
#

Yes, but where? In the dashboard looking at the webhook event? In your server logs?

limber crystal
#

yes my stripe dashboard

#

on developers

#

webhooks

#

yes!!! im getting closer!

fast kiln
#

Can you share the event ID you're seeing that with? Should be something like evt_123

limber crystal
#

let me see

#

evt_1MvSJnF4hmr5JS7oup7FxBc4

fast kiln
#

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

limber crystal
#

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

fast kiln
#

That's the request to create the webhook endpoint - that's unrelated to actually getting your endpoint to work and accept eents

limber crystal
#

i see...

fast kiln
#

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

limber crystal
#

ok

#

nothing!!! :/

#

wait

#

i think it may be my webhook file

#

:/

#

i love programming

#

fix one thing

#

break 10

#

โค๏ธ

#

unlimited questing

fast kiln
#

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

limber crystal
#

YEP

#

sorry caps

#

yep that was exactly what i was going to do

#

after going to the gym to relieve some stress...

#

thanks for all your help!!! it got me closer than i was 8 hours ago