#Themax1-webhooks

1 messages · Page 1 of 1 (latest)

crimson galleon
#

What are you looking to do with webhooks?

delicate totem
#

I really don't know, what can I use them for?

#

do I have to use them?

#

I didn't understand their porpuses

pseudo mango
#

I use them to send a purchase event to my application which updates our database with the order specifics.

#

Also use them to let us know when a subscription is renewed so we can update the corresponding dates in our database.

crimson galleon
#

Yeah, they are used to get real time updates on things that happen on your account

delicate totem
#

But I cannot just simple do a endpoint on my backend to happen after I fired my create payment intent for example?

crimson galleon
#

They are recommended/required in some circumstances but it is hard to give you general

#

That is what a webhook would be

#

You give us an endpoint on your server that we POST data to

delicate totem
#

so I use this webhooks on my application or I use them on my backend?

#

thats whats is confusing me

crimson galleon
#

Yes they are backend

delicate totem
#

but how I execute them

#

thats whats bothering me

crimson galleon
#

I would read our doc on that

delicate totem
#

I tried, but it's so confused for me

#

I saw that a create a webhook, then I call him when I want to do something?

pseudo mango
#

We run in Google cloud and have a specific function setup for catching the Stripe webhook.

yes it is possible to catch the webhook with either our app or a backend, best practices say go directly against a backend, not a webapp.

delicate totem
#

got it, but my main question is how I use them

#

like

#

if is real time

#

lets say I execute a payment intention or update a user

#

how I trigger this webhook?

crimson galleon
#

You do not trigger it, Stripe sends you event data

delicate totem
#

but how I get this event data?

#

on my backend?

#

but how?

crimson galleon
#

How, in what way?

delicate totem
#

i capture after I do a update a user for example?

#

on my endpoint

#

that update the user for example

pseudo mango
#

When you setup a webhook in stripe you tell it which address to POST to and which actions you want it to happen on (e.g. invoice_paid).

delicate totem
#

lets say someting like this:

updateUser() => { //update logic user, then capture webhook event and return that to my app }

something like this?

delicate totem
#

because i saw that or different types of config here

#

add a endpoint and test on local environment

pseudo mango
#

The Stripe documentation is pretty good on setting up webhooks and how to test them in local development.

delicate totem
#

so basically this webhooks are something that I can use to performance some calls on my application, like, when I update a user, I don't have to do another endpoint to retrieve him, with webhooks this are going to do realtime and don't need to do manually

#

but when goes to production, I going to use them in another way?

delicate totem
#

i really needed a real use case

pseudo mango
#

Perhaps @crimson galleon can assist with some use cases. I don't have anything written

delicate totem
#

in the app I'm doing, I need that to be right way after i finish complete my user

#

gotcha

#

but my question is like, I have to do a main endpoint on my api to only recieve webhooks and manage them right?

#

or wrong?

pseudo mango
delicate totem
#

hmm gotcha

#

and he's going to execute automatcly on something happen

#

lets say I have a endpoint on my api that update striper user

#

if this endpoint webhook is listening to update_user type

#

he's going to fire?

pseudo mango
#

Where did you get update_user from?

crimson galleon
#

Thanks for the assistance @pseudo mango

pseudo mango
#

You want me to stop @crimson galleon ?

crimson galleon
#

Oh no feel free to keep going if you want. Genuine appreciation

delicate totem
#

different name

#

sorryu

pseudo mango
#

If you want to setup a webhook to send data to your api whenever a customer is updated you would select the customer.updated event when setting up the webhook in the stripe dashboard.
Then whenever there is an update to a customer record in Stripe that webhook will fire

delicate totem
#

so is automactly them

#

I just need to configure actually

pseudo mango
#

Yes, it is all based on events which happen at stripe

delicate totem
#

lets say a customer.updated, when the webhook is fired and captured by the event, I can do a update on my database with new data?

pseudo mango
#

A good automatic example is subscriptions. Once a subscription is in place we really have nothing more to do with it. Stripe automatically charges the customer on the subscription interval.
Though we do things in our app for subscribers and need to know who is subscribed, who isn't etc. So our webhook is configured to let us know when a subscription renews, or is set to not renew, and a few other things.

delicate totem
#

and other thing he captures the customer I'm updating right?

pseudo mango
delicate totem
#

gotcha

pseudo mango
#

The stripe documentation, once you get your head around it will describe what data is in the payloads, etc. It will take some time, so allow for that. The support team here have been really good on helping me understand all of this craziness

delicate totem
#

it's good to use webhook when I create payment_intent with event payment_intent.created?

#

or is not that necessary?

#

like, webhook is only necessary if I going to update something on my database or not necessary?

pseudo mango
#

I can't answer that as I don't know what your goal is with the data, what it is you need to do. Plus, I can only go off my own experience and smarts. I have not experienced a lot of different configurations as the support team here has

pseudo mango
delicate totem
#

interesting

crimson galleon
#

Yes, exactly. What you do and do not need webhooks for is a design question that you need to answer for yourself

#

Again, in some places it is recommended. For example when you take a payment, it is recommended to listen to the related webhook as part of your fulfillment logic

delicate totem
#

so this webhooks is going to help me a lot, because I was going to do manually, I'm using connected users and everytime they close something on my app I was going to call a endpoint to update on my database, but if that webhook this is something i don't need to do "manually"

crimson galleon
#

Exactly. That is a great example of when a webhook is beneficial

delicate totem
#

hmmm that is really nice

#

for what I reading here and with that explanation, using webhook doesn't seems that hard

pseudo mango
#

It’s an http request. :).

