[英]Stripe Payment - Network request failed
我在 react native 应用程序中使用条带进行支付。 对于后端,我运行了 NodeJS,它运行良好,这意味着当我通过令牌时,付款成功借记。 但是,在本机反应方面,我正在获取客户卡详细信息并创建令牌,然后将此令牌传递给我的 NodeJS 服务器进行付款,但每次都会出现网络错误。
反应原生代码
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);
});
}
节点代码
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
发送您的请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.