question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unpredictable failure mode due to Stripe.apiKey not being set and lazy-loaded collections

See original GitHub issue

Java Version: 11 Stripe-Java Library version: 19.33.0

This may not be a bug exactly, but it looks a lot like one from here.

When Stripe.apiKey is not set, the Stripe Java API works fine most of the time, so long as a RequestOptions containing the API key is supplied with every API call.

However, when a webhook endpoint triggers a lazy-load of a collection, then the Stripe call fails with com.stripe.exception.AuthenticationException: No API key provided... because Stripe doesn’t have an API key to use.

Whether a collection is lazy-loaded is not easily predictable.

In my case I found that my webhook only failed when the Payment Intent payload it received had more than one charge (i.e. one failed charge and then one successful charge). With only a single charge then lazy-loading was not triggered because the single charge was included in the webhook payload, but with two charges then only one of the two charges was included and so when the webhook code iterated over all the charges then a lazy-load was triggered.

Luckily this behaviour was found during testing, but it could easily have been missed. The API docs don’t make it clear that you really to need to set Stripe.apiKey even if you also set the API key in a RequestOptions (https://stripe.com/docs/api/authentication)

I’m not sure how to fix this. Perhaps Stripe should fail to do anything if Stripe.apiKey is not set, so that this coding error is detecting as soon as possible?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kamil-stripecommented, Sep 28, 2022

The fix has shipped with v21.

1reaction
richardm-stripecommented, Jan 25, 2021

This definitely feels like a trap to me. I agree it’s worth considering throwing an exception immediately from .autoPagingIterator if it is ever called without the global APIKey set or passing in RequestOptions to .autoPagingIterator – although this would be a breaking change.

Marking this as future and breaking-api-change, hope to put together a PR soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API keys | Stripe Documentation
Stripe authenticates your API requests using your account's API keys. Stripe raises an invalid request error if you don't include a key, ...
Read more >
Stripe.apiKey not resolving in Android - Stack Overflow
The code you provided is server-side Java code for creating a charge using a token. It is not meant to be used from...
Read more >
Service Status | Ontraport
Fixed issue that caused the column editor of a collection to not save new columns. ... blank objects to be created when forms...
Read more >
Latest updates and features - Webflow
Now your content-heavy sites will load much faster in the Designer — thanks to foundational updates we've made around how CMS and Ecommerce...
Read more >
Changelog - MISP Project
[Jakub Onderka] fix: [sync] galaxy clusters stopped being pushed to remote ... to --collection, since a TAXII collection URL is required as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found