#kronk
1 messages · Page 1 of 1 (latest)
hello! i think you're missing curly brackets around the idempotency key?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
it's supposed to be passed in an option object?
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...
...
I was looking at some test case examples from the stripe-ruby repo and also noticed that idempotency_key doesn't need to be wrapped in curly braces: https://github.com/stripe/stripe-ruby/blob/master/test/stripe/api_resource_test.rb#L220
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
what specifically are you trying to unit test?
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
you could potentially just let the Stripe SDK handle the idempotency and retries instead - https://github.com/stripe/stripe-ruby#configuring-automatic-retries
and you don't have to deal with all of that
oh interesting, so we are using the Stripe SDK. is the idempotency key implicitly included on all requests?
from the documentation it seemed like idempotency_key needed to be explicitly added to requests https://stripe.com/docs/api/idempotent_requests
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
if you configure it, Stripe SDK can handle idempotency and retries, maybe you'd want to look at this section first? https://github.com/stripe/stripe-ruby#configuring-automatic-retries
so as long as we have Stripe.max_network_retries set we get the idempotency key for free?
yes, and you can test it out
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
what do you mean by "redundant requests"?
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
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