redux 条带无效请求错误:令牌不能作为源传入

rqmkfv5c  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(112)

我试图在我的电子商务网站上设置付款方式,但条纹是给这个错误:令牌不能作为源传入。您可以使用/v1/sources并使用card[token]=MYTOKEN将令牌转换为源。
API侧:

const router = require("express").Router();
const stripe = require("stripe")(process.env.STRIPE_KEY);

router.post("/payment",(req,res)=> {
    stripe.paymentIntents.create({
        source:req.body.tokenId,
        amount:req.body.amount,
        currency: "usd",
    },(stripeErr,stripeRes)=>{
        if(stripeErr) {
            res.status(500).json(stripeErr);
        } else {
            res.status(200).json(stripeRes);
        }
    })
});

module.exports = router;

客户端:

useEffect(()=>{
    const makeRequest = async ()=> {
      try {
        const res = await userRequest.post("/checkout/payment",{
          tokenId: stripeToken.id,
          amount: cart.total*100,
        });
        history.push("/success",{data: res.data});
      } catch{}
    };
    stripeToken && makeRequest();
  },[stripeToken, cart.total, history]);
4ktjp1zp

4ktjp1zp1#

带条纹,both Tokens and Sources are legacy and deprecated。您应该使用带付款方式的Payment Methods
您可以使用create a Payment Method代替令牌,然后使用payment_method属性将该付款方法传递给付款意向。
或者,更好的是,遵循the accept a payment guide instead,它不需要您直接处理付款方法(Stripe.js将在确认付款意向客户端时为您处理它)。

相关问题