stripe / stripe-java

Java library for the Stripe API.

Home Page:https://stripe.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

autoPagingIterable with api key in RequestOptions fails

othp opened this issue · comments

Describe the bug

We recently upgraded to a change including the changes made in #1401. Prior to this change, when making a call like BalanceTransaction.list(BalanceTransactionListParams.builder.setPayout(payoutId).build(), requestOptions).autoPagingIterable() where requestOptions included the api key we'd have no trouble, but since that PR was included the call fails complaining that the global Stripe.apiKey is not set, and suggests making the overloaded call that includes the requestOptions parameter.

This is unfortunate, both because it's redundant (the requestOptions where just passed on the original list call) and more seriously because the only autoPagingIterable overload that takes requestOptions also requires that you reset the request parameters - and if, like me, you assume that you can just pass null there then you might all of a sudden find yourself paging through records that you had intended to filter in the original request.

Why not just check for the api key in the current request options, and then only throw this error if it and the global key are not set?

To Reproduce

call BalanceTransaction.list(BalanceTransactionListParams.builder.setPayout(payoutId).build(), requestOptions).autoPagingIterable() where requestOptions includes the api key

Expected behavior

Since the api key was included in the options, this should not throw an exception.

Code snippets

No response

OS

macOs

Java version

17

stripe-java version

v21.10.0

API version

2022-08-01

Additional context

No response

Hello @othp, thank you for reporting this. I agree this is confusing.

I am not sure whether #1401 considered this case or not. This was released in the major version 21.0.0, and the relevant changelog entry seems to elide the fact that there are two relevant RequestOptions objects

Check that apiKey is set (either globally or via request options) in StripeCollection.autoPagingIterable and StripeSearchResult.autoPagingIterable, and throw an exception if it is not.

I will investigate with the team and get you an update later this week.

Hello @othp, we determined this was a bug, and published the fix in https://github.com/stripe/stripe-java/releases/tag/v21.12.0. Please feel free to reopen if you have any further issues after updating.

Thank you again for the report.