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

optionally decouple account id specification from client struct #380

Open databasedav opened 1 year ago

databasedav commented 1 year ago

Is your feature request related to a problem? Please describe.

since the account id must be specified on the client struct with fn with_stripe_account(mut self, ..., this means that if one is managing many connected accounts, they need to take ownership of the client that's making the request, which means either (lazily) cloning the client on every request, even though post_form only needs &self, or (eagerly) managing a cache of client struct set to the account id's of the connected they are managing

Describe the solution you'd like

i want to avoid both cloning the client and managing cached client structs by allowing the specification of the account id in an alternative way not tied to the client

one solution (definitely not the best) is to introduce a new function

fn post_form_with(&self, path: &str, form: F, request_transformer: impl Fn(Request) -> Request) -> Response<T> {
    ...
    request = request_transformer(request);
    ...
}

which would allow setting the account id header in the request_transformer although i'm not sure how ergonomic this would be with how the endpoints are currently called or in the new codegen branch e.g.

pub fn post_products(
    client: &crate::Client,
    params: PostProductsParams,
) -> crate::Response<crate::generated::Product> {
    client.post_form("/products", params)
}

which would mean generating an extra _with function for everyone of these functions to expose the lower level request from the high level api, which seems undesirable ...

Describe alternatives you've considered

No response

Additional context

No response