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

stripe / stripe-java / #16624

07 Nov 2024 10:04PM UTC coverage: 12.419% (-0.1%) from 12.519%
#16624

push

github

web-flow
Merge pull request #1917 from stripe/latest-codegen-beta

Update generated code for beta

17 of 1341 new or added lines in 57 files covered. (1.27%)

33 existing lines in 29 files now uncovered.

18855 of 151828 relevant lines covered (12.42%)

0.12 hits per line

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

64.37
/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
    return parseThinEvent(payload, sigHeader, secret, Webhook.DEFAULT_TOLERANCE);
1✔
58
  }
59

60
  /**
61
   * Returns an StripeEvent instance using the provided JSON payload. Throws a JsonSyntaxException
62
   * if the payload is not valid JSON, and a SignatureVerificationException if the signature
63
   * verification fails for any reason.
64
   *
65
   * @param payload the payload sent by Stripe.
66
   * @param sigHeader the contents of the signature header sent by Stripe.
67
   * @param secret secret used to generate the signature.
68
   * @param tolerance number of seconds that the event's timestamp can differ from the system time.
69
   *     Passing `0` will disable the time check entirely and is **strongly discouraged**.
70
   * @return the StripeEvent instance
71
   * @throws SignatureVerificationException if the verification fails.
72
   */
73
  public ThinEvent parseThinEvent(String payload, String sigHeader, String secret, long tolerance)
