条纹付款-网络请求失败 [英] Stripe Payment - Network request failed
本文介绍了条纹付款-网络请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在React Native应用程序中使用Stripe付款.对于后端,我正在运行NodeJS,并且运行良好,这意味着当我通过令牌时,付款会成功记入借方.但是,在本机方面,我要获取客户卡详细信息并创建令牌,然后将此令牌传递给我的NodeJS服务器进行付款,但每次遇到网络错误时就可以.
I am using stripe for the payment in react native app. For the backend, I have NodeJS running and it is working fine means when I pass the token, the payment gets successfully debited. However, in react native side, I am getting customer card details and creating token and then passing this token to my NodeJS server for payment but every time it gets network error.
反应本机代码
pay() {
stripe.createToken({
card: {
"number": '4242424242424242',
"exp_month": 12,
"exp_year": 2020,
"cvc": '123',
"name": "RAM",
}
}).then((token_object) => {
fetch('https://<IP address>:3000/pay', {
method:"POST",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(token_object)
}).then(response => response.json())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error.message);
});
console.log(token_object.id);
});
}
NODEJS代码
const express = require ('express')
const cors = require('cors')
const stripe = require ('stripe')('sk_test_')
const app = express()
const bodyParser = require('body-parser')
const PORT = process.env.PORT || 3000
app.use(bodyParser.json())
app.use(cors())
app.get('/',(req,res) =>{
res.send("hello from NodeJS!!!!")
})
app.post('/pay',async (req,res) =>{
console.log(req.body)
try {
const {token} = req.body,
charge = await stripe.charges.create({
amount: 15 * 100,
currency: 'inr',
description: 'Jewwllwry',
source: (token),
});
console.log("charged",{charge})
res.send("payment done")
} catch (error) {
console.log(error)
}
})
app.listen(PORT, ()=>{
console.log("server is running on port" + PORT)
})
推荐答案
在处理本地环境时,请尝试使用http
而不是https
发送请求.
Try sending your request with http
instead of https
as you you are working on local env.
这篇关于条纹付款-网络请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文