@@ -1210,6 +1210,7 @@ public static final class StripeClientBuilder {
12101210 private String meterEventsBase = Stripe .METER_EVENTS_API_BASE ;
12111211 private String stripeAccount ;
12121212 private String stripeContext ;
1213+ private HttpClient httpClient ;
12131214
12141215 /**
12151216 * Constructs a request options builder with the global parameters (API key and client ID) as
@@ -1221,19 +1222,29 @@ public Authenticator getAuthenticator() {
12211222 return this .authenticator ;
12221223 }
12231224
1225+ /**
1226+ * Sets the authenticator used to authorize requests. Use this for custom authentication
1227+ * strategies. For standard API key authentication, prefer {@link #setApiKey(String)}.
1228+ *
1229+ * <p>This shares a backing field with {@link #setApiKey(String)} — calling one overwrites the
1230+ * other.
1231+ *
1232+ * @param authenticator the authenticator to use
1233+ */
12241234 public StripeClientBuilder setAuthenticator (Authenticator authenticator ) {
12251235 this .authenticator = authenticator ;
12261236 return this ;
12271237 }
12281238
1229- public String getApiKey () {
1230- if (authenticator instanceof BearerTokenAuthenticator ) {
1231- return ((BearerTokenAuthenticator ) authenticator ).getApiKey ();
1232- }
1233-
1234- return null ;
1235- }
1236-
1239+ /**
1240+ * Sets the API key for bearer token authentication. This is a convenience method equivalent to
1241+ * calling {@code setAuthenticator(new BearerTokenAuthenticator(apiKey))}.
1242+ *
1243+ * <p>This shares a backing field with {@link #setAuthenticator(Authenticator)} — calling one
1244+ * overwrites the other.
1245+ *
1246+ * @param apiKey the API key; if null, clears the authenticator
1247+ */
12371248 public StripeClientBuilder setApiKey (String apiKey ) {
12381249 if (apiKey == null ) {
12391250 this .authenticator = null ;
@@ -1341,7 +1352,8 @@ public StripeClientBuilder setProxyCredential(PasswordAuthentication proxyCreden
13411352 * Set the base URL for the Stripe API. By default this is "https://api.stripe.com".
13421353 *
13431354 * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of API. Use
1344- * {@link setFilesBase} or {@link setConnectBase} to interpect requests with other bases.
1355+ * {@link #setFilesBase}, {@link #setConnectBase} or {@link #setMeterEventsBase} to interpect
1356+ * requests with other bases.
13451357 */
13461358 public StripeClientBuilder setApiBase (String address ) {
13471359 this .apiBase = address ;
@@ -1418,9 +1430,23 @@ public String getStripeContext() {
14181430 return this .stripeContext ;
14191431 }
14201432
1433+ /**
1434+ * Sets the HTTP client to use for making requests to the Stripe API. If not set, a default
1435+ * {@link HttpURLConnectionClient} will be created.
1436+ *
1437+ * <p>This is useful for providing a custom HTTP client implementation, e.g. for testing or for
1438+ * using a different HTTP library.
1439+ *
1440+ * @param httpClient the HTTP client to use
1441+ */
1442+ public StripeClientBuilder setHttpClient (HttpClient httpClient ) {
1443+ this .httpClient = httpClient ;
1444+ return this ;
1445+ }
1446+
14211447 /** Constructs a {@link StripeResponseGetterOptions} with the specified values. */
14221448 public StripeClient build () {
1423- return new StripeClient (new LiveStripeResponseGetter (buildOptions (), null ));
1449+ return new StripeClient (new LiveStripeResponseGetter (buildOptions (), this . httpClient ));
14241450 }
14251451
14261452 StripeResponseGetterOptions buildOptions () {
0 commit comments