arlyon/async-stripe

Support pagination for Search queries

Closed this issue · 6 comments

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

I think I'm missing something because of this release note

* updated ListPaginator to be generic over type T where T impl PaginableList instead of having separate SearchListPaginator and ListPaginator implementations for types SearchList and List. ([9d49602](https://github.com/arlyon/async-stripe/commit/9d496023128ff5b3b5b16065241afc83fc1ba3cd))

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

let paginator = Customer::list(&client, &params).await.unwrap().paginate(params);

I think the param for paginate is the wrong type maybe

impl<T: Clone> Clone for SearchList<T> {

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.