#kronk

1 messages · Page 1 of 1 (latest)

old brambleBOT
mental wraith
#

hello! i think you're missing curly brackets around the idempotency key?

#

it's supposed to be passed in an option object?

naive rivet
#

curly brackets give me the same error :/

#
[12] pry(main)> Stripe::Invoice.pay({ invoice_id, payment_method: payment_method_id}, {idempotency_key: SecureRandom.uuid} )
SyntaxError: unexpected ',', expecting =>
...ripe::Invoice.pay({ invoice_id, payment_method: payment_meth...
...             
mental wraith
#

gimme a second

#

it should probably look something like that

Stripe::Invoice.pay('in_1Me7PPJQtHgRImA7jEkxuK9A', { off_session: true }, { idempotency_key: SecureRandom.uuid })
#

your other parameters should be in the params object i.e. the object that currently has off_session : true

#

and the invoice id is passed in as the first param

naive rivet
#

ohh i see, thanks!

#

is there a good way to go about unit testing this?

mental wraith
#

what specifically are you trying to unit test?

naive rivet
#

that the refactored requests with the idempotency key can be processed correctly by stripe

#

we typically stub out these requests but i'm worried given the syntax here we won't know about a syntax issue until the code is in staging/production

#

i've just been going through and manually running these requests to verify syntax but it's been quite tedious

mental wraith
#

and you don't have to deal with all of that

naive rivet
#

oh interesting, so we are using the Stripe SDK. is the idempotency key implicitly included on all requests?

mental wraith
naive rivet
#

so as long as we have Stripe.max_network_retries set we get the idempotency key for free?

mental wraith
#

yes, and you can test it out

naive rivet
#

do you know what version of the SDK this was introduced in? we use v4.24.0 of the stripe ruby gem so testing this out in the past has led to redundant requests

mental wraith
#

what do you mean by "redundant requests"?

naive rivet
#

non-idempotent

#

i can try again just to verify, but we've had a lot of problems with our gem not being up to date, so we don't have all the current features

#

i just checked our code. we have max_network_retries set, then i fired off 2 of the same requests to create a customer with the same email, which resulted in 2 different customers

mental wraith
#

i think there's a misunderstanding about how idempotency works

#

Stripe doesn't deduplicate customers with the same email for you

#

Idempotency keys are useful for preventing the same requests being processed twice (or more) in cases of poor network conditions only. They allow you to safely retrying requests without accidentally performing the same operation twice. This is useful when an API call is disrupted in transit and you do not receive a response. For example, if a request to create a charge does not respond due to a network connection error, the request can be retried with the same idempotency key to guarantee that no more than one charge is created.

#

so if you make two requests, then Stripe assumes that yes, you did intend to make two separate requests. However, if the SDK detects that the request failed due to poor network conditions, then it'll attempt to retry