簡體   English   中英

Stripe Payment - 網絡請求失敗

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM