#Vladislav Marinov

1 messages · Page 1 of 1 (latest)

woeful urchinBOT
little lichen
#

Are you trying to set metadata on the payment intent?

#

Or are you talking about different metadata?

final lotus
#

yes on the payment intent

#

I want to make a stripe payment with Ideal

little lichen
final lotus
#

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();
}, []);

little lichen
#

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"}

final lotus
#

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

little lichen
#

Are you able to do a console.log();. at each step to figure out where the data/variable is ending up empty?

woeful urchinBOT
final lotus
#

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

little lichen
#

If you do console.log(req.body) is it still empty?

final lotus
#

yes

#

the "body" string in front is just for orientation

little lichen
#

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?

final lotus
#

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

thin raptor
#

These requests are internal to your app and api though, right?

#

What do you end up parsing out as metadata in your server before creating the payment intent?

final lotus
#

nothing

#

I was just testing it

#

because it can work without giving it metadata but not without amount or email

#

I think I will just find another way around

#

thank you for the help you can close the chat