#sai_rez-idempotency

1 messages · Page 1 of 1 (latest)

teal stratus
#

@glad crane hmm I don't really understand that Javascript syntax you're using, why are you using the ... spread operator exactly?

glad crane
#

Hi, thanks for getting back

teal stratus
#

AFAIK just

stripe.
customers.create({...}, {idempotencyKey:key})

would work. if key is null then it's ignored by the library.

glad crane
#

Currently, we would like to use the key as an optional value so I'm running a check and adding the key to stripe if it exists

teal stratus
#

you can just add the variable directly like in my snippet. If the variable is null then it's ignored(I just tested to confirm that), I don't think you have to make it more complicated than that!

glad crane
#

Ah okay, so it it's just a second argument to customer.create()

teal stratus
#

yes it's create(params,opts)

#

and opts is an object that contains request-specific options

glad crane
#

Oh okay, so from stripe there is already a check to see if the key is valid?

teal stratus
#

well it's more like if you pass a null value in the object it's just ignored, the library doesn't pass anything to the API

glad crane
#

Okay that makes sense, I'll remove the extra fluff and see, I wasn't aware that it gets ignored

#

Like this should be fine correct?

    const customer = await client.customers.create(
      {
        description: content.customerDescription(email_address),
        name,
        email: email_address,
        address: {
          country,
          postal_code: postcode,
          state,
        },
        ...paymentInfo,
        metadata: {
          platform_id: user_id,
          address_country: country,
          address_zip: postcode,
          address_state: state,
          name,
          ip_address: userIp,
        },
      },
      { idempotencyKey: idempotency_key },
    );
teal stratus
#

seems good to me, I'd test it out and see if it works as you expect!

glad crane
#

Great, thanks so much

glad crane
#

Hey again

#

So the error message is different this time, it refers me to your previous link, any ideas why this would happen if the syntax is correct?

Error adding user to stripe: Stripe: Unknown arguments ([object Object]). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options. (on API request to POST /customers)

teal stratus
#

what version of stripe-node are you using?

#

you can get that error if you're using an old version(the parameter used to be called idempotency_key so older versions only recognise that and not idempotencyKey and would throw that error)

glad crane
#

"stripe": "7.5.0",

teal stratus
#

yeah try it with idempotency_key instead