#feni-patel_webhooks

1 messages ¡ Page 1 of 1 (latest)

split pathBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1303691949546668134

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

inland summit
#

That will only receive events from connected accounts connecting/onboarding to your platform

daring frigate
#

Okay, can you provide code snippet with nodejs and mongodb?

#

also can you suggest how can i implement step by step ?

inland summit
inland summit
daring frigate
#

first point is how can implement this account.updated webhooks and how can i test that IsOnboarding flag is updated or not into my database?

inland summit
#

You'd start with the guide I just shared

daring frigate
#

Okay thanks, i will provide more info if i am facing any info.

#

Okay so i have updated my webhooks code. can you guide me weather i am on right track or not?
app.post('/webhooks', async (req, res) => {
const sig = req.headers['stripe-signature'];
let event;

// Verify the webhook signature
try {
    event = stripe.webhooks.constructEvent(req.rawBody, sig, 'your_endpoint_secret');
} catch (err) {
    console.error('Webhook signature verification failed:', err.message);
    return res.status(400).send(`Webhook Error: ${err.message}`);
}

// Handle the account.updated event
if (event.type === 'account.updated') {
    const account = event.data.object;

    // Check if the account has completed onboarding
    const isOnboarded = account.requirements.currently_due.length === 0;

    // Update the restaurant's onboarding status in your database
    await Restaurant.updateOne(
        { stripeAccountId: account.id },
        { isOnboarded: isOnboarded }
    );

    console.log(`Updated onboarding status for account: ${account.id} - Onboarded: ${isOnboarded}`);
} else {
    console.log(`Unhandled event type ${event.type}`);
}

// Respond to Stripe
res.status(200).send('Received');

});

#

I have provided my code for your review. please review it

inland summit
#

Did you test it? Try and simulate an event with the CLI

daring frigate
#

how can i test this into my local system