#jorra

1 messages ยท Page 1 of 1 (latest)

soft harnessBOT
odd bramble
#

Hi! Let me help you with this.

urban monolith
odd bramble
#

Where are you getting this error?
Could you share a screenshot please?

urban monolith
#
  {
    name: 'Mont Blanc 70ml EDP',
    size: null,
    price: 5,
    quantity: 1,
    imagee: 'image'
  }
]
```js
#

the api:

odd bramble
urban monolith
#
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
odd bramble
#

If you want to store an object you can either JSON.stringify() it, or store an ID referring to it.

urban monolith
odd bramble
#

How are you doing it?

urban monolith
# odd bramble 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 })
});

odd bramble
#

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)
          }
        });
odd bramble
#

Happy to help. Let me know if you have any other questions.

urban monolith
gray harbor
#

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.