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
console error:
POST https://example.com/api/charge 400 (Bad Request)
{ "message":"Missing required param: amount." },
pretty new to all this but any help will be awesome! code posted below in
my charges.js file
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
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.
Documentation: 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,
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.