#King Rom II - Webhooks

1 messages · Page 1 of 1 (latest)

summer briar
#

Hello! When you say "on the page" what do you mean?

#

Can you reply here?

brazen egret
#

Well, if I understand correctly, the webhook needs to be a page on my website right? app.post('mywebhookpage')

summer briar
#

It needs to be a URL on your website. There's no "page" though, as in no human will visit the URL, and thus no page needs to be displayed. Webhooks are designed to let Stripe send your integration Events when certain things happen; Stripe's servers talk directly to your server via the webhook URL you provide.

brazen egret
#

Okay so it should be an endpoint to my firebase database? I'm sorry for asking obvious things, but I've read documentation various times

summer briar
#

It's a lot like a reverse API. When you make a request to the Stripe API with info you don't get a page back, you get a response containing JSON. With a webhook we're making a request to your URL with info so your server knows when something happened.

#

At a high level what are you trying to build?

brazen egret
# summer briar At a high level what are you trying to build?

App xyz with a premium feature.
After payment I need to write a customer to my own database somehow, and upgrade said user for premium functionality.
The demo payments are successful, it gets added to my credit in the dashboard. User is redirected to the success url. Then comes the part where I need to use the available object to write certain info to my database. Yet I'm finding it difficult to understand. The webhook sends data to my specified path, and from there I need to handle the data?

In the lower part of my post request (the template I copied from stripe site) we're handling different events.
Is this where I need to define my logic on the event.type object?

summer briar
#

Yep, that's correct. You add logic there for the Events you care about and process them as you see fit.

#

Which guide/doc are you looking at?

brazen egret
#

Okay great. The defaults are intent succeed and method attached. I think I'm interested in checkout.session.completed, so I'd change the case to that.
There I put my function that handles another fetch request to add said data to firebase yes.

Which path should I specify to handle the webhook? It's a file I create right

#

I feel like I shouldn't even be doing this yet I refuse to give up

summer briar
#

Which path should I specify to handle the webhook? It's a file I create right
It doesn't need to be a file. The path can be whatever you want, it's entirely up to you.

brazen egret
#

It's the literal template I copied minus the fulfillOrder handler. It makes more sence this way. Let me see what I can do, thanks for now!

brazen egret
summer briar
#

The path really doesn't matter, and doesn't need to change in production. It can be anything you want. A lot of people do something like /stripe-webhooks or /stripe/webhooks or things like that, but just /webhook is fine too.

brazen egret
#

Thanks alot

brazen egret
#

I've come this far. Am I handling data correctly like this? I'm getting nothing written to DB, and I can't display console errors since it's redirecting after successful payment

languid prawn
#

👋 Rubeus had to head out, but give me a minute to catch up and I can help

#

What debugging have you done so far? Have you confirmed that postFirebase is being called? Have you confirmed that the event is hitting your endpoint successfully?

brazen egret
#

Well I'm working from this template.
fulfillOrder() is postFirebase()

I'm getting the object logged in my vscode terminal, along with a success redirect, therefor I was expecting this to work

languid prawn
#

What do you mean by the "success redirect"?

brazen egret
languid prawn
#

That Checkout redirect to the success URL has nothing to do with the actual webhook event though - the webhook event is sent to a different endpoint entirely. Are you using something like stripe listen to set up Stripe sending the webhook events to your local endpoint?

brazen egret
#

Yeah exactly, I set up the listener. I think the problem is somewhere lower, I'm having a typeError of undefined reading prototype for the template I copied. That needs sorting first. Let me see what I can do