#Jane_Zhong

1 messages ยท Page 1 of 1 (latest)

rotund valeBOT
radiant kettle
devout spoke
#

Hi my friend ,thank you so much for your answer . I know the way delete one by one but it is a bit tough :p ,Therefore ,I was thinking if there is a easier way .

#

Hmmm , I have another question , I have realize that ,when submit all the datas to create an Express Account ,if you fill all the fields in one time ,the account will only create one for a user in one time .However ,if modify the form before submittin ,will create two times ... I am not sure is it the problem of Stripe or the webhook .As I am using Node.js .Could you please take a look my webhook ? Thank you so much in advance !

radiant kettle
#

However ,if modify the form before submittin ,will create two times
Can you share an example ?

devout spoke
#
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.updated") {
      const account = event.data.object;
      const previousAccount = event.data.previous_attributes;

      if (account.charges_enabled && !previousAccount.charges_enabled) {
    


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


    res.json({ received: true });
  }
);

radiant kettle
#

Yes this is your code, so it looks like your code is creating twice the account

devout spoke
#

Oh no ... Could you please help me modify it ?

#

It dosen't have node.js version in your doc .

radiant kettle
#

This is a particular use case, you need to do a check on account.id if it exists on your database, and create a Withdraw only if no elements exists...

devout spoke
#

Ahh ,ok ,thank you my friend ! ๐Ÿ˜„

radiant kettle
#

Welcome!

rotund valeBOT