Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pagination for Search queries #468

Open
sjmiller609 opened this issue Jan 8, 2024 · 6 comments
Open

Support pagination for Search queries #468

sjmiller609 opened this issue Jan 8, 2024 · 6 comments

Comments

@sjmiller609
Copy link

sjmiller609 commented Jan 8, 2024

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

@sjmiller609
Copy link
Author

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))

@sjmiller609
Copy link
Author

@sjmiller609
Copy link
Author

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);

@sjmiller609
Copy link
Author

I think the param for paginate is the wrong type maybe

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

@sjmiller609
Copy link
Author

@arlyon
Copy link
Owner

arlyon commented Jan 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants