Stripe payments 401向Stripe`Customers`API发送数据时出错

Stripe payments 401向Stripe`Customers`API发送数据时出错,stripe-payments,react-stripe-elements,Stripe Payments,React Stripe Elements,我想在提交表单时创建一个Stripe中的新客户,并将该客户的信用卡添加到他们的帐户中。现在,我在我的React应用程序中提交时使用以下代码。创建客户呼叫然后与我的服务器分开进行: async submit(ev) { let {token} = await this.props.stripe.createToken({name: "Name"}); let response = await fetch("https://api.stripe.com/v1/customers", {

我想在提交表单时创建一个Stripe中的新客户,并将该客户的信用卡添加到他们的帐户中。现在,我在我的React应用程序中提交时使用以下代码。创建客户呼叫然后与我的服务器分开进行:

async submit(ev) {
  let {token} = await this.props.stripe.createToken({name: "Name"});
  let response = await fetch("https://api.stripe.com/v1/customers", {
     method: "POST",
     headers: {"Content-Type": "text/plain"},
     body: token.id
});

当发送数据时,我在let response=。。。线我知道401是一个身份验证错误,但我的测试API密钥绝对正确,并且对如何访问我的stripe帐户没有限制。有人能提供建议吗?

这里的问题是,您正在尝试用原始Javascript创建客户对象客户端。此API请求需要您的机密API密钥。这意味着您永远不能在客户端执行此操作,否则任何人都可以找到您的API密钥并使用它进行退款或转账


相反,您需要将令牌发送到您自己的服务器。在那里,您可以使用其中一个Stripe创建客户或收费,而不是自己发出原始HTTP请求。

非常感谢您的回复。我目前在我的服务器上有以下调用:`app.post,async req,res=>{try{let{status}=wait stripe.customers.create{description:Customer test,source:req.body,email:null}那么,我根本不应该从客户端文件调用api吗?根据,我正在使用该调用将令牌发送到我的服务器。