当我点击前端上的按钮时,我会被定向到本地主机/创建帐户托管,但呈现“无法发布”。然而,邮递员显示,端点运行得很好.
我不知道我在这里出了什么错。
Firebase函数文件夹上的后端端点
app.post("/create-account-hosted", async (req, res) => {
try {
var account = await stripe.accounts.create({
type: "custom",
requested_capabilities: ["card_payments", "transfers"],
business_type: 'company',
})
var accountLink = await stripe.accountLinks.create({
account: account.id,
success_url: "https://example.com",
failure_url: "https://example.com",
type: "custom_account_verification",
collect: "eventually_due",
});
} catch (err) {
console.log(err);
res.status(400);
res.send({ error: err });
return;
}
res.send(accountLink.url)前端代码表单后请求服务器端重定向。
<div className="beASeller">
<form
type="submit"
action="/create-account-hosted"
method="POST"
class="stripe-connect white"
>
<button> Seller Signup</button>
</form>
</div>发布于 2021-11-24 07:29:43
因为我的邮递员是在查询Firebase函数本身,例如https://uscentral1.myfunction.cloudfunctions.net/create-account-hosted,所以我需要对我的前端代码做同样的操作。
<div className="beASeller">
<button
action="https://uscentral1.myfunction.cloudfunctions.net/create-account-hosted/"
class="stripe-connect white"
>
</button>
</div>发布于 2021-11-24 10:14:31
您还可以使用HTTP客户端。对于这种情况,我们将使用Axios。
在使用Axios发出请求时,您可以利用一些附加选项,但以下是最常见的选项:
您可以参考,以在项目中设置Axios。
安装之后,现在可以使用Axios。请参阅下面的示例代码:
import axios from 'axios';
axios.post('https://uscentral1.myfunction.cloudfunctions.net/create-account-hosted', {"body":data}, {
headers: {
'Content-Type': 'application/json'
'Authorization': 'Bearer ' + token
}
}
)还请检查步骤2-4上的这个thread,看看它是否也有帮助。
https://stackoverflow.com/questions/70087033
复制相似问题