#Vladislav Marinov
1 messages · Page 1 of 1 (latest)
Are you trying to set metadata on the payment intent?
Or are you talking about different metadata?
Yeah, you can set metadata on the create request: https://stripe.com/docs/api/payment_intents/create#create_payment_intent-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
yes but can it be formData
i am trying to send formData to the server like this and it doesnt give me
const postPaymentIntent = async (req, res, next) => {
const { amount, email, metadata } = req.body;
if (!amount || !email) {
return next(new HttpError("No amount or email set, please try again", 500));
}
let paymentIntent;
try {
paymentIntent = await stripe.paymentIntents.create({
currency: "eur",
amount: amount,
receipt_email: email,
automatic_payment_methods: {
enabled: true,
},
metadata,
});
} catch (err) {
return next(
new HttpError("Payment Form failed to load, please try again", 400)
);
}
frontend is useEffect(() => {
const formData = new FormData();
formData.append("amount", 1000);
formData.append("email", "vdasdas@gmail.com");
const loadPayment = async () => {
try {
const responseData = await sendRequest(
payment/create-payment-intent,
"POST",
formData
);
setClientSecret(responseData.clientSecret);
setInvoiceEmail(responseData.invoiceEmail);
} catch (err) {
console.log(err);
}
};
loadPayment();
}, []);
It doesn't look like you're actually setting anything for metadata.
The line with metadata doesn't have anything on it
It should look something like metadata: {"some_key": "some_value"}
yeah, now its empty
but with this code
I should set amount and email
and I receive an error on my backend that they are empty
meaning that a cannot pass formData to the req.body
Are you able to do a console.log();. at each step to figure out where the data/variable is ending up empty?
just a moment
so i do this
const postPaymentIntent = async (req, res, next) => {
console.log("body", req.body);
const { amount, email, metadata } = req.body;
if (!amount || !email) {
return next(new HttpError("No amount or email set, please try again", 500));
}
at the backend and it gives me body {}
frontend is the same
const formData = new FormData();
formData.append("amount", 1000);
formData.append("email", "vdasdas@gmail.com");
const loadPayment = async () => {
try {
const responseData = await sendRequest(
payment/create-payment-intent,
"POST",
formData
);
sendRequest is my custom hook btw
If you do console.log(req.body) is it still empty?
Do you know for certain that the console log line is actually running? In other words, if you put console.log("This is a string");, do you see that pop up in the console?
yes
i think the problem is in the formData, because when I change it to json data
it works fine
ones I change it to formData the req.body becomes empty