delicate totem
#

yeah, but I didn't know that is called automactly by stripe, I thought it need some really hard configuration

pseudo mango
#

The configuration is pretty straight forward and the cli is great for testing code (you’ll find this in webhook docs 😀)

delicate totem
#

hmm ok

#

going to do some testing here them

#

ty for both helping me

pseudo mango
#

You’re welcome

delicate totem
#

one more thing, I saw that I can create a webhook endpoint using stripe.webhookEndpoints.create, I have to use this right?

crimson galleon
#

You can also create them via your dashboard

#

Either works

delicate totem
#

but how I configure to listen to connected users?

#

on the endpoint is kinda easy

crimson galleon
delicate totem
#

gotcha, so instead of doing stripe listen --forward-to, I do --forward-connect-to?

crimson galleon
#

While testing yes

delicate totem
#

but I need to do something different on my webhook endpoint?

#

going to try out

crimson galleon
#

The same code should work while testing. Let us know if you have any further questions

delicate totem
#

I saw that stripe.webhooks.constructEvent(request.body, sig, endpointSecret recieve I request.body, what can I pass for him?

crimson galleon
#

Pass to what? The constructEvent call?

delicate totem
#

yes

jolly basin
#

@delicate totem I'm confused, you pass the things you mentioned in that call, the webhook event body, the signature header value, your webhook endpoint secret

delicate totem
#

wait what

#

I'm confused

#

haha

jolly basin
#

let's take a step back, if you reword your question to me fully

delicate totem
#

I'm constructing my wehbook endpoint on my api, and I saw this stripe.webhooks.constructEvent(request.body, sig, endpointSecret), what can my request.body have?

#

what body properties I can send?\

jolly basin
#

what can my request.body have?
have you referenced the Webhook documentation? this is all explained there, it has to be the full raw POST request body

#

let me link you to it

#

that has almost everything you need to set up your webhook endpoint

delicate totem
#

ok

#

well I tried to setup a webhook endpoint and run local

#

with webhook connected accounts

#

but I don't it's working

#

first I run stripe listen --forward-connect-to localhost:3333/webhook

#

stripe trigger --stripe-account account.updated

#

but it gives me a error

jolly basin
#

but I don't it's working
how is it not working? please do share more details

delicate totem
#

I think i now what I did wrong

jolly basin
#

is there an error ? does the code not compile?

delicate totem
#

one second

jolly basin
#

could be anything

delicate totem
#

this error

delicate totem
#

and if i execute like this stripe trigger --stripe-account acct_1JtcgIQ1mfvI6KUR account.updated, it gives me another error

#

Trigger failed: Request failed, status=403, body={
"error": {
"message": "Connect platforms cannot create new accounts on behalf of their connected accounts.",
"type": "invalid_request_error"
}
}

#

I'm trying to update a connected account on a endpoint

#

but he's not executing my webhook

#

wait a sec, I can not test my webhook locally without stripe cli?

jolly basin
#

and if i execute like this stripe trigger --stripe-account acct_1JtcgIQ1mfvI6KUR account.updated, it gives me another error
ok so this one is that you're asking your Connect account to update its Connect account, which won't work

so let's come back to this part:

stripe trigger --stripe-account account.updated
[3:45 PM] Themax1: but it gives me a error
what error did that give

#

wait a sec, I can not test my webhook locally without stripe cli?
you can via ngrok which publicly tunnels your local endpoint, or just use CLI which is simplest

delicate totem
#

so if I have a endpoint on my api /updateAccount, he's not goint to trigger webhook?

#

let's go from the beggining

#

I have two endpoints:

1 - webhook endpoint type POST / going to check what event i called
2 - my endpoint that I update a connected account

when I do stripe listen --forward-to localhost:4242/webhook, I want to be on my webhook endpoint right?

#

and with testing locally, can I execute my second endpoint and hope that webhook trigger or not?

#

because locally I can not test like that?

delicate totem
limber bobcat
#

Hello! I'm taking over for @jolly basin, let me get caught up. Hang on...

delicate totem
#

np

limber bobcat
#

I'm not sure I understand your latest questions. Let's work on them one at a time.

so if I have a endpoint on my api /updateAccount, he's not goint to trigger webhook?

What is "he's" referring to here?

delicate totem
#

my endpoint

#

/updateAccount

#

my english doesn't help me

limber bobcat
#

Okay, so you have a webhook endpoint set up at /updateAccount on your integration and you want to trigger an account.updated event that will be sent to it, correct?

delicate totem
#

no

#

I have a webhook endopoint called /webhook, when I run my endpoint /updateAccount, I want to trigger account.updated event that is going to trigger my wehbook endpoint

limber bobcat
#

Meaning your client-side code hits /updateAccount, runs your server-side code, that updates an Account, generates an account.updated event, and that should be sent to /webhook on your server?

delicate totem
#

yes

#

but on local it's not working

limber bobcat
#

Okay, which piece of it is not working locally?

delicate totem
#

I run /updateAccount, but doesn't trigger my webhook

#

can you help me really quickly with another question?

#

more important than that acctually

limber bobcat
#

What code inside /updateAccount do you expect to update an Account and trigger the webhook?

#

Sure.

delicate totem
delicate totem
# limber bobcat Sure.

Ok, I'm trying to create a connected account type being express and when I generate the URL of type onboarding_proccess, on my app I open the browser so he can continue the configuration of his account, but it says that I have to login-in to my Main Stripe account, but this is not ideal, because the user doens't have to login-in on my platform account, only I have this

#

so what I have to do in this URL so he can be autheticated to continue his onboarding proccess?

limber bobcat
#

You should open the URL in a different web browser or private/incognito mode. If you open it in a browser that's already logged in to an existing Stripe account Stripe will try to reuse some of the information from the existing account to speed up creation of the new one.

delicate totem
#

but I not logging in any account on my phone

#

it always have to be on private/incognito?

limber bobcat
#

No, only while you're testing.

#

Are you using the same email address as your platform account?

#

That could also be why.

delicate totem
#

no

limber bobcat
#

Can you share a screenshot of what you're seeing?

#

Make sure to remove any sensitive/non-public information.

delicate totem
#

ok, one sec

#

going to take screenshot and edit

#

Ohh I think I figure it out, if a create a connected account but didn't end the setup-up and create another with the same email, he's going to try to login me in right?

limber bobcat
#

Yep. If you want to start from scratch you need to use a different email address.

delicate totem
#

ohh gotcha, but let's say the user didn't finished and it's going to continue later, I saw that I have to generate another link because he expires first timing opening, When i generate another link, it's going to ask he to login too?

limber bobcat
#

Yes.

delicate totem
#

but how? because connected account doesn't have password

#

how is going to login?

limber bobcat
#

It should only prompt if they have an account with a password.

delicate totem
#

ohhh gotcha, going to try out that, one sec

#

ohh didn't ask

#

gotcha

#

another question, if I delete a connected account, I can make with the email I already had used right?

limber bobcat
#

I think so, yeah. Who's your email provider? Is it Gmail?

delicate totem
#

wait, my connected account or platform account?

limber bobcat
#

I'm wondering because if you have a Gmail account you can use the + to create new email addresses.

#

For example, if you have example@gmail.com you can do example+connect1@gmail.com and example+connect2@gmail.com and so on.

delicate totem
#

hmm

#

but I going to delete them all to test

#

but know I get it

limber bobcat
#

The email address test@test.com.br is a real email address though.

#

You should use either an email address you control or an explicit test address (like something-unique-to-you@example.com).

#

Ideally you would use your-gmail-account+something-specific-for-the-connect-account@gmail.com or something along those lines. 🙂

delicate totem
#

hmm gotcha

limber bobcat
#

Yeah, that domain is a real domain that's owned by a company.

delicate totem
delicate totem
limber bobcat
#

Yeah, I'm saying while you're testing you should use your own email addresses.

delicate totem
#

hmm

limber bobcat
#

When people sign up for real in live mode they'll use their own addresses.

delicate totem
#

so if a use + signal, I can use my own email for testing porpuses?

limber bobcat
#

If you have a Gmail account or another email provider that supports using the + then yes.

delicate totem
#

or a temp email too right?

limber bobcat
#

Yeah, you can create a bunch of throwaway email addresses/accounts but it's more work that way.

delicate totem
#

hmm gotcha

#

ty

#

Ok, going back to the webhooks

#

I trying to updating a connected account if my endpoint /updateConnectedUser for example, when I execute this and completed, I thought that my webhook endpoint called /webhook was going to be called

#

but I think that's only on production mode?

#

because this code here on my /updateConnectedUser update a connected account:

        const account = await stripe.accounts.update(
            'acct_1JtcgIQ1mfvI6KUR',
            { business_profile: { name: 'Teste2' } }
        );
limber bobcat
#

account.updated events happen in both live and test modes, but you may not be set up to receive that event in your particular configuration. Can you give me the ID of an account.updated event that you expected to be delivered to a specific webhook endpoint?

delicate totem
#

how can I get this ID event?

#

I'm really lost

limber bobcat
delicate totem
#

it's actually not listed there

#

I wonder why

limber bobcat
#

You can use the Filter button at the top to narrow down to that event type specifically:

#

You're using Connect, so the event would exist on the connected account, not your platform account. Make sure you're viewing the Dashboard as the connected account where the event exists, then go to Developers > Events and look there.

#

Or make sure you're logged in as that account.

delicate totem
#

I'm updating a connected account

#

so that would appear where?

#

with test mode on

limber bobcat
#

If you're logged in as the connected account, yes.

#

Not if you're logged in as your platform account.

delicate totem
#

I'm logged as my platform account\

#

I have to login with one of my connected accounts?

limber bobcat
#

You can either log in as the connected account or view your Dashboard as the connected account. Do you know how to do that?

delicate totem
#

so i have to generate I link to my connected account dashboard right?

limber bobcat
#

No.

delicate totem
#

or just go in connect?

limber bobcat
#

While logged in as your platform account go to Connect > click on the connected account in question > click on the ••• button in the top right corner > click on View Dashboard as this account

delicate totem
#

ohh okay

#

gotchz

#

gotcha

#

evt_1JtgxwPsUEu1eseMnXOo9ISL

#

my event

#

my webhook responded to this event

#

but got 400 error

#

i wonder why

limber bobcat
#

The 400 came from your code, so you'd need to investigate what happened on your end.

delicate totem
#

in my webhook endpoint right?

limber bobcat
#

The code that handles /webhook requests, yeah.

delicate totem
#

event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);

