#Themax1-webhooks
1 messages · Page 1 of 1 (latest)
Have you seen our docs on this? https://stripe.com/docs/webhooks
What are you looking to do with webhooks?
I really don't know, what can I use them for?
do I have to use them?
I didn't understand their porpuses
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.
Yeah, they are used to get real time updates on things that happen on your account
But I cannot just simple do a endpoint on my backend to happen after I fired my create payment intent for example?
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
so I use this webhooks on my application or I use them on my backend?
thats whats is confusing me
Yes they are backend
I would read our doc on that
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?
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.
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?
You do not trigger it, Stripe sends you event data
How, in what way?
i capture after I do a update a user for example?
on my endpoint
that update the user for example
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).
lets say someting like this:
updateUser() => { //update logic user, then capture webhook event and return that to my app }
something like this?
but I do that on local or production?
because i saw that or different types of config here
add a endpoint and test on local environment
The Stripe documentation is pretty good on setting up webhooks and how to test them in local development.
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?
this docs are really confusing me more
i really needed a real use case
This depends on how you want to construct your application. If you need the response now, to work with it, you may want to query the Stripe API for the specific data.
The webhook is real-time, but there is still time involved so you don't know exactly when it comes through, if there was an issue, etc. These questions are difficult in a chat system
Perhaps @crimson galleon can assist with some use cases. I don't have anything written
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?
To catch (receive) the webhooks, yes. You will need to create an endpoint accessible, and addressable from the Internet so you can point to it when configuring the webhook in the Stripe developer dashboard
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?
Where did you get update_user from?
Stripe events, which is what you configure on matching events to trigger the webhook are listed here: https://stripe.com/docs/api/events/types
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Thanks for the assistance @pseudo mango
You want me to stop @crimson galleon ?
Oh no feel free to keep going if you want. Genuine appreciation
account.updated
different name
sorryu
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
ohh
so is automactly them
I just need to configure actually
Yes, it is all based on events which happen at stripe
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?
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.
and other thing he captures the customer I'm updating right?
Yes, that is what it is for. You take the payload from the webhook and update your database, act on it, etc.
gotcha
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
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?
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
Well, what else would you use it for? A notification maybe
hmm gotcha
interesting
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
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"
Exactly. That is a great example of when a webhook is beneficial
hmmm that is really nice
for what I reading here and with that explanation, using webhook doesn't seems that hard
It’s an http request. :).
yeah, but I didn't know that is called automactly by stripe, I thought it need some really hard configuration
The configuration is pretty straight forward and the cli is great for testing code (you’ll find this in webhook docs 😀)
You’re welcome
one more thing, I saw that I can create a webhook endpoint using stripe.webhookEndpoints.create, I have to use this right?
With a connect webhook https://stripe.com/docs/connect/webhooks
gotcha, so instead of doing stripe listen --forward-to, I do --forward-connect-to?
While testing yes
The same code should work while testing. Let us know if you have any further questions
I saw that stripe.webhooks.constructEvent(request.body, sig, endpointSecret recieve I request.body, what can I pass for him?
Pass to what? The constructEvent call?
yes
@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
let's take a step back, if you reword your question to me fully
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?\
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
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
but I don't it's working
how is it not working? please do share more details
I think i now what I did wrong
is there an error ? does the code not compile?
one second
could be anything
this error
Trigger specific webhook events to be sent. Webhooks events created through
the trigger command will also create all necessary side-effect events that are
needed to create the triggered event as well as the corresponding A
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?
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
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?
but it's says if I pass connected true I can do that
Hello! I'm taking over for @jolly basin, let me get caught up. Hang on...
np
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?
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?
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
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?
Okay, which piece of it is not working locally?
I run /updateAccount, but doesn't trigger my webhook
can you help me really quickly with another question?
more important than that acctually
What code inside /updateAccount do you expect to update an Account and trigger the webhook?
Sure.
const account = await stripe.accounts.update(
'acct_1JtcgIQ1mfvI6KUR',
{ business_profile: { name: 'Teste2' } }
);
This update my connected account, so I think is a event of a webhook type
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?
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.
but I not logging in any account on my phone
it always have to be on private/incognito?
No, only while you're testing.
Are you using the same email address as your platform account?
That could also be why.
Can you share a screenshot of what you're seeing?
Make sure to remove any sensitive/non-public information.
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?
Yep. If you want to start from scratch you need to use a different email address.
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?
Yes.
It should only prompt if they have an account with a password.
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?
I think so, yeah. Who's your email provider? Is it Gmail?
wait, my connected account or platform account?
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.
See here for more information: https://www.idownloadblog.com/2018/12/19/gmail-email-address-tricks/
hmm
I creating my connected account with test@test.com.br just for testing porpuses
but I going to delete them all to test
but know I get it
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. 🙂
hmm gotcha
wait really?
Yeah, that domain is a real domain that's owned by a company.
ideally on production mode, the users are going to register with their on email address
didn't know about it
Yeah, I'm saying while you're testing you should use your own email addresses.
hmm
When people sign up for real in live mode they'll use their own addresses.
so if a use + signal, I can use my own email for testing porpuses?
If you have a Gmail account or another email provider that supports using the + then yes.
or a temp email too right?
Yeah, you can create a bunch of throwaway email addresses/accounts but it's more work that way.
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' } }
);
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?
You should be able to find it in your Dashboard: https://dashboard.stripe.com/events
Here for test mode: https://dashboard.stripe.com/test/events
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.
I'm updating a connected account
so that would appear where?
here right? https://dashboard.stripe.com/test/events\
with test mode on
If you're logged in as the connected account, yes.
Not if you're logged in as your platform account.
I'm logged as my platform account\
I have to login with one of my connected accounts?
You can either log in as the connected account or view your Dashboard as the connected account. Do you know how to do that?
so i have to generate I link to my connected account dashboard right?
No.
or just go in connect?
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
ohh okay
gotchz
gotcha
evt_1JtgxwPsUEu1eseMnXOo9ISL
my event
my webhook responded to this event
but got 400 error
2021-11-08 20:09:28 <-- [400] POST http://localhost:3333/webhook [evt_1JtgxwPsUEu1eseMnXOo9ISL]
i wonder why
The 400 came from your code, so you'd need to investigate what happened on your end.
in my webhook endpoint right?
The code that handles /webhook requests, yeah.
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
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?
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
I'm not sure I understand what you're saying. Do you have the error the constructEvent() code produced?
No signatures found matching the
expected signature for payload. Are you passing the raw request body you received from Stripe?
Yeah, sounds like you didn't pass in the raw body of the request.
This is a common issue with Node as so many things will modify the body. There are several different things you can try in this thread: https://github.com/stripe/stripe-node/issues/341
but i need to pass what information to my raw body or don't need too?
I don't understand. Can you rephrase?
tried to add the middleware por raw body
but know is giving me this
[ERROR] Failed to POST: Post "http://localhost:3333/webhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
do I have to pass any body information?
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.
If you're using the Stripe CLI it's the one given to you when you run stripe listen.
the key is right
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.
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)
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?
I think is falling in my middleware
trying multiple solutions on that thread
[200] POST http://localhost:3333/webhook [evt_1JthQ1Q56OlDpuXH5tCUMf8D]
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
👋 I'm just hopping in for @limber bobcat since they had to step away - give me a minute to catch up
What was the issue?
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
ahhh gotcha 👍
going to test even futher, but I think that was it