我以为我当时在家里,然后走了!脚踏实地!我自己的截止日期越来越近了!
Final通过条纹付款表格使所有内容都在本地运行,并进行了实时发布,并且以某种方式我从我的api代码中收到了一条消息
控制台错误:
POST https://example.com/api/charge 400 (Bad Request)
{“ message”:“缺少必需的参数:数量。” },
这一切还很新,但是任何帮助都会很棒!下面的
中发布的代码我的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,
});
}
};
我的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);
}
}
};
答案 0 :(得分:0)
消息说您没有传递强制的参数amount
。
文档: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,
});