• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-java / #16493

03 Oct 2024 07:15PM UTC coverage: 12.942% (+0.08%) from 12.864%
#16493

push

github

web-flow
Merge Stripe-java v27.0.0 to beta branch (#1888)

409 of 1651 new or added lines in 88 files covered. (24.77%)

31 existing lines in 7 files now uncovered.

18773 of 145050 relevant lines covered (12.94%)

0.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.91
/src/main/java/com/stripe/StripeClient.java
1
package com.stripe;
2

3
import com.stripe.exception.SignatureVerificationException;
4
import com.stripe.exception.StripeException;
5
import com.stripe.model.StripeObject;
6
import com.stripe.model.ThinEvent;
7
import com.stripe.net.*;
8
import com.stripe.net.Webhook.Signature;
9
import java.net.PasswordAuthentication;
10
import java.net.Proxy;
11
import lombok.Getter;
12

13
/**
14
 * This is the primary entrypoint to make requests against Stripe's API. It provides a means of
15
 * accessing all the methods on the Stripe API, and the ability to set configuration such as apiKey
16
 * and connection timeouts.
17
 */
18
public class StripeClient {
19
  private final StripeResponseGetter responseGetter;
20

21
  /**
22
   * Constructs a StripeClient with default settings, using the provided API key. Use the builder
23
   * instead if you require more complex configuration.
24
   */
25
  public StripeClient(String apiKey) {
1✔
26
    this.responseGetter =
1✔
27
        new LiveStripeResponseGetter(builder().setApiKey(apiKey).buildOptions(), null);
1✔
28
  }
1✔
29

30
  /**
31
   * Constructs a StripeClient with a custom StripeResponseGetter.
32
   *
33
   * <p>Use this for testing, or advanced use cases where you need to make fundamental changes to
34
   * how the StripeClient makes requests.
35
   */
36
  public StripeClient(StripeResponseGetter responseGetter) {
1✔
37
    this.responseGetter = responseGetter;
1✔
38
  }
1✔
39

40
  protected StripeResponseGetter getResponseGetter() {
41
    return responseGetter;
1✔
42
  }
43

44
  /**
45
   * Returns an StripeEvent instance using the provided JSON payload. Throws a JsonSyntaxException
46
   * if the payload is not valid JSON, and a SignatureVerificationException if the signature
47
   * verification fails for any reason.
48
   *
49
   * @param payload the payload sent by Stripe.
50
   * @param sigHeader the contents of the signature header sent by Stripe.
51
   * @param secret secret used to generate the signature.
52
   * @return the StripeEvent instance
53
   * @throws SignatureVerificationException if the verification fails.
54
   */
55
  public ThinEvent parseThinEvent(String payload, String sigHeader, String secret)
56
      throws SignatureVerificationException {
57
    Signature.verifyHeader(payload, sigHeader, secret, Webhook.DEFAULT_TOLERANCE);
1✔
58

59
    return ApiResource.GSON.fromJson(payload, ThinEvent.class);
1✔
60
  }
61

62
  /**
63
   * Returns an Event instance using the provided JSON payload. Throws a JsonSyntaxException if the
64
   * payload is not valid JSON, and a SignatureVerificationException if the signature verification
65
   * fails for any reason.
66
   *
67
   * @param payload the payload sent by Stripe.
68
   * @param sigHeader the contents of the signature header sent by Stripe.
69
   * @param secret secret used to generate the signature.
70
   * @return the Event instance
71
   * @throws SignatureVerificationException if the verification fails.
72
   */
73
  public com.stripe.model.Event constructEvent(String payload, String sigHeader, String secret)
74
      throws SignatureVerificationException {
75
    com.stripe.model.Event event = Webhook.constructEvent(payload, sigHeader, secret);
1✔
76
    event.setResponseGetter(this.getResponseGetter());
1✔
77
    return event;
1✔
78
  }
79

80
  /**
81
   * Returns an Event instance using the provided JSON payload. Throws a JsonSyntaxException if the
82
   * payload is not valid JSON, and a SignatureVerificationException if the signature verification
83
   * fails for any reason.
84
   *
85
   * @param payload the payload sent by Stripe.
86
   * @param sigHeader the contents of the signature header sent by Stripe.
87
   * @param secret secret used to generate the signature.
88
   * @param tolerance maximum difference in seconds allowed between the header's timestamp and the
89
   *     current time
90
   * @return the Event instance
91
   * @throws SignatureVerificationException if the verification fails.
92
   */
93
  public com.stripe.model.Event constructEvent(
94
      String payload, String sigHeader, String secret, long tolerance)
95
      throws SignatureVerificationException {
96
    com.stripe.model.Event event = Webhook.constructEvent(payload, sigHeader, secret, tolerance);
1✔
97
    event.setResponseGetter(this.getResponseGetter());
1✔
98
    return event;
1✔
99
  }
100

101
  // The beginning of the section generated from our OpenAPI spec
102
  public com.stripe.service.AccountLinkService accountLinks() {
103
    return new com.stripe.service.AccountLinkService(this.getResponseGetter());
1✔
104
  }
105

106
  public com.stripe.service.AccountNoticeService accountNotices() {
107
    return new com.stripe.service.AccountNoticeService(this.getResponseGetter());
×
108
  }
109

110
  public com.stripe.service.AccountSessionService accountSessions() {
111
    return new com.stripe.service.AccountSessionService(this.getResponseGetter());
×
112
  }
113

114
  public com.stripe.service.AccountService accounts() {
115
    return new com.stripe.service.AccountService(this.getResponseGetter());
1✔
116
  }
117

118
  public com.stripe.service.ApplePayDomainService applePayDomains() {
119
    return new com.stripe.service.ApplePayDomainService(this.getResponseGetter());
×
120
  }
121

122
  public com.stripe.service.ApplicationFeeService applicationFees() {
123
    return new com.stripe.service.ApplicationFeeService(this.getResponseGetter());
1✔
124
  }
125

126
  public com.stripe.service.AppsService apps() {
127
    return new com.stripe.service.AppsService(this.getResponseGetter());
1✔
128
  }
129

130
  public com.stripe.service.BalanceService balance() {
131
    return new com.stripe.service.BalanceService(this.getResponseGetter());
×
132
  }
133

134
  public com.stripe.service.BalanceTransactionService balanceTransactions() {
135
    return new com.stripe.service.BalanceTransactionService(this.getResponseGetter());
1✔
136
  }
137

138
  public com.stripe.service.BillingService billing() {
139
    return new com.stripe.service.BillingService(this.getResponseGetter());
×
140
  }
141

142
  public com.stripe.service.BillingPortalService billingPortal() {
143
    return new com.stripe.service.BillingPortalService(this.getResponseGetter());
1✔
144
  }
145

146
  public com.stripe.service.CapitalService capital() {
147
    return new com.stripe.service.CapitalService(this.getResponseGetter());
×
148
  }
149

150
  public com.stripe.service.ChargeService charges() {
151
    return new com.stripe.service.ChargeService(this.getResponseGetter());
1✔
152
  }
153

154
  public com.stripe.service.CheckoutService checkout() {
155
    return new com.stripe.service.CheckoutService(this.getResponseGetter());
1✔
156
  }
157

158
  public com.stripe.service.ClimateService climate() {
159
    return new com.stripe.service.ClimateService(this.getResponseGetter());
×
160
  }
161

162
  public com.stripe.service.ConfirmationTokenService confirmationTokens() {
163
    return new com.stripe.service.ConfirmationTokenService(this.getResponseGetter());
×
164
  }
165

166
  public com.stripe.service.CountrySpecService countrySpecs() {
167
    return new com.stripe.service.CountrySpecService(this.getResponseGetter());
1✔
168
  }
169

170
  public com.stripe.service.CouponService coupons() {
171
    return new com.stripe.service.CouponService(this.getResponseGetter());
1✔
172
  }
173

174
  public com.stripe.service.CreditNoteService creditNotes() {
175
    return new com.stripe.service.CreditNoteService(this.getResponseGetter());
1✔
176
  }
177

178
  public com.stripe.service.CustomerSessionService customerSessions() {
179
    return new com.stripe.service.CustomerSessionService(this.getResponseGetter());
1✔
180
  }
181

182
  public com.stripe.service.CustomerService customers() {
183
    return new com.stripe.service.CustomerService(this.getResponseGetter());
1✔
184
  }
185

186
  public com.stripe.service.DisputeService disputes() {
187
    return new com.stripe.service.DisputeService(this.getResponseGetter());
1✔
188
  }
189

190
  public com.stripe.service.EntitlementsService entitlements() {
191
    return new com.stripe.service.EntitlementsService(this.getResponseGetter());
×
192
  }
193

194
  public com.stripe.service.EphemeralKeyService ephemeralKeys() {
195
    return new com.stripe.service.EphemeralKeyService(this.getResponseGetter());
1✔
196
  }
197

198
  public com.stripe.service.EventService events() {
199
    return new com.stripe.service.EventService(this.getResponseGetter());
1✔
200
  }
201

202
  public com.stripe.service.ExchangeRateService exchangeRates() {
203
    return new com.stripe.service.ExchangeRateService(this.getResponseGetter());
×
204
  }
205

206
  public com.stripe.service.FileLinkService fileLinks() {
207
    return new com.stripe.service.FileLinkService(this.getResponseGetter());
1✔
208
  }
209

210
  public com.stripe.service.FileService files() {
211
    return new com.stripe.service.FileService(this.getResponseGetter());
1✔
212
  }
213

214
  public com.stripe.service.FinancialConnectionsService financialConnections() {
215
    return new com.stripe.service.FinancialConnectionsService(this.getResponseGetter());
1✔
216
  }
217

218
  public com.stripe.service.ForwardingService forwarding() {
219
    return new com.stripe.service.ForwardingService(this.getResponseGetter());
×
220
  }
221

222
  public com.stripe.service.GiftCardsService giftCards() {
223
    return new com.stripe.service.GiftCardsService(this.getResponseGetter());
×
224
  }
225

226
  public com.stripe.service.IdentityService identity() {
227
    return new com.stripe.service.IdentityService(this.getResponseGetter());
1✔
228
  }
229

230
  public com.stripe.service.InvoiceItemService invoiceItems() {
231
    return new com.stripe.service.InvoiceItemService(this.getResponseGetter());
1✔
232
  }
233

234
  public com.stripe.service.InvoiceRenderingTemplateService invoiceRenderingTemplates() {
235
    return new com.stripe.service.InvoiceRenderingTemplateService(this.getResponseGetter());
×
236
  }
237

238
  public com.stripe.service.InvoiceService invoices() {
239
    return new com.stripe.service.InvoiceService(this.getResponseGetter());
1✔
240
  }
241

242
  public com.stripe.service.IssuingService issuing() {
243
    return new com.stripe.service.IssuingService(this.getResponseGetter());
1✔
244
  }
245

246
  public com.stripe.service.MandateService mandates() {
247
    return new com.stripe.service.MandateService(this.getResponseGetter());
1✔
248
  }
249

250
  public com.stripe.service.MarginService margins() {
251
    return new com.stripe.service.MarginService(this.getResponseGetter());
×
252
  }
253

254
  public com.stripe.service.OrderService orders() {
255
    return new com.stripe.service.OrderService(this.getResponseGetter());
×
256
  }
257

258
  public com.stripe.service.PaymentIntentService paymentIntents() {
259
    return new com.stripe.service.PaymentIntentService(this.getResponseGetter());
1✔
260
  }
261

262
  public com.stripe.service.PaymentLinkService paymentLinks() {
263
    return new com.stripe.service.PaymentLinkService(this.getResponseGetter());
1✔
264
  }
265

266
  public com.stripe.service.PaymentMethodConfigurationService paymentMethodConfigurations() {
267
    return new com.stripe.service.PaymentMethodConfigurationService(this.getResponseGetter());
1✔
268
  }
269

270
  public com.stripe.service.PaymentMethodDomainService paymentMethodDomains() {
271
    return new com.stripe.service.PaymentMethodDomainService(this.getResponseGetter());
×
272
  }
273

274
  public com.stripe.service.PaymentMethodService paymentMethods() {
275
    return new com.stripe.service.PaymentMethodService(this.getResponseGetter());
1✔
276
  }
277

278
  public com.stripe.service.PayoutService payouts() {
279
    return new com.stripe.service.PayoutService(this.getResponseGetter());
1✔
280
  }
281

282
  public com.stripe.service.PlanService plans() {
283
    return new com.stripe.service.PlanService(this.getResponseGetter());
1✔
284
  }
285

286
  public com.stripe.service.PriceService prices() {
287
    return new com.stripe.service.PriceService(this.getResponseGetter());
1✔
288
  }
289

290
  public com.stripe.service.ProductService products() {
291
    return new com.stripe.service.ProductService(this.getResponseGetter());
1✔
292
  }
293

294
  public com.stripe.service.PromotionCodeService promotionCodes() {
295
    return new com.stripe.service.PromotionCodeService(this.getResponseGetter());
1✔
296
  }
297

298
  public com.stripe.service.QuoteService quotes() {
299
    return new com.stripe.service.QuoteService(this.getResponseGetter());
1✔
300
  }
301

302
  public com.stripe.service.RadarService radar() {
303
    return new com.stripe.service.RadarService(this.getResponseGetter());
1✔
304
  }
305

306
  public com.stripe.service.RefundService refunds() {
307
    return new com.stripe.service.RefundService(this.getResponseGetter());
1✔
308
  }
309

310
  public com.stripe.service.ReportingService reporting() {
311
    return new com.stripe.service.ReportingService(this.getResponseGetter());
1✔
312
  }
313

314
  public com.stripe.service.ReviewService reviews() {
315
    return new com.stripe.service.ReviewService(this.getResponseGetter());
1✔
316
  }
317

318
  public com.stripe.service.SetupAttemptService setupAttempts() {
319
    return new com.stripe.service.SetupAttemptService(this.getResponseGetter());
1✔
320
  }
321

322
  public com.stripe.service.SetupIntentService setupIntents() {
323
    return new com.stripe.service.SetupIntentService(this.getResponseGetter());
1✔
324
  }
325

326
  public com.stripe.service.ShippingRateService shippingRates() {
327
    return new com.stripe.service.ShippingRateService(this.getResponseGetter());
1✔
328
  }
329

330
  public com.stripe.service.SigmaService sigma() {
331
    return new com.stripe.service.SigmaService(this.getResponseGetter());
1✔
332
  }
333

334
  public com.stripe.service.SourceService sources() {
335
    return new com.stripe.service.SourceService(this.getResponseGetter());
1✔
336
  }
337

338
  public com.stripe.service.SubscriptionItemService subscriptionItems() {
339
    return new com.stripe.service.SubscriptionItemService(this.getResponseGetter());
1✔
340
  }
341

342
  public com.stripe.service.SubscriptionScheduleService subscriptionSchedules() {
343
    return new com.stripe.service.SubscriptionScheduleService(this.getResponseGetter());
1✔
344
  }
345

346
  public com.stripe.service.SubscriptionService subscriptions() {
347
    return new com.stripe.service.SubscriptionService(this.getResponseGetter());
1✔
348
  }
349

350
  public com.stripe.service.TaxService tax() {
351
    return new com.stripe.service.TaxService(this.getResponseGetter());
1✔
352
  }
353

354
  public com.stripe.service.TaxCodeService taxCodes() {
355
    return new com.stripe.service.TaxCodeService(this.getResponseGetter());
1✔
356
  }
357

358
  public com.stripe.service.TaxIdService taxIds() {
359
    return new com.stripe.service.TaxIdService(this.getResponseGetter());
×
360
  }
361

362
  public com.stripe.service.TaxRateService taxRates() {
363
    return new com.stripe.service.TaxRateService(this.getResponseGetter());
1✔
364
  }
365

366
  public com.stripe.service.TerminalService terminal() {
367
    return new com.stripe.service.TerminalService(this.getResponseGetter());
1✔
368
  }
369

370
  public com.stripe.service.TestHelpersService testHelpers() {
371
    return new com.stripe.service.TestHelpersService(this.getResponseGetter());
1✔
372
  }
373

374
  public com.stripe.service.TokenService tokens() {
375
    return new com.stripe.service.TokenService(this.getResponseGetter());
1✔
376
  }
377

378
  public com.stripe.service.TopupService topups() {
379
    return new com.stripe.service.TopupService(this.getResponseGetter());
1✔
380
  }
381

382
  public com.stripe.service.TransferService transfers() {
383
    return new com.stripe.service.TransferService(this.getResponseGetter());
1✔
384
  }
385

386
  public com.stripe.service.TreasuryService treasury() {
387
    return new com.stripe.service.TreasuryService(this.getResponseGetter());
1✔
388
  }
389

390
  public com.stripe.service.V2Services v2() {
391
    return new com.stripe.service.V2Services(this.getResponseGetter());
1✔
392
  }
393

394
  public com.stripe.service.WebhookEndpointService webhookEndpoints() {
395
    return new com.stripe.service.WebhookEndpointService(this.getResponseGetter());
1✔
396
  }
397

398
  // The end of the section generated from our OpenAPI spec
399
  static class ClientStripeResponseGetterOptions extends StripeResponseGetterOptions {
400
    // When adding setting here keep them in sync with settings in RequestOptions and
401
    // in the RequestOptions.merge method
402
    @Getter(onMethod_ = {@Override})
403
    private final Authenticator authenticator;
404

405
    @Getter(onMethod_ = {@Override})
406
    private final String clientId;
407

408
    @Getter(onMethod_ = {@Override})
409
    private final int connectTimeout;
410

411
    @Getter(onMethod_ = {@Override})
412
    private final int readTimeout;
413

414
    @Getter(onMethod_ = {@Override})
415
    private final int maxNetworkRetries;
416

417
    @Getter(onMethod_ = {@Override})
418
    private final Proxy connectionProxy;
419

420
    @Getter(onMethod_ = {@Override})
421
    private final PasswordAuthentication proxyCredential;
422

423
    @Getter(onMethod_ = {@Override})
424
    private final String apiBase;
425

426
    @Getter(onMethod_ = {@Override})
427
    private final String filesBase;
428

429
    @Getter(onMethod_ = {@Override})
430
    private final String connectBase;
431

432
    @Getter(onMethod_ = {@Override})
433
    private final String meterEventsBase;
434

435
    @Getter(onMethod_ = {@Override})
436
    private final String stripeContext;
437

438
    ClientStripeResponseGetterOptions(
439
        Authenticator authenticator,
440
        String clientId,
441
        int connectTimeout,
442
        int readTimeout,
443
        int maxNetworkRetries,
444
        Proxy connectionProxy,
445
        PasswordAuthentication proxyCredential,
446
        String apiBase,
447
        String filesBase,
448
        String connectBase,
449
        String meterEventsBase,
450
        String stripeContext) {
1✔
451
      this.authenticator = authenticator;
1✔
452
      this.clientId = clientId;
1✔
453
      this.connectTimeout = connectTimeout;
1✔
454
      this.readTimeout = readTimeout;
1✔
455
      this.maxNetworkRetries = maxNetworkRetries;
1✔
456
      this.connectionProxy = connectionProxy;
1✔
457
      this.proxyCredential = proxyCredential;
1✔
458
      this.apiBase = apiBase;
1✔
459
      this.filesBase = filesBase;
1✔
460
      this.connectBase = connectBase;
1✔
461
      this.meterEventsBase = meterEventsBase;
1✔
462
      this.stripeContext = stripeContext;
1✔
463
    }
1✔
464
  }
465

466
  /**
467
   * Builder class for creating a {@link StripeClient} instance. Allows you to specify settings like
468
   * the API key, connect and read timeouts, and proxy settings.
469
   */
470
  public static StripeClientBuilder builder() {
471
    return new StripeClientBuilder();
1✔
472
  }
473

474
  public static final class StripeClientBuilder {
475
    private Authenticator authenticator;
476
    private String clientId;
477
    private int connectTimeout = Stripe.DEFAULT_CONNECT_TIMEOUT;
1✔
478
    private int readTimeout = Stripe.DEFAULT_READ_TIMEOUT;
1✔
479
    private int maxNetworkRetries;
480
    private Proxy connectionProxy;
481
    private PasswordAuthentication proxyCredential;
482
    private String apiBase = Stripe.LIVE_API_BASE;
1✔
483
    private String filesBase = Stripe.UPLOAD_API_BASE;
1✔
484
    private String connectBase = Stripe.CONNECT_API_BASE;
1✔
485
    private String meterEventsBase = Stripe.METER_EVENTS_API_BASE;
1✔
486
    private String stripeContext;
487

488
    /**
489
     * Constructs a request options builder with the global parameters (API key and client ID) as
490
     * default values.
491
     */
492
    public StripeClientBuilder() {}
1✔
493

494
    public Authenticator getAuthenticator() {
NEW
495
      return this.authenticator;
×
496
    }
497

498
    public StripeClientBuilder setAuthenticator(Authenticator authenticator) {
NEW
499
      this.authenticator = authenticator;
×
NEW
500
      return this;
×
501
    }
502

503
    public String getApiKey() {
NEW
504
      if (authenticator instanceof BearerTokenAuthenticator) {
×
NEW
505
        return ((BearerTokenAuthenticator) authenticator).getApiKey();
×
506
      }
507

NEW
508
      return null;
×
509
    }
510

511
    public StripeClientBuilder setApiKey(String apiKey) {
512
      if (apiKey == null) {
1✔
NEW
513
        this.authenticator = null;
×
514
      } else {
515
        this.authenticator = new BearerTokenAuthenticator(apiKey);
1✔
516
      }
517
      return this;
1✔
518
    }
519

520
    public StripeClientBuilder clearApiKey() {
NEW
521
      this.authenticator = null;
×
UNCOV
522
      return this;
×
523
    }
524

525
    public String getClientId() {
526
      return clientId;
×
527
    }
528

529
    /**
530
     * Set the client id, used for OAuth with Stripe Connect.
531
     *
532
     * @param clientId client ID
533
     */
534
    public StripeClientBuilder setClientId(String clientId) {
535
      this.clientId = clientId;
×
536
      return this;
×
537
    }
538

539
    public int getConnectTimeout() {
540
      return connectTimeout;
×
541
    }
542

543
    /**
544
     * Sets the timeout value that will be used for making new connections to the Stripe API (in
545
     * milliseconds).
546
     *
547
     * @param timeout timeout value in milliseconds
548
     */
549
    public StripeClientBuilder setConnectTimeout(int timeout) {
550
      this.connectTimeout = timeout;
×
551
      return this;
×
552
    }
553

554
    public int getReadTimeout() {
555
      return readTimeout;
×
556
    }
557

558
    /**
559
     * Sets the timeout value that will be used when reading data from an established connection to
560
     * the Stripe API (in milliseconds).
561
     *
562
     * <p>Note that this value should be set conservatively because some API requests can take time
563
     * and a short timeout increases the likelihood of causing a problem in the backend.
564
     *
565
     * @param timeout timeout value in milliseconds
566
     */
567
    public StripeClientBuilder setReadTimeout(int timeout) {
568
      this.readTimeout = timeout;
×
569
      return this;
×
570
    }
571

572
    public int getMaxNetworkRetries() {
573
      return maxNetworkRetries;
×
574
    }
575

576
    /**
577
     * Sets the maximum number of times the request will be retried in the event of a failure.
578
     *
579
     * @param maxNetworkRetries the number of times to retry the request
580
     */
581
    public StripeClientBuilder setMaxNetworkRetries(int maxNetworkRetries) {
582
      this.maxNetworkRetries = maxNetworkRetries;
×
583
      return this;
×
584
    }
585

586
    public Proxy getConnectionProxy() {
587
      return connectionProxy;
×
588
    }
589

590
    /**
591
     * Set proxy to tunnel all Stripe connections.
592
     *
593
     * @param connectionProxy proxy host and port setting
594
     */
595
    public StripeClientBuilder setConnectionProxy(Proxy connectionProxy) {
596
      this.connectionProxy = connectionProxy;
×
597
      return this;
×
598
    }
599

600
    public PasswordAuthentication getProxyCredential() {
601
      return proxyCredential;
×
602
    }
603

604
    /**
605
     * Provide credential for proxy authorization if required.
606
     *
607
     * @param proxyCredential proxy required userName and password
608
     */
609
    public StripeClientBuilder setProxyCredential(PasswordAuthentication proxyCredential) {
610
      this.proxyCredential = proxyCredential;
×
611
      return this;
×
612
    }
613

614
    /**
615
     * Set the base URL for the Stripe API. By default this is "https://api.stripe.com".
616
     *
617
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of API. Use
618
     * {@link setFilesBase} or {@link setConnectBase} to interpect requests with other bases.
619
     */
620
    public StripeClientBuilder setApiBase(String address) {
621
      this.apiBase = address;
1✔
622
      return this;
1✔
623
    }
624

625
    public String getApiBase() {
626
      return this.apiBase;
×
627
    }
628

629
    /**
630
     * Set the base URL for the Stripe Files API. By default this is "https://files.stripe.com".
631
     *
632
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of FILES.
633
     */
634
    public StripeClientBuilder setFilesBase(String address) {
635
      this.filesBase = address;
×
636
      return this;
×
637
    }
638

639
    public String getFilesBase() {
640
      return this.filesBase;
×
641
    }
642

643
    /**
644
     * Set the base URL for the Stripe Connect API. By default this is "https://connect.stripe.com".
645
     *
646
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of CONNECT.
647
     */
648
    public StripeClientBuilder setConnectBase(String address) {
649
      this.connectBase = address;
×
650
      return this;
×
651
    }
652

653
    public String getConnectBase() {
654
      return this.connectBase;
×
655
    }
656

657
    /**
658
     * Set the base URL for the Stripe Meter Events API. By default this is
659
     * "https://events.stripe.com".
660
     *
661
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of EVENTMES.
662
     */
663
    public StripeClientBuilder setMeterEventsBase(String address) {
NEW
664
      this.meterEventsBase = address;
×
NEW
665
      return this;
×
666
    }
667

668
    public String getMeterEventsBase() {
NEW
669
      return this.meterEventsBase;
×
670
    }
671

672
    public StripeClientBuilder setStripeContext(String context) {
NEW
673
      this.stripeContext = context;
×
NEW
674
      return this;
×
675
    }
676

677
    public String getStripeContext() {
NEW
678
      return this.stripeContext;
×
679
    }
680

681
    /** Constructs a {@link StripeResponseGetterOptions} with the specified values. */
682
    public StripeClient build() {
683
      return new StripeClient(new LiveStripeResponseGetter(buildOptions(), null));
×
684
    }
685

686
    StripeResponseGetterOptions buildOptions() {
687
      if (this.authenticator == null) {
1✔
688
        throw new IllegalArgumentException(
×
689
            "No authentication settings provided. Use setApiKey to set the Stripe API key");
690
      }
691
      return new ClientStripeResponseGetterOptions(
1✔
692
          this.authenticator,
693
          this.clientId,
694
          connectTimeout,
695
          readTimeout,
696
          maxNetworkRetries,
697
          connectionProxy,
698
          proxyCredential,
699
          apiBase,
700
          filesBase,
701
          connectBase,
702
          meterEventsBase,
703
          this.stripeContext);
704
    }
705
  }
706

707
  /**
708
   * Send raw request to Stripe API. This is the lowest level method for interacting with the Stripe
709
   * API. This method is useful for interacting with endpoints that are not covered yet in
710
   * stripe-java.
711
   *
712
   * @param method the HTTP method
713
   * @param relativeUrl the relative URL of the request, e.g. "/v1/charges"
714
   * @param content the body of the request as a string
715
   * @return the JSON response as a string
716
   */
717
  public StripeResponse rawRequest(
718
      final ApiResource.RequestMethod method, final String relativeUrl, final String content)
719
      throws StripeException {
720
    return rawRequest(method, relativeUrl, content, null);
×
721
  }
722

723
  /**
724
   * Send raw request to Stripe API. This is the lowest level method for interacting with the Stripe
725
   * API. This method is useful for interacting with endpoints that are not covered yet in
726
   * stripe-java.
727
   *
728
   * @param method the HTTP method
729
   * @param relativeUrl the relative URL of the request, e.g. "/v1/charges"
730
   * @param content the body of the request as a string
731
   * @param options the special modifiers of the request
732
   * @return the JSON response as a string
733
   */
734
  public StripeResponse rawRequest(
735
      final ApiResource.RequestMethod method,
736
      final String relativeUrl,
737
      final String content,
738
      RawRequestOptions options)
739
      throws StripeException {
740
    if (options == null) {
1✔
741
      options = RawRequestOptions.builder().build();
1✔
742
    }
743
    if (method != ApiResource.RequestMethod.POST && content != null && !content.equals("")) {
1✔
744
      throw new IllegalArgumentException(
1✔
745
          "content is not allowed for non-POST requests. Please pass null and add request parameters to the query string of the URL.");
746
    }
747
    RawApiRequest req = new RawApiRequest(BaseAddress.API, method, relativeUrl, content, options);
1✔
748
    req = req.addUsage("stripe_client");
1✔
749
    req = req.addUsage("raw_request");
1✔
750
    return this.getResponseGetter().rawRequest(req);
1✔
751
  }
752

753
  /** Deserializes StripeResponse returned by rawRequest into a similar class. */
754
  public StripeObject deserialize(String rawJson, ApiMode apiMode) throws StripeException {
755
    return StripeObject.deserializeStripeObject(rawJson, this.getResponseGetter(), apiMode);
1✔
756
  }
757
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc