Javascript 未连接到条带API

Javascript 未连接到条带API,javascript,react-native,stripe-payments,Javascript,React Native,Stripe Payments,我正在编写一个stripe React本机网关,并且正在编写到API的stripe连接。我在连接Stripe时使用了API,但它说我没有连接到API。这主要存在于两个文件中:ShopScreen.js和index.js 以下是ShopScreen.js: 从'react'导入{PureComponent}; 从“tipsi条带”导入条带; 从“../components/components/Button”导入按钮; 进口{ 活动指示器, 可触摸不透明度, 文本输入, 形象,, 图像背景, }

我正在编写一个stripe React本机网关,并且正在编写到API的stripe连接。我在连接Stripe时使用了API,但它说我没有连接到API。这主要存在于两个文件中:ShopScreen.js和index.js

以下是ShopScreen.js:

从'react'导入{PureComponent};
从“tipsi条带”导入条带;
从“../components/components/Button”导入按钮;
进口{
活动指示器,
可触摸不透明度,
文本输入,
形象,,
图像背景,
}从“反应本机”;
从“React”导入*作为React;
从“axios”导入axios;
从“react native WebView”导入{WebView};
进口{
安全区域视图,
样式表,
滚动视图,
看法
文本,
状态栏,
平面列表,
}从“反应本机”;
stripe.setOptions({
publisherKey:“pk_test_hwcogstifop98vzkhrijumo00e1ezyuqg”,
});
类ShopScreen扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
搜索:“”,
数据:[],
};
}
handleSearch=(文本)=>{
this.setState({search:text});
};
componentDidMount(){
axios
.get('http://localhost:3000')
。然后((响应)=>{
这是我的国家({
数据:response.data,
});
})
.catch(函数(err){
警惕(err);
});
}
静态标题='卡片格式';
状态={
加载:false,
令牌:null,
};
handleCardPayPress=async()=>{
试一试{
this.setState({loading:true,token:null});
const token=wait stripe.paymentRequestWithCardForm({
//只有iOS支持此选项
smsAutofillDisabled:正确,
requiredBillingAddressFields:“完整”,
预填充信息:{
帐单地址:{
名称:“Vaibhav Herugu”,
第1行:“Darryl大道2号”,
第2行:“”,
城市:“摩根维尔”,
州:“NJ”,
国家:'美国',
邮政编码:“07751”,
电邮:'vherugu@gmail.com',
},
},
});
this.setState({loading:false,token:token});
}捕获(错误){
this.setState({loading:false});
}
};
makePayment=async()=>{
this.setState({loading:true});
axios({
方法:“POST”,
网址:
'https://us-central1-localmainstreet-b0144.cloudfunctions.net/completePaymentWithStripe',
数据:{
金额:0,
货币:美元,
令牌:this.state.token,
},
})。然后((响应)=>{
控制台日志(响应);
this.setState({loading:false});
});
};
render(){
const{loading,token}=this.state;
console.log('##data',this.state.data);
常量项=({user})=>{
console.log(“##项”,用户);
返回(
{user.item.bname}
{令牌&&(
令牌:{this.state.Token}
{this.makePayment}
)}
{user.item.bdesc}
电子邮件:{user.item.Email}
电话号码:{user.item.phonenum}
);
};
const{navigate}=this.props.navigation;
返回(
搜寻
{
导航(“帮助”);
}}>
帮助
{/*    */}
}
keyExtractor={(用户)=>user.id}
/>
);
}
}

导出默认商店屏幕嘿,问题是您没有在请求中添加令牌

exports.completePaymentWithStripe = functions.https.onRequest(
      (request, response) => {
    stripe.customers.create(req.body.token).then(customer => {
        stripe.charges
          .create({
            amount: request.body.amount,
            currency: request.body.currency,
            source: 'tok_mastercard',
            customer: customer.id
          })
         })
          .then((charge) => {
            response.send(charge);
            return charge;
          })
          .catch((error) => {
            console.log(error);
          });
      },
    );

您好,Vaibhav,此问题似乎是由于未提供可发布密钥而不是您的机密(后端)密钥造成的。如果查看在ShopScreen.js中初始化tipsi条带的方式,您会注意到您正在将可发布密钥设置为“publisherKey”。它应该是“publishableKey”,而不是根据:。简而言之,在ShopScreen.js中将
publisherKey
更改为
publishableKey
,应该可以解决您的问题。谢谢!它起作用了