@@ -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
@@ -33,15 +34,15 @@ public class RequestOptions {
3334 private final PasswordAuthentication proxyCredential ;
3435
3536 public static RequestOptions getDefault () {
36- return new RequestOptions (
37- null , null , null , null , null , null , null , null , null , null , null , null );
37+ return new RequestOptionsBuilder ().build ();
3838 }
3939
40- protected RequestOptions (
40+ private RequestOptions (
4141 Authenticator authenticator ,
4242 String clientId ,
4343 String idempotencyKey ,
4444 String stripeContext ,
45+ String stripeRequestTrigger ,
4546 String stripeAccount ,
4647 String stripeVersionOverride ,
4748 String baseUrl ,
@@ -54,6 +55,7 @@ protected RequestOptions(
5455 this .clientId = clientId ;
5556 this .idempotencyKey = idempotencyKey ;
5657 this .stripeContext = stripeContext ;
58+ this .stripeRequestTrigger = stripeRequestTrigger ;
5759 this .stripeAccount = stripeAccount ;
5860 this .stripeVersionOverride = stripeVersionOverride ;
5961 this .baseUrl = baseUrl ;
@@ -64,6 +66,23 @@ protected RequestOptions(
6466 this .proxyCredential = proxyCredential ;
6567 }
6668
69+ RequestOptions (RequestOptionsBuilder builder ) {
70+ this (
71+ builder .authenticator ,
72+ normalizeClientId (builder .clientId ),
73+ normalizeIdempotencyKey (builder .idempotencyKey ),
74+ builder .stripeContext ,
75+ builder .stripeRequestTrigger ,
76+ normalizeStripeAccount (builder .stripeAccount ),
77+ normalizeStripeVersion (builder .stripeVersionOverride ),
78+ normalizeBaseUrl (builder .baseUrl ),
79+ builder .connectTimeout ,
80+ builder .readTimeout ,
81+ builder .maxNetworkRetries ,
82+ builder .connectionProxy ,
83+ builder .proxyCredential );
84+ }
85+
6786 public Authenticator getAuthenticator () {
6887 return this .authenticator ;
6988 }
@@ -84,6 +103,10 @@ public String getStripeContext() {
84103 return stripeContext ;
85104 }
86105
106+ public String getStripeRequestTrigger () {
107+ return stripeRequestTrigger ;
108+ }
109+
87110 public String getIdempotencyKey () {
88111 return idempotencyKey ;
89112 }
@@ -155,6 +178,7 @@ public RequestOptionsBuilder toBuilderFullCopy() {
155178 .setClientId (this .clientId )
156179 .setIdempotencyKey (this .idempotencyKey )
157180 .setStripeAccount (this .stripeAccount )
181+ .setStripeRequestTrigger (this .stripeRequestTrigger )
158182 .setConnectTimeout (this .connectTimeout )
159183 .setReadTimeout (this .readTimeout )
160184 .setMaxNetworkRetries (this .maxNetworkRetries )
@@ -168,6 +192,7 @@ public static class RequestOptionsBuilder {
168192 protected String clientId ;
169193 protected String idempotencyKey ;
170194 protected String stripeContext ;
195+ protected String stripeRequestTrigger ;
171196 protected String stripeAccount ;
172197 protected String stripeVersionOverride ;
173198 protected Integer connectTimeout ;
@@ -253,6 +278,15 @@ public RequestOptionsBuilder clearStripeContext() {
253278 return this ;
254279 }
255280
281+ public String getStripeRequestTrigger () {
282+ return stripeRequestTrigger ;
283+ }
284+
285+ public RequestOptionsBuilder setStripeRequestTrigger (String stripeRequestTrigger ) {
286+ this .stripeRequestTrigger = stripeRequestTrigger ;
287+ return this ;
288+ }
289+
256290 public RequestOptionsBuilder setIdempotencyKey (String idempotencyKey ) {
257291 this .idempotencyKey = idempotencyKey ;
258292 return this ;
@@ -368,19 +402,7 @@ public RequestOptionsBuilder setBaseUrl(final String baseUrl) {
368402
369403 /** Constructs a {@link RequestOptions} with the specified values. */
370404 public RequestOptions build () {
371- return new RequestOptions (
372- this .authenticator ,
373- normalizeClientId (this .clientId ),
374- normalizeIdempotencyKey (this .idempotencyKey ),
375- stripeContext ,
376- normalizeStripeAccount (this .stripeAccount ),
377- normalizeStripeVersion (this .stripeVersionOverride ),
378- normalizeBaseUrl (this .baseUrl ),
379- connectTimeout ,
380- readTimeout ,
381- maxNetworkRetries ,
382- connectionProxy ,
383- proxyCredential );
405+ return new RequestOptions (this );
384406 }
385407 }
386408
@@ -470,20 +492,17 @@ protected static String normalizeStripeAccount(String stripeAccount) {
470492
471493 static RequestOptions merge (StripeResponseGetterOptions clientOptions , RequestOptions options ) {
472494 if (options == null ) {
473- return new RequestOptions (
474- clientOptions .getAuthenticator (), // authenticator
475- clientOptions .getClientId (), // clientId
476- null , // idempotencyKey
477- clientOptions .getStripeContext (), // stripeContext
478- clientOptions .getStripeAccount (), // stripeAccount
479- null , // stripeVersionOverride
480- null , // baseUrl
481- clientOptions .getConnectTimeout (), // connectTimeout
482- clientOptions .getReadTimeout (), // readTimeout
483- clientOptions .getMaxNetworkRetries (), // maxNetworkRetries
484- clientOptions .getConnectionProxy (), // connectionProxy
485- clientOptions .getProxyCredential () // proxyCredential
486- );
495+ return new RequestOptionsBuilder ()
496+ .setAuthenticator (clientOptions .getAuthenticator ())
497+ .setClientId (clientOptions .getClientId ())
498+ .setStripeContext (clientOptions .getStripeContext ())
499+ .setStripeAccount (clientOptions .getStripeAccount ())
500+ .setConnectTimeout (clientOptions .getConnectTimeout ())
501+ .setReadTimeout (clientOptions .getReadTimeout ())
502+ .setMaxNetworkRetries (clientOptions .getMaxNetworkRetries ())
503+ .setConnectionProxy (clientOptions .getConnectionProxy ())
504+ .setProxyCredential (clientOptions .getProxyCredential ())
505+ .build ();
487506 }
488507
489508 // callers need to be able to explicitly unset context per-request
@@ -500,33 +519,46 @@ static RequestOptions merge(StripeResponseGetterOptions clientOptions, RequestOp
500519 } else {
501520 stripeContext = clientOptions .getStripeContext ();
502521 }
503- return new RequestOptions (
504- options .getAuthenticator () != null
505- ? options .getAuthenticator ()
506- : clientOptions .getAuthenticator (),
507- options .getClientId () != null ? options .getClientId () : clientOptions .getClientId (),
508- options .getIdempotencyKey (),
509- stripeContext ,
510- options .getStripeAccount () != null
511- ? options .getStripeAccount ()
512- : clientOptions .getStripeAccount (),
513- RequestOptions .unsafeGetStripeVersionOverride (options ),
514- options .getBaseUrl (),
515- options .getConnectTimeout () != null
516- ? options .getConnectTimeout ()
517- : clientOptions .getConnectTimeout (),
518- options .getReadTimeout () != null
519- ? options .getReadTimeout ()
520- : clientOptions .getReadTimeout (),
521- options .getMaxNetworkRetries () != null
522- ? options .getMaxNetworkRetries ()
523- : clientOptions .getMaxNetworkRetries (),
524- options .getConnectionProxy () != null
525- ? options .getConnectionProxy ()
526- : clientOptions .getConnectionProxy (),
527- options .getProxyCredential () != null
528- ? options .getProxyCredential ()
529- : clientOptions .getProxyCredential ());
522+
523+ return RequestOptionsBuilder .unsafeSetStripeVersionOverride (
524+ new RequestOptionsBuilder ()
525+ .setAuthenticator (
526+ options .getAuthenticator () != null
527+ ? options .getAuthenticator ()
528+ : clientOptions .getAuthenticator ())
529+ .setClientId (
530+ options .getClientId () != null
531+ ? options .getClientId ()
532+ : clientOptions .getClientId ())
533+ .setIdempotencyKey (options .getIdempotencyKey ())
534+ .setStripeContext (stripeContext )
535+ .setStripeRequestTrigger (options .getStripeRequestTrigger ())
536+ .setStripeAccount (
537+ options .getStripeAccount () != null
538+ ? options .getStripeAccount ()
539+ : clientOptions .getStripeAccount ())
540+ .setConnectTimeout (
541+ options .getConnectTimeout () != null
542+ ? options .getConnectTimeout ()
543+ : clientOptions .getConnectTimeout ())
544+ .setReadTimeout (
545+ options .getReadTimeout () != null
546+ ? options .getReadTimeout ()
547+ : clientOptions .getReadTimeout ())
548+ .setMaxNetworkRetries (
549+ options .getMaxNetworkRetries () != null
550+ ? options .getMaxNetworkRetries ()
551+ : clientOptions .getMaxNetworkRetries ())
552+ .setConnectionProxy (
553+ options .getConnectionProxy () != null
554+ ? options .getConnectionProxy ()
555+ : clientOptions .getConnectionProxy ())
556+ .setProxyCredential (
557+ options .getProxyCredential () != null
558+ ? options .getProxyCredential ()
559+ : clientOptions .getProxyCredential ()),
560+ RequestOptions .unsafeGetStripeVersionOverride (options ))
561+ .build ();
530562 }
531563
532564 public static class InvalidRequestOptionsException extends RuntimeException {
0 commit comments