Stripe Connect firebase函数用于创建卖家帐户



我正在使用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)
}
})

这是我的flutter代码,我正在检索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'
}
}

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

相关内容

  • 没有找到相关文章

最新更新