#jorra
1 messages ยท Page 1 of 1 (latest)
Hi! Let me help you with this.
thank you
Where are you getting this error?
Could you share a screenshot please?
Sure. I am trying to do it in nodejs. cartItems:
{
name: 'Mont Blanc 70ml EDP',
size: null,
price: 5,
quantity: 1,
imagee: 'image'
}
]
```js
the api:
The metadata property is a set of key-value pairs, and both key and value needs to be a string: https://stripe.com/docs/api/payment_intents/create#create_payment_intent-metadata
try {
const paymentIntent = await stripe.paymentIntents.create({
amount: req.body.totalPrice,
currency: 'aud',
receipt_email: req.body.email,
metadata: req.body.cartItems
});
res.send({
client_secret: paymentIntent.client_secret
});
return paymentIntent;
} catch (err) {
console.log(err);
throw err;
}
```js
If you want to store an object you can either JSON.stringify() it, or store an ID referring to it.
yes. Even if I JSON.stringify() it it dones't work ๐ฆ
How are you doing it?
try {
const paymentIntent = await stripe.paymentIntents.create({
amount: req.body.totalPrice,
currency: 'aud',
receipt_email: req.body.email,
metadata: JSON.stringify(req.body.cartItems)
});
res.send({
client_secret: paymentIntent.client_secret
});
return paymentIntent;
} catch (err) {
console.log(err);
throw err;
}
```js
in frontend: const response = await fetch('/api/stripe/checkout', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ cartItems, email, totalPrice })
});
The metadata needs to be an object with keys and values in in, like so:
const paymentIntent = await stripe.paymentIntents.create({
...
metadata: {
"key": "value",
"foo": "bar",
}
});
In your case:
const paymentIntent = await stripe.paymentIntents.create({
...
metadata: {
"cart": JSON.stringify(req.body.cartItems)
}
});
thank you will try
Happy to help. Let me know if you have any other questions.
thank you It worked. I wanted an advice. So, currently I am doing payment by paymentIntent then element card. How should I do orders database? Should I INSERT into the database after successful payment or, since I will be passing ordered products, should I get directly from stripe?
Hi ๐ apologies for the delay as my teammate needed to step away. We won't have much insight into the best way to structure your database flows. Those are decisions you're best suited to make as you have the best understanding of what your processes need to accomplish.
no worries toby.