arlyon / async-stripe

Async (and blocking!) Rust bindings for the Stripe API
https://payments.rs
Apache License 2.0
464 stars 130 forks source link

Support idempotency key in post requests #342

Closed evforde closed 1 year ago

evforde commented 1 year ago

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:

Any 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

arlyon commented 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.