Support pagination for Search queries
Closed this issue · 6 comments
sjmiller609 commented
Is your feature request related to a problem? Please describe.
Paginate for queries to Stripe Search API(s)
Describe the solution you'd like
impl Paginable for Search types
Describe alternatives you've considered
- I'm doing it wrong / didn't find how to do it properly using this SDK
- Don't use search endpoint
- Do pagination in my code
Additional context
- Stripe docs for one of the search endpoints https://stripe.com/docs/api/customers/search
- Search for Paginable in this repo https://github.com/search?q=repo%3Aarlyon%2Fasync-stripe%20Paginable&type=code
sjmiller609 commented
I think I'm missing something because of this release note
Line 32 in 8032120
sjmiller609 commented
sjmiller609 commented
This is the code that does not work
let stripe_secret_key = get_stripe_secret_key()?;
let client = stripe::Client::new(stripe_secret_key);
// https://stripe.com/docs/search#query-fields-for-customers
let customer_search = CustomerSearchParams {
query: format!("-invoice_settings.default_payment_method:null"),
limit: Some(90),
..Default::default()
};
let customers = match Customer::search(&client, customer_search.clone()).await {
Ok(first_batch) => {
let mut customers = first_batch.data;
let paginator = first_batch.paginate(customer_search);
while let Some(next_batch) = paginator.next(&client).await {
customers.extend(next_batch.data);
}
customers
},
Err(e) => {
error!("Failed to search for customer in Stripe: {:?}", e);
return Err(ControlPlaneError::NetworkError(
"Failed to search for customer in Stripe".to_string(),
));
}
};
info!("Found {} customers with a payment method", customers.len());
Ok(customers)
I was comparing to this
async-stripe/examples/customer.rs
Line 60 in 8032120
sjmiller609 commented
I think the param for paginate is the wrong type maybe
Line 217 in 8032120
arlyon commented
I have used this API before when testing the PRs in question but it is clearly broken. I should be stricter with mandating examples of public-facing apis when accepting PRs. I am currently mostly focusing on the codegen revamp but will try to prioritise this after that is cleared.