[英]React Stripe api not working on live but fine on local
I thought i was on the home stretch then bam!我以为我在回家的路上然后砰! back down to earth!回到地球! and my own deadline is creeping right up on me!而我自己的最后期限就快到了!
Final got everything working on local with a stripe payment form, and pushed live and somehow i get a message from my api code saying Final 使用条纹支付表格在本地完成所有工作,并推送到现场,不知何故我从我的 api 代码中收到一条消息说
console error:控制台错误:
POST https://example.com/api/charge 400 (Bad Request)
{ "message":"Missing required param: amount." { "message":"缺少必需的参数:数量。" }, },
pretty new to all this but any help will be awesome!这一切都很新,但任何帮助都会很棒! code posted below in下面发布的代码
my charges.js file我的charges.js 文件
import Stripe from "stripe";
const stripe = new Stripe(process.env.SECRET_KEY);
export default async (req, res) => {
const { id, amount } = req.body;
try {
const payment = await stripe.paymentIntents.create({
amount,
currency: "AUD",
description: "Delicious empanadas",
payment_method: id,
confirm: true,
});
console.log(payment);
return res.status(200).json({
confirm: "abc123",
});
} catch (error) {
console.log(error);
return res.status(400).json({
message: error.message,
});
}
};
my checkoutform.js我的 checkoutform.js
const CheckoutForm = ({ success }) => {
const stripe = useStripe();
const elements = useElements();
const [isProcessing, setProcessingTo] = useState(false);
const [checkoutError, setCheckoutError] = useState();
const handleSubmit = async (event) => {
event.preventDefault();
const { error, paymentMethod } = await stripe.createPaymentMethod({
type: "card",
card: elements.getElement(CardElement),
billing_details: {
name: event.target.name.value,
address: {
city: event.target.city.value,
line1: event.target.line1.value,
line2: event.target.line2.value,
},
},
});
setProcessingTo(true);
if (!error) {
const { id } = paymentMethod;
try {
const { data } = await axios.post("/api/charge", { id, amount: 2000 });
console.log(data);
success();
} catch (error) {
console.log(error);
}
}
};
Message says that you are not passing parameter amount
which is obligatory.消息说您没有传递参数amount
,这是强制性的。
Documentation: https://stripe.com/docs/api/payment_intents/create文档: https://stripe.com/docs/api/payment_intents/create
const payment = await stripe.paymentIntents.create({
amount: 100,
currency: "AUD",
description: "Delicious empanadas",
payment_method: id,
confirm: true,
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.