[英]Stripe invalid_request_error: A token may not be passed in as a Source
I am trying to set payment method on my ecommerce site but the stripe is giving this error: A token may not be passed in as a Source.我正在尝试在我的电子商务网站上设置付款方式,但条纹出现此错误:令牌可能不会作为来源传递。 You can convert your token into a Source using /v1/sources with card[token]=tok_1Lg9eWSEOA145r9TEaDbCDmr.
您可以使用带有 card[token]=tok_1Lg9eWSEOA145r9TEaDbCDmr 的 /v1/sources 将您的令牌转换为 Source。
API Side: 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;
Client Side:客户端:
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]);
With Stripe, both Tokens and Sources are legacy and deprecated .使用 Stripe, Tokens 和 Sources 都是 legacy 并且 deprecated 。 You should be using Payment Methods with Payment Intents instead.
您应该改用具有付款意图的付款方式。
You can create a Payment Method instead of a Token, then pass that Payment Method to the Payment Intent using the payment_method
property .您可以创建一个支付方式而不是一个令牌,然后使用
payment_method
属性将该支付方式传递给支付意图。
Or, better yet, follow the accept a payment guide instead , which doesn't require you to handle the Payment Method directly (Stripe.js will take care of it for you when confirming the Payment Intent client-side).或者,更好的是,请遵循接受付款指南,这不需要您直接处理付款方式(Stripe.js 会在确认付款意图客户端时为您处理)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.