#

i think is this

#

i think is something to if my body

#

with*

#

or is not working with connected accounts

#

what is a suspect

limber bobcat
#

You need to pass the raw body of the incoming request to that function for it to work, and you need to make sure your endpointSecret is set to the one Stripe CLI gave you.

#

What error did that function throw?

delicate totem
#

because i did not see how I activate to work in connected accounts

#

that is so weird

#

because to test with connected account you have to pass stripe listen --forward-connect-to localhost:3333/webhook

#

but if a send a update

#

my event doest go throught

limber bobcat
#

I'm not sure I understand what you're saying. Do you have the error the constructEvent() code produced?

delicate totem
#

No signatures found matching the
expected signature for payload. Are you passing the raw request body you received from Stripe?

limber bobcat
#

Yeah, sounds like you didn't pass in the raw body of the request.

delicate totem
#

but i need to pass what information to my raw body or don't need too?

limber bobcat
#

I don't understand. Can you rephrase?

delicate totem
#

tried to add the middleware por raw body

#

but know is giving me this

delicate totem
limber bobcat
#

No, the body of the incoming webhook request is set by Stripe and must not be modified in any way before it's passed to the constructEvent() function.

delicate totem
#

ohh gotcha

#

how do I know if I using the right secret key for webhook?

limber bobcat
#

