#Jane_Zhong

1 messages ยท Page 1 of 1 (latest)

trim reefBOT
clear wedge
#

๐Ÿ‘‹ happy to help

#

would you mind sharing more details please?

#

event IDs, code snippets etc

summer plank
#

Yes ,this is the webhook I set , and the Express Account create twice when the user modify twince the form : ```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}`);
}
//handle the account create
if (event.type === "")
  if (event.type === "account.updated") {
    // Handle account updates
    const account = event.data.object;
    const previousAccount = event.data.previous_attributes;

    if (
      account.charges_enabled &&
      !previousAccount.charges_enabled &&
      !expressAccountCreated
    ) {
      expressAccountCreated = true; // Set flag to true after account creation
      // The account was just created and is fully set up and ready to process payments
      // Do something with the account data
      const { userPublicId } = account.metadata;
      const user = await UserInfo.findOne({ publicId: userPublicId });

      await Withdraw.create({
        userId: user.id,
        card: account.id,
        country: account.country,
        phone: account.company.phone,
        email: account.individual.email,
        valid: true,
      });
    }
  }

}
);

spark mist
#

Hi! I'm taking over this thread.

summer plank
#

Hi Soma ,nice to see you again

spark mist
#

the Express Account create twice when the user modify twince the form
What do you mean by "user modify twice the form"?

#

And how do you create the Express accounts?

summer plank
#

Well , when set up a function where allow user's to create Express Account ,users need to fill up datas such as Email ,company etc . And sometimes ,if users skip some form ,the form won't notice you that 'this cant be empty' till the last step for submitting .And it will need users to complete the forms in order to submit those datas .And after the user fill up all the information ,and submit ,it will create twice Express Account . And it won't happen if the user fill up all the information and submit in one time .

summer plank
#

Is it possible to detect in the webhook if the Express Account is Limited ,delete this account ?

spark mist
summer plank
#

Because ,event though create twice ,one of the account wil be Limited

#

Ah , i seee, let me take a look and try it out