StripeClient is a class in the official Stripe Java SDK (com.stripe.StripeClient), not part of Spring Boot. It is the entry point for calling the Stripe API: you create it once with your secret key and use it to reach services such as paymentIntents(), customers() and subscriptions(). In Spring Boot you expose it as a singleton bean, so every component shares one configured, thread-safe client.
The older style of setting the static Stripe.apiKey field still works, but a StripeClient instance avoids global mutable state and makes the key easy to inject and test.
The Stripe Java library offers two ways to call the API. The legacy way uses static methods on model classes, for example PaymentIntent.create(params), with a global key set through Stripe.apiKey. The newer way builds a StripeClient and calls instance services, for example client.paymentIntents().create(params).
Reasons to prefer the client:
Check the version of stripe-java in your build, because StripeClient services are available in current releases but not in very old ones.
Add the Stripe SDK to your build. Spring Boot does not manage its version, so declare one yourself.
Never hard-code the secret key. Read it from configuration that comes from an environment variable or a secrets manager.
Then register the client as a bean.
Use a test-mode key (starting with sk_test_) in development. The publishable key belongs in your frontend only.
A PaymentIntent tracks one payment from creation to success. The recommended flow is to create it on the server, send its clientSecret to the browser, and let Stripe.js confirm it so card details never touch your server.
Points to note:
StripeException is a checked exception. Let it propagate to a controller advice, or translate it into your own domain exception, rather than catching Exception and wrapping it in a RuntimeException without detail.Recurring billing uses a Customer, a saved payment method and a Price created in the Stripe Dashboard or via the API.
Setting the payment behaviour to DEFAULT_INCOMPLETE lets the customer finish any required authentication, such as 3D Secure, before the subscription becomes active. For simple cases, Stripe Checkout or the Customer Portal can handle most of this flow for you and reduce the code you maintain.
Payments finish asynchronously, so do not treat the client redirect as proof of payment. Listen for webhook events such as payment_intent.succeeded and verify the signature before trusting them.
The request body must be the raw string exactly as received, because the signature is computed over the raw bytes. Parsing it into an object first breaks verification.
No. It comes from the stripe-java library. Spring Boot only provides the dependency injection and configuration around it.
It is designed to be created once and shared, so a singleton bean is the normal setup. Avoid changing its configuration per request.
It still works, but it sets a global value for the whole JVM. A StripeClient bean is cleaner, especially if you use more than one Stripe account or write tests.
In an environment variable or a secrets manager, injected through Spring configuration. Never commit it to source control or expose it to the frontend.
StripeClient is the Stripe SDK's entry point for API calls. In Spring Boot, create one as a singleton bean from a key supplied by external configuration, inject it into services, and call paymentIntents() and subscriptions() through it. Send amounts in minor units, use idempotency keys for create calls, confirm payments on the client with the clientSecret, and rely on signature-verified webhooks, not redirects, to fulfil orders.