@@ -1048,6 +1048,7 @@ public static final class StripeClientBuilder {
10481048 private String meterEventsBase = Stripe .METER_EVENTS_API_BASE ;
10491049 private String stripeAccount ;
10501050 private String stripeContext ;
1051+ private HttpClient httpClient ;
10511052
10521053 /**
10531054 * Constructs a request options builder with the global parameters (API key and client ID) as
@@ -1059,19 +1060,29 @@ public Authenticator getAuthenticator() {
10591060 return this .authenticator ;
10601061 }
10611062
1063+ /**
1064+ * Sets the authenticator used to authorize requests. Use this for custom authentication
1065+ * strategies. For standard API key authentication, prefer {@link #setApiKey(String)}.
1066+ *
1067+ * <p>This shares a backing field with {@link #setApiKey(String)} — calling one overwrites the
1068+ * other.
1069+ *
1070+ * @param authenticator the authenticator to use
1071+ */
10621072 public StripeClientBuilder setAuthenticator (Authenticator authenticator ) {
10631073 this .authenticator = authenticator ;
10641074 return this ;
10651075 }
10661076
1067- public String getApiKey () {
1068- if (authenticator instanceof BearerTokenAuthenticator ) {
1069- return ((BearerTokenAuthenticator ) authenticator ).getApiKey ();
1070- }
1071-
1072- return null ;
1073- }
1074-
1077+ /**
1078+ * Sets the API key for bearer token authentication. This is a convenience method equivalent to
1079+ * calling {@code setAuthenticator(new BearerTokenAuthenticator(apiKey))}.
1080+ *
1081+ * <p>This shares a backing field with {@link #setAuthenticator(Authenticator)} — calling one
1082+ * overwrites the other.
1083+ *
1084+ * @param apiKey the API key; if null, clears the authenticator
1085+ */
10751086 public StripeClientBuilder setApiKey (String apiKey ) {
10761087 if (apiKey == null ) {
10771088 this .authenticator = null ;
@@ -1179,7 +1190,8 @@ public StripeClientBuilder setProxyCredential(PasswordAuthentication proxyCreden
11791190 * Set the base URL for the Stripe API. By default this is "https://api.stripe.com".
11801191 *
11811192 * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of API. Use
1182- * {@link setFilesBase} or {@link setConnectBase} to interpect requests with other bases.
1193+ * {@link #setFilesBase}, {@link #setConnectBase} or {@link #setMeterEventsBase} to interpect
1194+ * requests with other bases.
11831195 */
11841196 public StripeClientBuilder setApiBase (String address ) {
11851197 this .apiBase = address ;
@@ -1256,9 +1268,23 @@ public String getStripeContext() {
12561268 return this .stripeContext ;
12571269 }
12581270
1271+ /**
1272+ * Sets the HTTP client to use for making requests to the Stripe API. If not set, a default
1273+ * {@link HttpURLConnectionClient} will be created.
1274+ *
1275+ * <p>This is useful for providing a custom HTTP client implementation, e.g. for testing or for
1276+ * using a different HTTP library.
1277+ *
1278+ * @param httpClient the HTTP client to use
1279+ */
1280+ public StripeClientBuilder setHttpClient (HttpClient httpClient ) {
1281+ this .httpClient = httpClient ;
1282+ return this ;
1283+ }
1284+
12591285 /** Constructs a {@link StripeResponseGetterOptions} with the specified values. */
12601286 public StripeClient build () {
1261- return new StripeClient (new LiveStripeResponseGetter (buildOptions (), null ));
1287+ return new StripeClient (new LiveStripeResponseGetter (buildOptions (), this . httpClient ));
12621288 }
12631289
12641290 StripeResponseGetterOptions buildOptions () {
0 commit comments