#Jane_Zhong
1 messages ยท Page 1 of 1 (latest)
๐ happy to help
const account = webhook.data.object;
const previousAccount = webhook.data.previous_attributes;
if (account.charges_enabled && !previousAccount.charges_enabled) {
// The account was just created and is fully set up and ready to process payments
// Do something with the account data
console.log("Webhook:user's express account created!", account);
}
}
```
would you mind sharing the webhook endpoint ID? we_xxx
Hi tarzan , not at all ,glad to share ๐ โ``` app.post(
"/stripe",
bodyParser.raw({ type: "application/json" }),
async (req, res) => {
const sig = req.headers["stripe-signature"];
let event = JSON.parse(req.body);
try {
event = stripe.webhooks.constructEvent(
req.body,
sig,
process.env.STRIPE_WEBHOOK_SECRET
);
} catch (err) {
// On error, log and return the error message
console.log(`โ Error message: ${err.message}`);
return res.status(400).send(`Webhook Error: ${err.message}`);
}
// for express account
if (event.type === "account.update") {
const account = webhook.data.object;
const previousAccount = webhook.data.previous_attributes;
if (account.charges_enabled && !previousAccount.charges_enabled) {
// The account was just created and is fully set up and ready to process payments
// Do something with the account data
console.log("Webhook:user's express account created!", account);
}
}
res.json({ received: true });
}
);โ```
Are you talking about this ?
no the ID from your dashboard
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
we_1MjS11Em6oZta2poZAiIVhzz
thanks
To you ๐
so basically as I suspected you created the webhook endpoint to listen on the events of your own account
on your dashboard when you create a new Webhook Endpoint you need to specify "Listen on Events on my connected accounts"
otherwise the event account.updated will not trigger for you
Oh,where can I find it ?
and you also have a typo it's account.updated and not account.update
when you create a new webhook endpoint
you also need to add the event to the list of events you wish to listen to
since in that webhook endpoint there's only payment intent events on your own account
The wehook I created for listen to the user's account creation ,could you please help me how to modify it in orde to listen to the user's account create event ?โ```
app.post(
"/stripe",
bodyParser.raw({ type: "application/json" }),
async (req, res) => {
const sig = req.headers["stripe-signature"];
let event = JSON.parse(req.body);
try {
event = stripe.webhooks.constructEvent(
req.body,
sig,
process.env.STRIPE_WEBHOOK_SECRET
);
} catch (err) {
// On error, log and return the error message
console.log(`โ Error message: ${err.message}`);
return res.status(400).send(`Webhook Error: ${err.message}`);
}
// for express account
if (event.type === "account.update") {
const account = webhook.data.object;
const previousAccount = webhook.data.previous_attributes;
if (account.charges_enabled && !previousAccount.charges_enabled) {
// The account was just created and is fully set up and ready to process payments
// Do something with the account data
console.log("Webhook:user's express account created!", account);
}
}
res.json({ received: true });
}
);โ```
it's not the code you should worry about but rather the webhook endpoint creation
I don't really understand how to create a webhook endpoint in this case .Because ,I only have the one that I just showed you above .Could you please guide me how to do it ? Or show me docs about it ?Thank you so much in advance !
you need to go to your dashboard https://dashboard.stripe.com/test/webhooks and create a new webhook endpoint
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
there you need to select Events on Connected accounts as shared by the screenshot earlier
and you need to select the events you want to listen to
in this case you need to include account.updated
one last thing you need to change in your code is the typo I mentioned account.updated insteead of account.update
if (event.type === "account.updated") {
Ahhh ,I seee ! Thank you so much Tarzan ! You did really helped me !