If you're using the Stripe CLI it's the one given to you when you run stripe listen.

delicate totem
#

the key is right

limber bobcat
#

Yeah, it's something modifying the body of the request before it hits that function. I recommend you read through the GitHub thread I linked above and try various solutions posted there.

#

Typically you need to move your raw body parsing code to run first before any other middleware.

delicate totem
#

i tried the middleware one

#

but know is giving me this [ERROR] Failed to POST: Post "http://localhost:3333/webhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

limber bobcat
#

I don't know what's causing that error. Maybe an endless loop somewhere?

#

Can you add additional logging to your code and find out where it's getting stuck?

delicate totem
#

I think is falling in my middleware

#

trying multiple solutions on that thread

#

oh

#

gotcha

#

but still when I run /updateConnectedUser my endpoint

#

the webhook doesn't trigger

#

only when I do this on stripe cli: stripe trigger account.updated

hazy ridge
#

👋 I'm just hopping in for @limber bobcat since they had to step away - give me a minute to catch up

delicate totem
#

np

#

I think I figure out

hazy ridge
#

What was the issue?

delicate totem
#

I was updating my user with mock data to test out, so was sending the same name that was already there, so he's was not updating anything

#

I think was that

#

if I send the same data, that's not updating anything

hazy ridge
#

ahhh gotcha 👍

delicate totem
#

going to test even futher, but I think that was it