#feni-patel_webhooks

1 messages · Page 1 of 1 (latest)

runic etherBOT
#

👋 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/1303985276971913257

📝 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.

crimson zephyr
#

I am working on one task where i need to confirm that merchant successfully onboarded their self into stripe using connected account link. for that i am using account.updated webhook to perform flag updation for this. but i am getting error, like "Webhook signature verification failed: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing". I am also provided code for you. so can you help me with this error?

static async webhook(req,user){
//const { stripe } = await stripeService.getStripeInstance();
const sig = req.headers['stripe-signature'];
console.log("sig",sig)
console.log("stripe",stripe)
let event;

try {
    console.log('req.body',req.body)
    console.log('webhookSecret',webhookSecret)
    event = stripe.webhooks.constructEvent(req.body, sig, webhookSecret);
    console.log("event",event);
} catch (err) {
    console.error('Webhook signature verification failed:', err.message);
}

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

    const isOnboarded = account.requirements.currently_due.length === 0;

    // 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}`);
}
return true

}

chrome tangle
#

Your system can listen to account.updated event and check the following properties:

Onboard connected accounts by redirecting them to a Stripe-hosted onboarding flow.

#

I don't see your code maintain the request body in its raw form with any of the following:

Learn how to set up and deploy a webhook to listen to events from Stripe.

GitHub

If you use in your express app bodyParser.json() for all routes, and then have a dedicated route for stripe's webhook, then the second call to bodyParser.json({verify: ...}) as done in the exam...

crimson zephyr
#

but still getting the error

chrome tangle
#

Does your node middleware configure parse all the requests to JSON somewhere? For example, if you have app.use(express.json()); prior to your webhook route, this will parse the requests in all JSON, not in raw form before reaching to your webhook function.

crimson zephyr
chrome tangle
#

Can you move your webhook route before app.use(express.json())?

#

The order of where app.use(express.json()) is placed matters

crimson zephyr
#

sure i will check this

#

currently i have checked with manually using the stripe listen --forward-to localhost:3007/stripe/webhook. and now after your suggested changes i am not able to get the error. but now let's suppose one merchant onboarded them self then i need to check weather this webhook run and update the flag into my database or not. then how can i check this?

chrome tangle
#

You can check whether account.updated event is sent and those properties mentioned above are checked by adding additional logs

crimson zephyr
#

so when any merchant onboarded their self then this account.updated webhook run automattically correct ?

chrome tangle
#

Any change on the hosted onboarding will result in account.updated event. You should still check the charges_enabled, payout_enabled and requirements properties to determine if the connected account has charge and payout enabled and whether there is any pending requirements to complete. If both of charge and payout are enabled and no requirement is pending, then the connected account is fully onboarded

crimson zephyr
#

Okay thank you

chrome tangle
#

No problem! Happy to help 😄