Я думал, что на финише, а потом бац! обратно на землю! и мой собственный крайний срок приближается ко мне!
Final получил все, что работает локально с полосковой формой оплаты, и нажал вживую, и каким-то образом я получаю сообщение от моего кода api, говорящее
console error:
POST https://example.com/api/charge 400 (Bad Request)
{"message": "Отсутствует обязательный параметр: количество." },
довольно новичок во всем этом, но любая помощь будет потрясающей! код размещен ниже в
мои расходы. 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,
});
}
};
моя форма оформления заказа. 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);
}
}
};