74
      throws SignatureVerificationException {
75
    Signature.verifyHeader(payload, sigHeader, secret, tolerance);
1✔
76

77
    return ApiResource.GSON.fromJson(payload, ThinEvent.class);
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
   * @return the Event instance
89
   * @throws SignatureVerificationException if the verification fails.
90
   */
91
  public com.stripe.model.Event constructEvent(String payload, String sigHeader, String secret)
92
      throws SignatureVerificationException {
93
    com.stripe.model.Event event = Webhook.constructEvent(payload, sigHeader, secret);
1✔
94
    event.setResponseGetter(this.getResponseGetter());
1✔
95
    return event;
1✔
96
  }
97

98
  /**
99
   * Returns an Event instance using the provided JSON payload. Throws a JsonSyntaxException if the
100
   * payload is not valid JSON, and a SignatureVerificationException if the signature verification
101
   * fails for any reason.
102
   *
103
   * @param payload the payload sent by Stripe.
104
   * @param sigHeader the contents of the signature header sent by Stripe.
105
   * @param secret secret used to generate the signature.
106
   * @param tolerance maximum difference in seconds allowed between the header's timestamp and the
107
   *     current time
108
   * @return the Event instance
109
   * @throws SignatureVerificationException if the verification fails.
110
   */
111
  public com.stripe.model.Event constructEvent(
112
      String payload, String sigHeader, String secret, long tolerance)
113
      throws SignatureVerificationException {
114
    com.stripe.model.Event event = Webhook.constructEvent(payload, sigHeader, secret, tolerance);
1✔
115
    event.setResponseGetter(this.getResponseGetter());
1✔
116
    return event;
1✔
117
  }
118

119
  // The beginning of the section generated from our OpenAPI spec
120
  public com.stripe.service.AccountLinkService accountLinks() {
121
    return new com.stripe.service.AccountLinkService(this.getResponseGetter());
1✔
122
  }
123

124
  public com.stripe.service.AccountNoticeService accountNotices() {
125
    return new com.stripe.service.AccountNoticeService(this.getResponseGetter());
×
126
  }
127

128
  public com.stripe.service.AccountSessionService accountSessions() {
129
    return new com.stripe.service.AccountSessionService(this.getResponseGetter());
×
130
  }
131

132
  public com.stripe.service.AccountService accounts() {
133
    return new com.stripe.service.AccountService(this.getResponseGetter());
1✔
134
  }
135

136
  public com.stripe.service.ApplePayDomainService applePayDomains() {
137
    return new com.stripe.service.ApplePayDomainService(this.getResponseGetter());
×
138
  }
139

140
  public com.stripe.service.ApplicationFeeService applicationFees() {
141
    return new com.stripe.service.ApplicationFeeService(this.getResponseGetter());
1✔
142
  }
143

144
  public com.stripe.service.AppsService apps() {
145
    return new com.stripe.service.AppsService(this.getResponseGetter());
1✔
146
  }
147

148
  public com.stripe.service.BalanceService balance() {
149
    return new com.stripe.service.BalanceService(this.getResponseGetter());
×
150
  }
151

152
  public com.stripe.service.BalanceTransactionService balanceTransactions() {
153
    return new com.stripe.service.BalanceTransactionService(this.getResponseGetter());
1✔
154
  }
155

156
  public com.stripe.service.BillingService billing() {
157
    return new com.stripe.service.BillingService(this.getResponseGetter());
×
158
  }
159

160
  public com.stripe.service.BillingPortalService billingPortal() {
161
    return new com.stripe.service.BillingPortalService(this.getResponseGetter());
1✔
162
  }
163

164
  public com.stripe.service.CapitalService capital() {
165
    return new com.stripe.service.CapitalService(this.getResponseGetter());
×
166
  }
167

168
  public com.stripe.service.ChargeService charges() {
169
    return new com.stripe.service.ChargeService(this.getResponseGetter());
1✔
170
  }
171

172
  public com.stripe.service.CheckoutService checkout() {
173
    return new com.stripe.service.CheckoutService(this.getResponseGetter());
1✔
174
  }
175

176
  public com.stripe.service.ClimateService climate() {
177
    return new com.stripe.service.ClimateService(this.getResponseGetter());
×
178
  }
179

180
  public com.stripe.service.ConfirmationTokenService confirmationTokens() {
181
    return new com.stripe.service.ConfirmationTokenService(this.getResponseGetter());
×
182
  }
183

184
  public com.stripe.service.CountrySpecService countrySpecs() {
185
    return new com.stripe.service.CountrySpecService(this.getResponseGetter());
1✔
186
  }
187

188
  public com.stripe.service.CouponService coupons() {
189
    return new com.stripe.service.CouponService(this.getResponseGetter());
1✔
190
  }
191

192
  public com.stripe.service.CreditNoteService creditNotes() {
193
    return new com.stripe.service.CreditNoteService(this.getResponseGetter());
1✔
194
  }
195

196
  public com.stripe.service.CustomerSessionService customerSessions() {
197
    return new com.stripe.service.CustomerSessionService(this.getResponseGetter());
1✔
198
  }
199

200
  public com.stripe.service.CustomerService customers() {
201
    return new com.stripe.service.CustomerService(this.getResponseGetter());
1✔
202
  }
203

204
  public com.stripe.service.DisputeService disputes() {
205
    return new com.stripe.service.DisputeService(this.getResponseGetter());
1✔
206
  }
207

208
  public com.stripe.service.EntitlementsService entitlements() {
209
    return new com.stripe.service.EntitlementsService(this.getResponseGetter());
×
210
  }
211

212
  public com.stripe.service.EphemeralKeyService ephemeralKeys() {
213
    return new com.stripe.service.EphemeralKeyService(this.getResponseGetter());
1✔
214
  }
215

216
  public com.stripe.service.EventService events() {
217
    return new com.stripe.service.EventService(this.getResponseGetter());
1✔
218
  }
219

220
  public com.stripe.service.ExchangeRateService exchangeRates() {
221
    return new com.stripe.service.ExchangeRateService(this.getResponseGetter());
×
222
  }
223

224
  public com.stripe.service.FileLinkService fileLinks() {
225
    return new com.stripe.service.FileLinkService(this.getResponseGetter());
1✔
226
  }
227

228
  public com.stripe.service.FileService files() {
229
    return new com.stripe.service.FileService(this.getResponseGetter());
1✔
230
  }
231

232
  public com.stripe.service.FinancialConnectionsService financialConnections() {
233
    return new com.stripe.service.FinancialConnectionsService(this.getResponseGetter());
1✔
234
  }
235

236
  public com.stripe.service.ForwardingService forwarding() {
237
    return new com.stripe.service.ForwardingService(this.getResponseGetter());
×
238
  }
239

240
  public com.stripe.service.GiftCardsService giftCards() {
241
    return new com.stripe.service.GiftCardsService(this.getResponseGetter());
×
242
  }
243

244
  public com.stripe.service.IdentityService identity() {
245
    return new com.stripe.service.IdentityService(this.getResponseGetter());
1✔
246
  }
247

248
  public com.stripe.service.InvoiceItemService invoiceItems() {
249
    return new com.stripe.service.InvoiceItemService(this.getResponseGetter());
1✔
250
  }
251

252
  public com.stripe.service.InvoiceRenderingTemplateService invoiceRenderingTemplates() {
253
    return new com.stripe.service.InvoiceRenderingTemplateService(this.getResponseGetter());
×
254
  }
255

256
  public com.stripe.service.InvoiceService invoices() {
257
    return new com.stripe.service.InvoiceService(this.getResponseGetter());
1✔
258
  }
259

260
  public com.stripe.service.IssuingService issuing() {
261
    return new com.stripe.service.IssuingService(this.getResponseGetter());
1✔
262
  }
263

264
  public com.stripe.service.MandateService mandates() {
265
    return new com.stripe.service.MandateService(this.getResponseGetter());
1✔
266
  }
267

268
  public com.stripe.service.MarginService margins() {
269
    return new com.stripe.service.MarginService(this.getResponseGetter());
×
270
  }
271

272
  public com.stripe.service.OrderService orders() {
273
    return new com.stripe.service.OrderService(this.getResponseGetter());
×
274
  }
275

276
  public com.stripe.service.PaymentAttemptRecordService paymentAttemptRecords() {
NEW
277
    return new com.stripe.service.PaymentAttemptRecordService(this.getResponseGetter());
×
278
  }
279

280
  public com.stripe.service.PaymentIntentService paymentIntents() {
281
    return new com.stripe.service.PaymentIntentService(this.getResponseGetter());
1✔
282
  }
283

284
  public com.stripe.service.PaymentLinkService paymentLinks() {
285
    return new com.stripe.service.PaymentLinkService(this.getResponseGetter());
1✔
286
  }
287

288
  public com.stripe.service.PaymentMethodConfigurationService paymentMethodConfigurations() {
289
    return new com.stripe.service.PaymentMethodConfigurationService(this.getResponseGetter());
1✔
290
  }
291

292
  public com.stripe.service.PaymentMethodDomainService paymentMethodDomains() {
293
    return new com.stripe.service.PaymentMethodDomainService(this.getResponseGetter());
×
294
  }
295

296
  public com.stripe.service.PaymentMethodService paymentMethods() {
297
    return new com.stripe.service.PaymentMethodService(this.getResponseGetter());
1✔
298
  }
299

300
  public com.stripe.service.PaymentRecordService paymentRecords() {
NEW
301
    return new com.stripe.service.PaymentRecordService(this.getResponseGetter());
×
302
  }
303

304
  public com.stripe.service.PayoutService payouts() {
305
    return new com.stripe.service.PayoutService(this.getResponseGetter());
1✔
306
  }
307

308
  public com.stripe.service.PlanService plans() {
309
    return new com.stripe.service.PlanService(this.getResponseGetter());
1✔
310
  }
311

312
  public com.stripe.service.PriceService prices() {
313
    return new com.stripe.service.PriceService(this.getResponseGetter());
1✔
314
  }
315

316
  public com.stripe.service.ProductService products() {
317
    return new com.stripe.service.ProductService(this.getResponseGetter());
1✔
318
  }
319

320
  public com.stripe.service.PromotionCodeService promotionCodes() {
321
    return new com.stripe.service.PromotionCodeService(this.getResponseGetter());
1✔
322
  }
323

324
  public com.stripe.service.QuoteService quotes() {
325
    return new com.stripe.service.QuoteService(this.getResponseGetter());
1✔
326
  }
327

328
  public com.stripe.service.RadarService radar() {
329
    return new com.stripe.service.RadarService(this.getResponseGetter());
1✔
330
  }
331

332
  public com.stripe.service.RefundService refunds() {
333
    return new com.stripe.service.RefundService(this.getResponseGetter());
1✔
334
  }
335

336
  public com.stripe.service.ReportingService reporting() {
337
    return new com.stripe.service.ReportingService(this.getResponseGetter());
1✔
338
  }
339

340
  public com.stripe.service.ReviewService reviews() {
341
    return new com.stripe.service.ReviewService(this.getResponseGetter());
1✔
342
  }
343

344
  public com.stripe.service.SetupAttemptService setupAttempts() {
345
    return new com.stripe.service.SetupAttemptService(this.getResponseGetter());
1✔
346
  }
347

348
  public com.stripe.service.SetupIntentService setupIntents() {
349
    return new com.stripe.service.SetupIntentService(this.getResponseGetter());
1✔
350
  }
351

352
  public com.stripe.service.ShippingRateService shippingRates() {
353
    return new com.stripe.service.ShippingRateService(this.getResponseGetter());
1✔
354
  }
355

356
  public com.stripe.service.SigmaService sigma() {
357
    return new com.stripe.service.SigmaService(this.getResponseGetter());
1✔
358
  }
359

360
  public com.stripe.service.SourceService sources() {
361
    return new com.stripe.service.SourceService(this.getResponseGetter());
1✔
362
  }
363

364
  public com.stripe.service.SubscriptionItemService subscriptionItems() {
365
    return new com.stripe.service.SubscriptionItemService(this.getResponseGetter());
1✔
366
  }
367

368
  public com.stripe.service.SubscriptionScheduleService subscriptionSchedules() {
369
    return new com.stripe.service.SubscriptionScheduleService(this.getResponseGetter());
1✔
370
  }
371

372
  public com.stripe.service.SubscriptionService subscriptions() {
373
    return new com.stripe.service.SubscriptionService(this.getResponseGetter());
1✔
374
  }
375

376
  public com.stripe.service.TaxService tax() {
377
    return new com.stripe.service.TaxService(this.getResponseGetter());
1✔
378
  }
379

380
  public com.stripe.service.TaxCodeService taxCodes() {
381
    return new com.stripe.service.TaxCodeService(this.getResponseGetter());
1✔
382
  }
383

384
  public com.stripe.service.TaxIdService taxIds() {
385
    return new com.stripe.service.TaxIdService(this.getResponseGetter());
×
386
  }
387

388
  public com.stripe.service.TaxRateService taxRates() {
389
    return new com.stripe.service.TaxRateService(this.getResponseGetter());
1✔
390
  }
391

392
  public com.stripe.service.TerminalService terminal() {
393
    return new com.stripe.service.TerminalService(this.getResponseGetter());
1✔
394
  }
395

396
  public com.stripe.service.TestHelpersService testHelpers() {
397
    return new com.stripe.service.TestHelpersService(this.getResponseGetter());
1✔
398
  }
399

400
  public com.stripe.service.TokenService tokens() {
401
    return new com.stripe.service.TokenService(this.getResponseGetter());
1✔
402
  }
403

404
  public com.stripe.service.TopupService topups() {
405
    return new com.stripe.service.TopupService(this.getResponseGetter());
1✔
406
  }
407

408
  public com.stripe.service.TransferService transfers() {
409
    return new com.stripe.service.TransferService(this.getResponseGetter());
1✔
410
  }
411

412
  public com.stripe.service.TreasuryService treasury() {
413
    return new com.stripe.service.TreasuryService(this.getResponseGetter());
1✔
414
  }
415

416
  public com.stripe.service.V2Services v2() {
417
    return new com.stripe.service.V2Services(this.getResponseGetter());
1✔
418
  }
419

420
  public com.stripe.service.WebhookEndpointService webhookEndpoints() {
421
    return new com.stripe.service.WebhookEndpointService(this.getResponseGetter());
1✔
422
  }
423

424
  // The end of the section generated from our OpenAPI spec
425
  static class ClientStripeResponseGetterOptions extends StripeResponseGetterOptions {
426
    // When adding setting here keep them in sync with settings in RequestOptions and
427
    // in the RequestOptions.merge method
428
    @Getter(onMethod_ = {@Override})
429
    private final Authenticator authenticator;
430

431
    @Getter(onMethod_ = {@Override})
432
    private final String clientId;
433

434
    @Getter(onMethod_ = {@Override})
435
    private final int connectTimeout;
436

437
    @Getter(onMethod_ = {@Override})
438
    private final int readTimeout;
439

440
    @Getter(onMethod_ = {@Override})
441
    private final int maxNetworkRetries;
442

443
    @Getter(onMethod_ = {@Override})
444
    private final Proxy connectionProxy;
445

446
    @Getter(onMethod_ = {@Override})
447
    private final PasswordAuthentication proxyCredential;
448

449
    @Getter(onMethod_ = {@Override})
450
    private final String apiBase;
451

452
    @Getter(onMethod_ = {@Override})
453
    private final String filesBase;
454

455
    @Getter(onMethod_ = {@Override})
456
    private final String connectBase;
457

458
    @Getter(onMethod_ = {@Override})
459
    private final String meterEventsBase;
460

461
    @Getter(onMethod_ = {@Override})
462
    private final String stripeContext;
463

464
    ClientStripeResponseGetterOptions(
465
        Authenticator authenticator,
466
        String clientId,
467
        int connectTimeout,
468
        int readTimeout,
469
        int maxNetworkRetries,
470
        Proxy connectionProxy,
471
        PasswordAuthentication proxyCredential,
472
        String apiBase,
473
        String filesBase,
474
        String connectBase,
475
        String meterEventsBase,
476
        String stripeContext) {
1✔
477
      this.authenticator = authenticator;
1✔
478
      this.clientId = clientId;
1✔
479
      this.connectTimeout = connectTimeout;
1✔
480
      this.readTimeout = readTimeout;
1✔
481
      this.maxNetworkRetries = maxNetworkRetries;
1✔
482
      this.connectionProxy = connectionProxy;
1✔
483
      this.proxyCredential = proxyCredential;
1✔
484
      this.apiBase = apiBase;
1✔
485
      this.filesBase = filesBase;
1✔
486
      this.connectBase = connectBase;
1✔
487
      this.meterEventsBase = meterEventsBase;
1✔
488
      this.stripeContext = stripeContext;
1✔
489
    }
1✔
490
  }
491

492
  /**
493
   * Builder class for creating a {@link StripeClient} instance. Allows you to specify settings like
494
   * the API key, connect and read timeouts, and proxy settings.
495
   */
496
  public static StripeClientBuilder builder() {
497
    return new StripeClientBuilder();
1✔
498
  }
499

500
  public static final class StripeClientBuilder {
501
    private Authenticator authenticator;
502
    private String clientId;
503
    private int connectTimeout = Stripe.DEFAULT_CONNECT_TIMEOUT;
1✔
504
    private int readTimeout = Stripe.DEFAULT_READ_TIMEOUT;
1✔
505
    private int maxNetworkRetries;
506
    private Proxy connectionProxy;
507
    private PasswordAuthentication proxyCredential;
508
    private String apiBase = Stripe.LIVE_API_BASE;
1✔
509
    private String filesBase = Stripe.UPLOAD_API_BASE;
1✔
510
    private String connectBase = Stripe.CONNECT_API_BASE;
1✔
511
    private String meterEventsBase = Stripe.METER_EVENTS_API_BASE;
1✔
512
    private String stripeContext;
513

514
    /**
515
     * Constructs a request options builder with the global parameters (API key and client ID) as
516
     * default values.
517
     */
518
    public StripeClientBuilder() {}
1✔
519

520
    public Authenticator getAuthenticator() {
521
      return this.authenticator;
×
522
    }
523

524
    public StripeClientBuilder setAuthenticator(Authenticator authenticator) {
525
      this.authenticator = authenticator;
×
526
      return this;
×
527
    }
528

529
    public String getApiKey() {
530
      if (authenticator instanceof BearerTokenAuthenticator) {
×
531
        return ((BearerTokenAuthenticator) authenticator).getApiKey();
×
532
      }
533

534
      return null;
×
535
    }
536

537
    public StripeClientBuilder setApiKey(String apiKey) {
538
      if (apiKey == null) {
1✔
539
        this.authenticator = null;
×
540
      } else {
541
        this.authenticator = new BearerTokenAuthenticator(apiKey);
1✔
542
      }
543
      return this;
1✔
544
    }
545

546
    public StripeClientBuilder clearApiKey() {
547
      this.authenticator = null;
×
548
      return this;
×
549
    }
550

551
    public String getClientId() {
552
      return clientId;
×
553
    }
554

555
    /**
556
     * Set the client id, used for OAuth with Stripe Connect.
557
     *
558
     * @param clientId client ID
559
     */
560
    public StripeClientBuilder setClientId(String clientId) {
561
      this.clientId = clientId;
×
562
      return this;
×
563
    }
564

565
    public int getConnectTimeout() {
566
      return connectTimeout;
×
567
    }
568

569
    /**
570
     * Sets the timeout value that will be used for making new connections to the Stripe API (in
571
     * milliseconds).
572
     *
573
     * @param timeout timeout value in milliseconds
574
     */
575
    public StripeClientBuilder setConnectTimeout(int timeout) {
576
      this.connectTimeout = timeout;
×
577
      return this;
×
578
    }
579

580
    public int getReadTimeout() {
581
      return readTimeout;
×
582
    }
583

584
    /**
585
     * Sets the timeout value that will be used when reading data from an established connection to
586
     * the Stripe API (in milliseconds).
587
     *
588
     * <p>Note that this value should be set conservatively because some API requests can take time
589
     * and a short timeout increases the likelihood of causing a problem in the backend.
590
     *
591
     * @param timeout timeout value in milliseconds
592
     */
593
    public StripeClientBuilder setReadTimeout(int timeout) {
594
      this.readTimeout = timeout;
×
595
      return this;
×
596
    }
597

598
    public int getMaxNetworkRetries() {
599
      return maxNetworkRetries;
×
600
    }
601

602
    /**
603
     * Sets the maximum number of times the request will be retried in the event of a failure.
604
     *
605
     * @param maxNetworkRetries the number of times to retry the request
606
     */
607
    public StripeClientBuilder setMaxNetworkRetries(int maxNetworkRetries) {
608
      this.maxNetworkRetries = maxNetworkRetries;
×
609
      return this;
×
610
    }
611

612
    public Proxy getConnectionProxy() {
613
      return connectionProxy;
×
614
    }
615

616
    /**
617
     * Set proxy to tunnel all Stripe connections.
618
     *
619
     * @param connectionProxy proxy host and port setting
620
     */
621
    public StripeClientBuilder setConnectionProxy(Proxy connectionProxy) {
622
      this.connectionProxy = connectionProxy;
×
623
      return this;
×
624
    }
625

626
    public PasswordAuthentication getProxyCredential() {
627
      return proxyCredential;
×
628
    }
629

630
    /**
631
     * Provide credential for proxy authorization if required.
632
     *
633
     * @param proxyCredential proxy required userName and password
634
     */
635
    public StripeClientBuilder setProxyCredential(PasswordAuthentication proxyCredential) {
636
      this.proxyCredential = proxyCredential;
×
637
      return this;
×
638
    }
639

640
    /**
641
     * Set the base URL for the Stripe API. By default this is "https://api.stripe.com".
642
     *
643
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of API. Use
644
     * {@link setFilesBase} or {@link setConnectBase} to interpect requests with other bases.
645
     */
646
    public StripeClientBuilder setApiBase(String address) {
647
      this.apiBase = address;
1✔
648
      return this;
1✔
649
    }
650

651
    public String getApiBase() {
652
      return this.apiBase;
×
653
    }
654

655
    /**
656
     * Set the base URL for the Stripe Files API. By default this is "https://files.stripe.com".
657
     *
658
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of FILES.
659
     */
660
    public StripeClientBuilder setFilesBase(String address) {
661
      this.filesBase = address;
×
662
      return this;
×
663
    }
664

665
    public String getFilesBase() {
666
      return this.filesBase;
×
667
    }
668

669
    /**
670
     * Set the base URL for the Stripe Connect API. By default this is "https://connect.stripe.com".
671
     *
672
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of CONNECT.
673
     */
674
    public StripeClientBuilder setConnectBase(String address) {
675
      this.connectBase = address;
×
676
      return this;
×
677
    }
678

679
    public String getConnectBase() {
680
      return this.connectBase;
×
681
    }
682

683
    /**
684
     * Set the base URL for the Stripe Meter Events API. By default this is
685
     * "https://events.stripe.com".
686
     *
687
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of EVENTMES.
688
     */
689
    public StripeClientBuilder setMeterEventsBase(String address) {
690
      this.meterEventsBase = address;
×
691
      return this;
×
692
    }
693

694
    public String getMeterEventsBase() {
695
      return this.meterEventsBase;
×
696
    }
697

698
    public StripeClientBuilder setStripeContext(String context) {
699
      this.stripeContext = context;
×
700
      return this;
×
701
    }
702

703
    public String getStripeContext() {
704
      return this.stripeContext;
×
705
    }
706

707
    /** Constructs a {@link StripeResponseGetterOptions} with the specified values. */
708
    public StripeClient build() {
709
      return new StripeClient(new LiveStripeResponseGetter(buildOptions(), null));
×
710
    }
711

712
    StripeResponseGetterOptions buildOptions() {
713
      if (this.authenticator == null) {
1✔
714
        throw new IllegalArgumentException(
×
715
            "No authentication settings provided. Use setApiKey to set the Stripe API key");
716
      }
717
      return new ClientStripeResponseGetterOptions(
1✔
718
          this.authenticator,
719
          this.clientId,
720
          connectTimeout,
721
          readTimeout,
722
          maxNetworkRetries,
723
          connectionProxy,
724
          proxyCredential,
725
          apiBase,
726
          filesBase,
727
          connectBase,
728
          meterEventsBase,
729
          this.stripeContext);
730
    }
731
  }
732

733
  /**
734
   * Send raw request to Stripe API. This is the lowest level method for interacting with the Stripe
735
   * API. This method is useful for interacting with endpoints that are not covered yet in
736
   * stripe-java.
737
   *
738
   * @param method the HTTP method
739
   * @param relativeUrl the relative URL of the request, e.g. "/v1/charges"
740
   * @param content the body of the request as a string
741
   * @return the JSON response as a string
742
   */
743
  public StripeResponse rawRequest(
744
      final ApiResource.RequestMethod method, final String relativeUrl, final String content)
745
      throws StripeException {
746
    return rawRequest(method, relativeUrl, content, null);
×
747
  }
748

749
  /**
750
   * Send raw request to Stripe API. This is the lowest level method for interacting with the Stripe
751
   * API. This method is useful for interacting with endpoints that are not covered yet in
752
   * stripe-java.
753
   *
754
   * @param method the HTTP method
755
   * @param relativeUrl the relative URL of the request, e.g. "/v1/charges"
756
   * @param content the body of the request as a string
757
   * @param options the special modifiers of the request
758
   * @return the JSON response as a string
759
   */
760
  public StripeResponse rawRequest(
761
      final ApiResource.RequestMethod method,
762
      final String relativeUrl,
763
      final String content,
764
      RawRequestOptions options)
765
      throws StripeException {
766
    if (options == null) {
1✔
767
      options = RawRequestOptions.builder().build();
1✔
768
    }
769
    if (method != ApiResource.RequestMethod.POST && content != null && !content.equals("")) {
1✔
770
      throw new IllegalArgumentException(
1✔
771
          "content is not allowed for non-POST requests. Please pass null and add request parameters to the query string of the URL.");
772
    }
773
    RawApiRequest req = new RawApiRequest(BaseAddress.API, method, relativeUrl, content, options);
1✔
774
    req = req.addUsage("stripe_client");
1✔
775
    req = req.addUsage("raw_request");
1✔
776
    return this.getResponseGetter().rawRequest(req);
1✔
777
  }
778

779
  /** Deserializes StripeResponse returned by rawRequest into a similar class. */
780
  public StripeObject deserialize(String rawJson, ApiMode apiMode) throws StripeException {
781
    return StripeObject.deserializeStripeObject(rawJson, this.getResponseGetter(), apiMode);
1✔
782
  }
783
}
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