【问题标题】:Stripe Connect firebase functions for creating seller account用于创建卖家账户的 Stripe Connect firebase 函数
【发布时间】:2022-01-21 10:49:41
【问题描述】:

我正在使用 Firebase 函数来创建卖家账户,但我不知道如何创建卖家账户以及在 redirect_url 中添加什么 我遵循了一些教程并编写了以下代码 让我知道我应该做哪些更改才能使用 url_launcher 打开卖家账户注册 谢谢

const stripeAccount = functions.https.onRequest(async (req, res) => {
  const { method } = req
  if (method === "GET") {
    // CREATE CONNECTED ACCOUNT
    const { mobile } = req.query
    const account = await stripe.accounts.create({
      type: "express",
    })
    const accountLinks = await stripe.accountLinks.create({
      account: account.id,
      refresh_url:, <--  What to put here
      return_url:, <--  What to put here
      type: "account_onboarding",
    })
    if (mobile) {
      // In case of request generated from the flutter app, return a json response
      res.status(200).json({ success: true, url: accountLinks.url })
    } else {
      // In case of request generated from the web app, redirect
      res.redirect(accountLinks.url)
    }
  } else if (method === "DELETE") {
    // Delete the Connected Account having provided ID
    const {
      query: { id },
    } = req
    console.log(id)
    const deleted = await stripe.accounts.del(id)
    res.status(200).json({ message: "account deleted successfully", deleted })
  } else if (method === "POST") {
    // Retrieve the Connected Account for the provided ID
    // I know it shouldn't be a POST call. Don't judge :D I had a lot on my plate
    const account = await stripe.accounts.retrieve(req.query.id)
    res.status(200).json({ account })
  }


  const stripeReAuth = async (req, res) => {
    const { account_id: accountId } = req.query

    const accountLinks = await stripe.accountLinks.create({
      account: accountId,
      refresh_url:   <-- Here 
      return_url: , <-- Here 
      type: "account_onboarding",
    })
    res.redirect(accountLinks.url)
  }

})

这是我的颤振代码,我正在检索 return_url 并使用 url_launcher 启动它

class StripeBackendService {
  static String apiBase = '{function address}/stripeAccount';
  static String createAccountUrl =
      '$apiBase/account?mobile=true';
  static String checkoutSessionUrl =
      '${StripeBackendService.apiBase}/checkout-session?mobile=true';
  static Map<String, String> headers = {'Content-Type': 'application/json'};

 void createSellerAccount() async {
    var url = Uri.parse(StripeBackendService.createAccountUrl);
    var response = await http.get(url, headers: StripeBackendService.headers);
    Map<String, dynamic> body = jsonDecode(response.body.toString());
   await canLaunch(body['url']) ? await launch(body['url']) : throw 'Error'
  }
}

【问题讨论】:

    标签: flutter google-cloud-functions stripe-payments


    【解决方案1】:

    刷新 url 应该指向一个重新尝试创建条带连接帐户的地址,以防您当前的 http 函数返回一个过期的链接。返回 url 是潜在的条带连接用户在条带启动完成后被发送到的地址。在知道该地址后,您可以使用 webview 控制器在到达返回 URL 端点时跳回应用程序。

    【讨论】:

    • 你能分享一些firebase函数的代码吗?谢谢
    猜你喜欢
    • 2016-08-21
    • 2020-11-06
    • 2021-03-06
    • 2020-07-28
    • 2020-09-30
    • 2022-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多