#sai_rez-idempotency
1 messages · Page 1 of 1 (latest)
@glad crane hmm I don't really understand that Javascript syntax you're using, why are you using the ... spread operator exactly?
Hi, thanks for getting back
AFAIK just
stripe.
customers.create({...}, {idempotencyKey:key})
would work. if key is null then it's ignored by the library.
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
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!
Ah okay, so it it's just a second argument to customer.create()
yes it's create(params,opts)
and opts is an object that contains request-specific options
Oh okay, so from stripe there is already a check to see if the key is valid?
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
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 },
);
seems good to me, I'd test it out and see if it works as you expect!
Great, thanks so much
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)
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)
"stripe": "7.5.0",
yeah try it with idempotency_key instead