Error: Stripe: Unknown arguments ([object Object]). Did you mean to pass an options object?

Viewed 219

I am getting this error in my backend can anyone please look at this and help me. Thank you

router.post("/event/payment", auth, async (req, res) => {
    
    const { event, token } = req.body;
    const idempontencyKey = uuidv4()

    console.log(token.id);
    console.log(idempontencyKey);

    return stripe.customers.create({
        email: token.email,
        source: token.id
    })
        .then(customer => {
            stripe.charges.create(
                {
                    amount: event.priceOfPass * 100,
                    currency: 'usd',
                    customer: customer.id,
                    receipt_email: token.email,
                    description: `purchase of ${event.eventName} passes`,
                    shipping: {
                        name: token.card.name,

                    }
                }, { idempontencyKey })
        })
        .then(result => res.status(200).json(result))
        .catch(err => res.status(400).json(err))
})
1 Answers

This is coming from your charges.create call. The error is saying that the options object (the second top level argument in your call) expects a key value-format. Here, you can pass the idempotency key as the value to a key named idempotencyKey

stripe.charges.create(
{
  amount: event.priceOfPass * 100,
  currency: 'usd',
  customer: customer.id,
  receipt_email: token.email,
  description: `purchase of ${event.eventName} passes`,
  shipping: {
    name: token.card.name,
  }
}, { idempotencyKey: idempotencyKey })
Related