@@ -1197,6 +1197,7 @@ public static final class StripeClientBuilder {
11971197 private String meterEventsBase = Stripe .METER_EVENTS_API_BASE ;
11981198 private String stripeAccount ;
11991199 private String stripeContext ;
1200+ private HttpClient httpClient ;
12001201
12011202 /**
12021203 * Constructs a request options builder with the global parameters (API key and client ID) as
@@ -1208,19 +1209,29 @@ public Authenticator getAuthenticator() {
12081209 return this .authenticator ;
12091210 }
12101211
1212+ /**
1213+ * Sets the authenticator used to authorize requests. Use this for custom authentication
1214+ * strategies. For standard API key authentication, prefer {@link #setApiKey(String)}.
1215+ *
1216+ * <p>This shares a backing field with {@link #setApiKey(String)} — calling one overwrites the
1217+ * other.
1218+ *
1219+ * @param authenticator the authenticator to use
1220+ */
12111221 public StripeClientBuilder setAuthenticator (Authenticator authenticator ) {
12121222 this .authenticator = authenticator ;
12131223 return this ;
12141224 }
12151225
1216- public String getApiKey () {
1217- if (authenticator instanceof BearerTokenAuthenticator ) {
1218- return ((BearerTokenAuthenticator ) authenticator ).getApiKey ();
1219- }
1220-
1221- return null ;
1222- }
1223-
1226+ /**
1227+ * Sets the API key for bearer token authentication. This is a convenience method equivalent to
1228+ * calling {@code setAuthenticator(new BearerTokenAuthenticator(apiKey))}.
1229+ *
1230+ * <p>This shares a backing field with {@link #setAuthenticator(Authenticator)} — calling one
1231+ * overwrites the other.
1232+ *
1233+ * @param apiKey the API key; if null, clears the authenticator
1234+ */
12241235 public StripeClientBuilder setApiKey (String apiKey ) {
12251236 if (apiKey == null ) {
12261237 this .authenticator = null ;
@@ -1328,7 +1339,8 @@ public StripeClientBuilder setProxyCredential(PasswordAuthentication proxyCreden
13281339 * Set the base URL for the Stripe API. By default this is "https://api.stripe.com".
13291340 *
13301341 * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of API. Use
1331- * {@link setFilesBase} or {@link setConnectBase} to interpect requests with other bases.
1342+ * {@link #setFilesBase}, {@link #setConnectBase} or {@link #setMeterEventsBase} to interpect
1343+ * requests with other bases.
13321344 */
13331345 public StripeClientBuilder setApiBase (String address ) {
13341346 this .apiBase = address ;
@@ -1405,9 +1417,23 @@ public String getStripeContext() {
14051417 return this .stripeContext ;
14061418 }
14071419
1420+ /**
1421+ * Sets the HTTP client to use for making requests to the Stripe API. If not set, a default
1422+ * {@link HttpURLConnectionClient} will be created.
1423+ *
1424+ * <p>This is useful for providing a custom HTTP client implementation, e.g. for testing or for
1425+ * using a different HTTP library.
1426+ *
1427+ * @param httpClient the HTTP client to use
1428+ */
1429+ public StripeClientBuilder setHttpClient (HttpClient httpClient ) {
1430+ this .httpClient = httpClient ;
1431+ return this ;
1432+ }
1433+
14081434 /** Constructs a {@link StripeResponseGetterOptions} with the specified values. */
14091435 public StripeClient build () {
1410- return new StripeClient (new LiveStripeResponseGetter (buildOptions (), null ));
1436+ return new StripeClient (new LiveStripeResponseGetter (buildOptions (), this . httpClient ));
14111437 }
14121438
14131439 StripeResponseGetterOptions buildOptions () {
0 commit comments