首页 > 解决方案 > 带有使用 NODEJS 的功能的问题 Stripe

问题描述

我正在尝试将 Stripe 集成到我的 MERN 应用程序中进行测试。从今天早上开始我就有问题了。

  raw: {
    message: 'You must provide an account with capabilities when creating an account link of type "account_onboarding" for an account in a country that is not enabled for Express. You can enable FR in your Country and Capabilities settings at https://dashboard.stripe.com/settings/applications/express',
    param: 'account',
}

我联系了 Stripe 帮助,但他们无法帮助我。他们唯一告诉我的是在这里选择 FR:https ://dashboard.stripe.com/settings/applications/express 。

问题保持不变。没有不同 :)

这是我的代码:

  try {
    // 1. find user from db
    const user = await User.findById(req.user._id).exec();
    console.log("USER ==> ", user);
    // 2. if user don't have stripe_account_id yet, create now
    if (!user.stripe_account_id) {
      const account = await stripe.accounts.create({
        type: "express",
      });
      console.log("ACCOUNT ===> ", account);
      user.stripe_account_id = account.id;
      user.save();
    }
    // 3. create login link based on account id (for frontend to complete onboarding)
    let accountLink = await stripe.accountLinks.create({
      account: user.stripe_account_id,
      refresh_url: process.env.STRIPE_REDIRECT_URL,
      return_url: process.env.STRIPE_REDIRECT_URL,
      type: "account_onboarding",

    });
    // prefill any info such as email
    accountLink = Object.assign(accountLink, {
      "stripe_user[email]": user.email || undefined,
    });
    // console.log("ACCOUNT LINK", accountLink);
    let link = `${accountLink.url}?${queryString.stringify(accountLink)}`;
    console.log("LOGIN LINK", link);
    res.send(link);
    // 4. update payment schedule (optional. default is 2 days
  } catch (err) {
    console.log("STRIPE ERROR", err);
    res.status(400).send("Stripe failed");
  }
};

预先感谢您的帮助 !

鲁尔丹。

标签: node.jsexpressstripe-payments

解决方案


寻找解决方案后。我在这里的文档中找到:https ://stripe.com/docs/connect/express-accounts

我只是在我的 stripe.create.accouts() 中添加国家。

新功能现在看起来像这样:

  try {
    // 1. find user from db
    const user = await User.findById(req.user._id).exec();
    // 2. if user dont have stripe_account_id yet, then create new
    if (!user.stripe_account_id) {
      const account = await stripe.accounts.create({
        country: 'FR',
        type: 'express',
        capabilities: {
          card_payments: {
            requested: true,
          },
          transfers: {
            requested: true,
          },
        },
      });
      // console.log('ACCOUNT => ', account.id)
      user.stripe_account_id = account.id;
      await user.save();
    }
    // 3. create account link based on account id (for frontend to complete onboarding)
    let accountLink = await stripe.accountLinks.create({
      account: user.stripe_account_id,
      refresh_url: process.env.STRIPE_REDIRECT_URL,
      return_url: process.env.STRIPE_REDIRECT_URL,
      type: "account_onboarding",
    });
    //  console.log(accountLink)
    // 4. pre-fill any info such as email (optional), then send url resposne to frontend
    accountLink = Object.assign(accountLink, {
      "stripe_user[email]": user.email,
    });
    // 5. then send the account link as response to fronend
    console.log(accountLink.url)
    res.send(`${accountLink.url}?${queryString.stringify(accountLink)}`);

  } catch (err) {
    console.log("CREATE CONNECT ERR ", err);
  }
}; ```

Have a nice day :)

推荐阅读