88import com .stripe .net .Webhook .Signature ;
99import java .net .PasswordAuthentication ;
1010import java .net .Proxy ;
11+ import lombok .Builder ;
1112import lombok .Getter ;
1213
1314/**
@@ -73,7 +74,9 @@ public StripeClient withStripeContext(StripeContext context) {
7374
7475 StripeResponseGetter responseGetter = this .getResponseGetter ();
7576
76- // We can only create a new client for LiveStripeResponseGetter
77+ // We can only create a new client for LiveStripeResponseGetter because it's the only class with
78+ // `getOptions()`. If we add that method to the interface in a later major, we could remove this
79+ // check.
7780 if (!(responseGetter instanceof LiveStripeResponseGetter )) {
7881 throw new IllegalStateException (
7982 "Cannot create a client with custom context for non-Live response getters" );
@@ -88,20 +91,7 @@ public StripeClient withStripeContext(StripeContext context) {
8891 ClientStripeResponseGetterOptions existingOptions =
8992 (ClientStripeResponseGetterOptions ) options ;
9093
91- return new ClientStripeResponseGetterOptions (
92- existingOptions .getAuthenticator (),
93- existingOptions .getClientId (),
94- existingOptions .getConnectTimeout (),
95- existingOptions .getReadTimeout (),
96- existingOptions .getMaxNetworkRetries (),
97- existingOptions .getConnectionProxy (),
98- existingOptions .getProxyCredential (),
99- existingOptions .getApiBase (),
100- existingOptions .getFilesBase (),
101- existingOptions .getConnectBase (),
102- existingOptions .getMeterEventsBase (),
103- existingOptions .getStripeAccount (),
104- contextString );
94+ return existingOptions .toBuilder ().stripeContext (contextString ).build ();
10595 });
10696
10797 // Create and return a new StripeClient with the new response getter
@@ -1100,6 +1090,8 @@ public com.stripe.service.WebhookEndpointService webhookEndpoints() {
11001090 }
11011091
11021092 // The end of the section generated from our OpenAPI spec
1093+ @ SuppressWarnings ("ObjectToString" )
1094+ @ Builder (toBuilder = true )
11031095 static class ClientStripeResponseGetterOptions extends StripeResponseGetterOptions {
11041096 // When adding setting here keep them in sync with settings in RequestOptions and
11051097 // in the RequestOptions.merge method
0 commit comments