Closed evforde closed 1 year ago
Have a look at strategies, does this handle your use case? If you use the retry strategy, a key will automatically be generated for you and used across retries. If you would rather handle this yourself, you can create your own or use https://docs.rs/async-stripe/0.18.3/stripe/enum.RequestStrategy.html#method.idempotent_with_uuid.
I think the real issue is that we should do a better job documenting that API.
Is your feature request related to a problem? Please describe.
Stripe supports providing an
Idempotency-Key
header on POST (and other retry-able requests) in order to allow safely retrying a request when a connection error occurs. The async-stripe library doesn't appear to support this yet, and for good reason - it is tricky to implement :)Describe the solution you'd like
The idempotency key header is set per request, but since the client methods are largely invoked via util methods on the autogenerated resource types, there's not a simple backwards-compatible way to specify an idempotency key per request.
A few ideas:
CreateSubscription
, add anidempotency_key
value that isn't serialized in the HTTP body but is rather serialized in the headers. BlehClient
that allows generating a wrapper around a client that includes an idempotency key. Syntax might look something likeWe would have to be careful to make it hard to accidentally set an idempotency key for the entire client in a way that would make it easy to accidentally send the same idempotency key on another request. Tricky
We'd probably have to make all params-like structs implement a trait that provides this
with_idempotency_key
util. OofSubscription::create_with_idempotency_key(client, params, key)
for all use cases I want to useAny interest in any of these methods? If so, I'm happy to take a stab at implementing :)
Thanks all for your help!
Describe alternatives you've considered
No response
Additional context
No response