@@ -13,6 +13,7 @@ public class RequestOptions {
1313 private final Authenticator authenticator ;
1414 private final String clientId ;
1515 private final String stripeContext ;
16+ private final String stripeRequestTrigger ;
1617 private final String idempotencyKey ;
1718 private final String stripeAccount ;
1819 private final String baseUrl ;
@@ -31,15 +32,15 @@ public class RequestOptions {
3132 private final PasswordAuthentication proxyCredential ;
3233
3334 public static RequestOptions getDefault () {
34- return new RequestOptions (
35- null , null , null , null , null , null , null , null , null , null , null , null );
35+ return new RequestOptionsBuilder ().build ();
3636 }
3737
38- protected RequestOptions (
38+ private RequestOptions (
3939 Authenticator authenticator ,
4040 String clientId ,
4141 String idempotencyKey ,
4242 String stripeContext ,
43+ String stripeRequestTrigger ,
4344 String stripeAccount ,
4445 String stripeVersionOverride ,
4546 String baseUrl ,
@@ -52,6 +53,7 @@ protected RequestOptions(
5253 this .clientId = clientId ;
5354 this .idempotencyKey = idempotencyKey ;
5455 this .stripeContext = stripeContext ;
56+ this .stripeRequestTrigger = stripeRequestTrigger ;
5557 this .stripeAccount = stripeAccount ;
5658 this .stripeVersionOverride = stripeVersionOverride ;
5759 this .baseUrl = baseUrl ;
@@ -62,6 +64,23 @@ protected RequestOptions(
6264 this .proxyCredential = proxyCredential ;
6365 }
6466
67+ RequestOptions (RequestOptionsBuilder builder ) {
68+ this (
69+ builder .authenticator ,
70+ normalizeClientId (builder .clientId ),
71+ normalizeIdempotencyKey (builder .idempotencyKey ),
72+ builder .stripeContext ,
73+ builder .stripeRequestTrigger ,
74+ normalizeStripeAccount (builder .stripeAccount ),
75+ normalizeStripeVersion (builder .stripeVersionOverride ),
76+ normalizeBaseUrl (builder .baseUrl ),
77+ builder .connectTimeout ,
78+ builder .readTimeout ,
79+ builder .maxNetworkRetries ,
80+ builder .connectionProxy ,
81+ builder .proxyCredential );
82+ }
83+
6584 public Authenticator getAuthenticator () {
6685 return this .authenticator ;
6786 }
@@ -82,6 +101,10 @@ public String getStripeContext() {
82101 return stripeContext ;
83102 }
84103
104+ public String getStripeRequestTrigger () {
105+ return stripeRequestTrigger ;
106+ }
107+
85108 public String getIdempotencyKey () {
86109 return idempotencyKey ;
87110 }
@@ -153,6 +176,7 @@ public RequestOptionsBuilder toBuilderFullCopy() {
153176 .setClientId (this .clientId )
154177 .setIdempotencyKey (this .idempotencyKey )
155178 .setStripeAccount (this .stripeAccount )
179+ .setStripeRequestTrigger (this .stripeRequestTrigger )
156180 .setConnectTimeout (this .connectTimeout )
157181 .setReadTimeout (this .readTimeout )
158182 .setMaxNetworkRetries (this .maxNetworkRetries )
@@ -166,6 +190,7 @@ public static class RequestOptionsBuilder {
166190 protected String clientId ;
167191 protected String idempotencyKey ;
168192 protected String stripeContext ;
193+ protected String stripeRequestTrigger ;
169194 protected String stripeAccount ;
170195 protected String stripeVersionOverride ;
171196 protected Integer connectTimeout ;
@@ -251,6 +276,15 @@ public RequestOptionsBuilder clearStripeContext() {
251276 return this ;
252277 }
253278
279+ public String getStripeRequestTrigger () {
280+ return stripeRequestTrigger ;
281+ }
282+
283+ public RequestOptionsBuilder setStripeRequestTrigger (String stripeRequestTrigger ) {
284+ this .stripeRequestTrigger = stripeRequestTrigger ;
285+ return this ;
286+ }
287+
254288 public RequestOptionsBuilder setIdempotencyKey (String idempotencyKey ) {
255289 this .idempotencyKey = idempotencyKey ;
256290 return this ;
@@ -366,19 +400,7 @@ public RequestOptionsBuilder setBaseUrl(final String baseUrl) {
366400
367401 /** Constructs a {@link RequestOptions} with the specified values. */
368402 public RequestOptions build () {
369- return new RequestOptions (
370- this .authenticator ,
371- normalizeClientId (this .clientId ),
372- normalizeIdempotencyKey (this .idempotencyKey ),
373- stripeContext ,
374- normalizeStripeAccount (this .stripeAccount ),
375- normalizeStripeVersion (this .stripeVersionOverride ),
376- normalizeBaseUrl (this .baseUrl ),
377- connectTimeout ,
378- readTimeout ,
379- maxNetworkRetries ,
380- connectionProxy ,
381- proxyCredential );
403+ return new RequestOptions (this );
382404 }
383405 }
384406
@@ -468,20 +490,17 @@ protected static String normalizeStripeAccount(String stripeAccount) {
468490
469491 static RequestOptions merge (StripeResponseGetterOptions clientOptions , RequestOptions options ) {
470492 if (options == null ) {
471- return new RequestOptions (
472- clientOptions .getAuthenticator (), // authenticator
473- clientOptions .getClientId (), // clientId
474- null , // idempotencyKey
475- clientOptions .getStripeContext (), // stripeContext
476- clientOptions .getStripeAccount (), // stripeAccount
477- null , // stripeVersionOverride
478- null , // baseUrl
479- clientOptions .getConnectTimeout (), // connectTimeout
480- clientOptions .getReadTimeout (), // readTimeout
481- clientOptions .getMaxNetworkRetries (), // maxNetworkRetries
482- clientOptions .getConnectionProxy (), // connectionProxy
483- clientOptions .getProxyCredential () // proxyCredential
484- );
493+ return new RequestOptionsBuilder ()
494+ .setAuthenticator (clientOptions .getAuthenticator ())
495+ .setClientId (clientOptions .getClientId ())
496+ .setStripeContext (clientOptions .getStripeContext ())
497+ .setStripeAccount (clientOptions .getStripeAccount ())
498+ .setConnectTimeout (clientOptions .getConnectTimeout ())
499+ .setReadTimeout (clientOptions .getReadTimeout ())
500+ .setMaxNetworkRetries (clientOptions .getMaxNetworkRetries ())
501+ .setConnectionProxy (clientOptions .getConnectionProxy ())
502+ .setProxyCredential (clientOptions .getProxyCredential ())
503+ .build ();
485504 }
486505
487506 // callers need to be able to explicitly unset context per-request
@@ -498,33 +517,46 @@ static RequestOptions merge(StripeResponseGetterOptions clientOptions, RequestOp
498517 } else {
499518 stripeContext = clientOptions .getStripeContext ();
500519 }
501- return new RequestOptions (
502- options .getAuthenticator () != null
503- ? options .getAuthenticator ()
504- : clientOptions .getAuthenticator (),
505- options .getClientId () != null ? options .getClientId () : clientOptions .getClientId (),
506- options .getIdempotencyKey (),
507- stripeContext ,
508- options .getStripeAccount () != null
509- ? options .getStripeAccount ()
510- : clientOptions .getStripeAccount (),
511- RequestOptions .unsafeGetStripeVersionOverride (options ),
512- options .getBaseUrl (),
513- options .getConnectTimeout () != null
514- ? options .getConnectTimeout ()
515- : clientOptions .getConnectTimeout (),
516- options .getReadTimeout () != null
517- ? options .getReadTimeout ()
518- : clientOptions .getReadTimeout (),
519- options .getMaxNetworkRetries () != null
520- ? options .getMaxNetworkRetries ()
521- : clientOptions .getMaxNetworkRetries (),
522- options .getConnectionProxy () != null
523- ? options .getConnectionProxy ()
524- : clientOptions .getConnectionProxy (),
525- options .getProxyCredential () != null
526- ? options .getProxyCredential ()
527- : clientOptions .getProxyCredential ());
520+
521+ return RequestOptionsBuilder .unsafeSetStripeVersionOverride (
522+ new RequestOptionsBuilder ()
523+ .setAuthenticator (
524+ options .getAuthenticator () != null
525+ ? options .getAuthenticator ()
526+ : clientOptions .getAuthenticator ())
527+ .setClientId (
528+ options .getClientId () != null
529+ ? options .getClientId ()
530+ : clientOptions .getClientId ())
531+ .setIdempotencyKey (options .getIdempotencyKey ())
532+ .setStripeContext (stripeContext )
533+ .setStripeRequestTrigger (options .getStripeRequestTrigger ())
534+ .setStripeAccount (
535+ options .getStripeAccount () != null
536+ ? options .getStripeAccount ()
537+ : clientOptions .getStripeAccount ())
538+ .setConnectTimeout (
539+ options .getConnectTimeout () != null
540+ ? options .getConnectTimeout ()
541+ : clientOptions .getConnectTimeout ())
542+ .setReadTimeout (
543+ options .getReadTimeout () != null
544+ ? options .getReadTimeout ()
545+ : clientOptions .getReadTimeout ())
546+ .setMaxNetworkRetries (
547+ options .getMaxNetworkRetries () != null
548+ ? options .getMaxNetworkRetries ()
549+ : clientOptions .getMaxNetworkRetries ())
550+ .setConnectionProxy (
551+ options .getConnectionProxy () != null
552+ ? options .getConnectionProxy ()
553+ : clientOptions .getConnectionProxy ())
554+ .setProxyCredential (
555+ options .getProxyCredential () != null
556+ ? options .getProxyCredential ()
557+ : clientOptions .getProxyCredential ()),
558+ RequestOptions .unsafeGetStripeVersionOverride (options ))
559+ .build ();
528560 }
529561
530562 public static class InvalidRequestOptionsException extends RuntimeException {
0 commit comments