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

stripe / stripe-java / #16418

13 Sep 2024 05:53PM UTC coverage: 12.856% (-0.02%) from 12.874%
#16418

push

github

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

Update generated code for beta

9 of 344 new or added lines in 28 files covered. (2.62%)

10 existing lines in 8 files now uncovered.

18470 of 143664 relevant lines covered (12.86%)

0.13 hits per line

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

66.23
/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.Event;
6
import com.stripe.model.StripeObject;
7
import com.stripe.net.*;
8
import java.net.PasswordAuthentication;
9
import java.net.Proxy;
10
import lombok.Getter;
11

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

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

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

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

43
  /**
44
   * Returns an Event instance using the provided JSON payload. Throws a JsonSyntaxException if the
45
   * payload is not valid JSON, and a SignatureVerificationException if the signature verification
46
   * fails for any reason.
47
   *
48
   * @param payload the payload sent by Stripe.
49
   * @param sigHeader the contents of the signature header sent by Stripe.
50
   * @param secret secret used to generate the signature.
51
   * @return the Event instance
52
   * @throws SignatureVerificationException if the verification fails.
53
   */
54
  public Event constructEvent(String payload, String sigHeader, String secret)
55
      throws SignatureVerificationException {
56
    Event event = Webhook.constructEvent(payload, sigHeader, secret);
1✔
57
    event.setResponseGetter(this.getResponseGetter());
1✔
58
    return event;
1✔
59
  }
60

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

81
  // The beginning of the section generated from our OpenAPI spec
82
  public com.stripe.service.AccountLinkService accountLinks() {
83
    return new com.stripe.service.AccountLinkService(this.getResponseGetter());
1✔
84
  }
85

86
  public com.stripe.service.AccountNoticeService accountNotices() {
87
    return new com.stripe.service.AccountNoticeService(this.getResponseGetter());
×
88
  }
89

90
  public com.stripe.service.AccountSessionService accountSessions() {
91
    return new com.stripe.service.AccountSessionService(this.getResponseGetter());
×
92
  }
93

94
  public com.stripe.service.AccountService accounts() {
95
    return new com.stripe.service.AccountService(this.getResponseGetter());
1✔
96
  }
97

98
  public com.stripe.service.ApplePayDomainService applePayDomains() {
99
    return new com.stripe.service.ApplePayDomainService(this.getResponseGetter());
×
100
  }
101

102
  public com.stripe.service.ApplicationFeeService applicationFees() {
103
    return new com.stripe.service.ApplicationFeeService(this.getResponseGetter());
1✔
104
  }
105

106
  public com.stripe.service.AppsService apps() {
107
    return new com.stripe.service.AppsService(this.getResponseGetter());
1✔
108
  }
109

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

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

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

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

126
  public com.stripe.service.CapitalService capital() {
127
    return new com.stripe.service.CapitalService(this.getResponseGetter());
×
128
  }
129

130
  public com.stripe.service.ChargeService charges() {
131
    return new com.stripe.service.ChargeService(this.getResponseGetter());
1✔
132
  }
133

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

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

142
  public com.stripe.service.ConfirmationTokenService confirmationTokens() {
143
    return new com.stripe.service.ConfirmationTokenService(this.getResponseGetter());
×
144
  }
145

146
  public com.stripe.service.CountrySpecService countrySpecs() {
147
    return new com.stripe.service.CountrySpecService(this.getResponseGetter());
1✔
148
  }
149

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

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

158
  public com.stripe.service.CustomerSessionService customerSessions() {
159
    return new com.stripe.service.CustomerSessionService(this.getResponseGetter());
1✔
160
  }
161

162
  public com.stripe.service.CustomerService customers() {
163
    return new com.stripe.service.CustomerService(this.getResponseGetter());
1✔
164
  }
165

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

170
  public com.stripe.service.EntitlementsService entitlements() {
171
    return new com.stripe.service.EntitlementsService(this.getResponseGetter());
×
172
  }
173

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

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

182
  public com.stripe.service.ExchangeRateService exchangeRates() {
183
    return new com.stripe.service.ExchangeRateService(this.getResponseGetter());
×
184
  }
185

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

190
  public com.stripe.service.FileService files() {
191
    return new com.stripe.service.FileService(this.getResponseGetter());
1✔
192
  }
193

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

198
  public com.stripe.service.ForwardingService forwarding() {
199
    return new com.stripe.service.ForwardingService(this.getResponseGetter());
×
200
  }
201

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

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

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

214
  public com.stripe.service.InvoiceRenderingTemplateService invoiceRenderingTemplates() {
NEW
215
    return new com.stripe.service.InvoiceRenderingTemplateService(this.getResponseGetter());
×
216
  }
217

218
  public com.stripe.service.InvoiceService invoices() {
219
    return new com.stripe.service.InvoiceService(this.getResponseGetter());
1✔
220
  }
221

222
  public com.stripe.service.IssuingService issuing() {
223
    return new com.stripe.service.IssuingService(this.getResponseGetter());
1✔
224
  }
225

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

230
  public com.stripe.service.MarginService margins() {
231
    return new com.stripe.service.MarginService(this.getResponseGetter());
×
232
  }
233

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

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

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

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

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

254
  public com.stripe.service.PaymentMethodService paymentMethods() {
255
    return new com.stripe.service.PaymentMethodService(this.getResponseGetter());
1✔
256
  }
257

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

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

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

270
  public com.stripe.service.ProductService products() {
271
    return new com.stripe.service.ProductService(this.getResponseGetter());
1✔
272
  }
273

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

278
  public com.stripe.service.QuotePhaseService quotePhases() {
279
    return new com.stripe.service.QuotePhaseService(this.getResponseGetter());
×
280
  }
281

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

342
  public com.stripe.service.TaxIdService taxIds() {
343
    return new com.stripe.service.TaxIdService(this.getResponseGetter());
×
344
  }
345

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

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

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

358
  public com.stripe.service.TokenService tokens() {
359
    return new com.stripe.service.TokenService(this.getResponseGetter());
1✔
360
  }
361

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

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

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

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

378
  // The end of the section generated from our OpenAPI spec
379
  static class ClientStripeResponseGetterOptions extends StripeResponseGetterOptions {
380
    // When adding setting here keep them in sync with settings in RequestOptions and
381
    // in the RequestOptions.merge method
382
    @Getter(onMethod_ = {@Override})
383
    private final String apiKey;
384

385
    @Getter(onMethod_ = {@Override})
386
    private final String clientId;
387

388
    @Getter(onMethod_ = {@Override})
389
    private final int connectTimeout;
390

391
    @Getter(onMethod_ = {@Override})
392
    private final int readTimeout;
393

394
    @Getter(onMethod_ = {@Override})
395
    private final int maxNetworkRetries;
396

397
    @Getter(onMethod_ = {@Override})
398
    private final Proxy connectionProxy;
399

400
    @Getter(onMethod_ = {@Override})
401
    private final PasswordAuthentication proxyCredential;
402

403
    @Getter(onMethod_ = {@Override})
404
    private final String apiBase;
405

406
    @Getter(onMethod_ = {@Override})
407
    private final String filesBase;
408

409
    @Getter(onMethod_ = {@Override})
410
    private final String connectBase;
411

412
    ClientStripeResponseGetterOptions(
413
        String apiKey,
414
        String clientId,
415
        int connectTimeout,
416
        int readTimeout,
417
        int maxNetworkRetries,
418
        Proxy connectionProxy,
419
        PasswordAuthentication proxyCredential,
420
        String apiBase,
421
        String filesBase,
422
        String connectBase) {
1✔
423
      this.apiKey = apiKey;
1✔
424
      this.clientId = clientId;
1✔
425
      this.connectTimeout = connectTimeout;
1✔
426
      this.readTimeout = readTimeout;
1✔
427
      this.maxNetworkRetries = maxNetworkRetries;
1✔
428
      this.connectionProxy = connectionProxy;
1✔
429
      this.proxyCredential = proxyCredential;
1✔
430
      this.apiBase = apiBase;
1✔
431
      this.filesBase = filesBase;
1✔
432
      this.connectBase = connectBase;
1✔
433
    }
1✔
434
  }
435

436
  /**
437
   * Builder class for creating a {@link StripeClient} instance. Allows you to specify settings like
438
   * the API key, connect and read timeouts, and proxy settings.
439
   */
440
  public static StripeClientBuilder builder() {
441
    return new StripeClientBuilder();
1✔
442
  }
443

444
  public static final class StripeClientBuilder {
445
    private String apiKey;
446
    private String clientId;
447
    private int connectTimeout = Stripe.DEFAULT_CONNECT_TIMEOUT;
1✔
448
    private int readTimeout = Stripe.DEFAULT_READ_TIMEOUT;
1✔
449
    private int maxNetworkRetries;
450
    private Proxy connectionProxy;
451
    private PasswordAuthentication proxyCredential;
452
    private String apiBase = Stripe.LIVE_API_BASE;
1✔
453
    private String filesBase = Stripe.UPLOAD_API_BASE;
1✔
454
    private String connectBase = Stripe.CONNECT_API_BASE;
1✔
455

456
    /**
457
     * Constructs a request options builder with the global parameters (API key and client ID) as
458
     * default values.
459
     */
460
    public StripeClientBuilder() {}
1✔
461

462
    public String getApiKey() {
463
      return this.apiKey;
×
464
    }
465

466
    /**
467
     * Set API key to use for authenticating requests.
468
     *
469
     * @param apiKey API key
470
     */
471
    public StripeClientBuilder setApiKey(String apiKey) {
472
      this.apiKey = apiKey;
1✔
473
      return this;
1✔
474
    }
475

476
    public String getClientId() {
477
      return clientId;
×
478
    }
479

480
    /**
481
     * Set the client id, used for OAuth with Stripe Connect.
482
     *
483
     * @param clientId client ID
484
     */
485
    public StripeClientBuilder setClientId(String clientId) {
486
      this.clientId = clientId;
×
487
      return this;
×
488
    }
489

490
    public int getConnectTimeout() {
491
      return connectTimeout;
×
492
    }
493

494
    /**
495
     * Sets the timeout value that will be used for making new connections to the Stripe API (in
496
     * milliseconds).
497
     *
498
     * @param timeout timeout value in milliseconds
499
     */
500
    public StripeClientBuilder setConnectTimeout(int timeout) {
501
      this.connectTimeout = timeout;
×
502
      return this;
×
503
    }
504

505
    public int getReadTimeout() {
506
      return readTimeout;
×
507
    }
508

509
    /**
510
     * Sets the timeout value that will be used when reading data from an established connection to
511
     * the Stripe API (in milliseconds).
512
     *
513
     * <p>Note that this value should be set conservatively because some API requests can take time
514
     * and a short timeout increases the likelihood of causing a problem in the backend.
515
     *
516
     * @param timeout timeout value in milliseconds
517
     */
518
    public StripeClientBuilder setReadTimeout(int timeout) {
519
      this.readTimeout = timeout;
×
520
      return this;
×
521
    }
522

523
    public int getMaxNetworkRetries() {
524
      return maxNetworkRetries;
×
525
    }
526

527
    /**
528
     * Sets the maximum number of times the request will be retried in the event of a failure.
529
     *
530
     * @param maxNetworkRetries the number of times to retry the request
531
     */
532
    public StripeClientBuilder setMaxNetworkRetries(int maxNetworkRetries) {
533
      this.maxNetworkRetries = maxNetworkRetries;
×
534
      return this;
×
535
    }
536

537
    public Proxy getConnectionProxy() {
538
      return connectionProxy;
×
539
    }
540

541
    /**
542
     * Set proxy to tunnel all Stripe connections.
543
     *
544
     * @param connectionProxy proxy host and port setting
545
     */
546
    public StripeClientBuilder setConnectionProxy(Proxy connectionProxy) {
547
      this.connectionProxy = connectionProxy;
×
548
      return this;
×
549
    }
550

551
    public PasswordAuthentication getProxyCredential() {
552
      return proxyCredential;
×
553
    }
554

555
    /**
556
     * Provide credential for proxy authorization if required.
557
     *
558
     * @param proxyCredential proxy required userName and password
559
     */
560
    public StripeClientBuilder setProxyCredential(PasswordAuthentication proxyCredential) {
561
      this.proxyCredential = proxyCredential;
×
562
      return this;
×
563
    }
564

565
    /**
566
     * Set the base URL for the Stripe API. By default this is "https://api.stripe.com".
567
     *
568
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of API. Use
569
     * {@link setFilesBase} or {@link setConnectBase} to interpect requests with other bases.
570
     */
571
    public StripeClientBuilder setApiBase(String address) {
572
      this.apiBase = address;
1✔
573
      return this;
1✔
574
    }
575

576
    public String getApiBase() {
577
      return this.apiBase;
×
578
    }
579

580
    /**
581
     * Set the base URL for the Stripe Files API. By default this is "https://files.stripe.com".
582
     *
583
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of FILES.
584
     */
585
    public StripeClientBuilder setFilesBase(String address) {
586
      this.filesBase = address;
×
587
      return this;
×
588
    }
589

590
    public String getFilesBase() {
591
      return this.filesBase;
×
592
    }
593

594
    /**
595
     * Set the base URL for the Stripe Connect API. By default this is "https://connect.stripe.com".
596
     *
597
     * <p>This only affects requests made with a {@link com.stripe.net.BaseAddress} of CONNECT.
598
     */
599
    public StripeClientBuilder setConnectBase(String address) {
600
      this.connectBase = address;
×
601
      return this;
×
602
    }
603

604
    public String getConnectBase() {
605
      return this.connectBase;
×
606
    }
607

608
    /** Constructs a {@link StripeClient} with the specified configuration. */
609
    public StripeClient build() {
610
      return new StripeClient(new LiveStripeResponseGetter(buildOptions(), null));
×
611
    }
612

613
    StripeResponseGetterOptions buildOptions() {
614
      if (this.apiKey == null) {
1✔
615
        throw new IllegalArgumentException(
×
616
            "No API key provided. Use setApiKey to set the Stripe API key");
617
      }
618
      return new ClientStripeResponseGetterOptions(
1✔
619
          this.apiKey,
620
          this.clientId,
621
          connectTimeout,
622
          readTimeout,
623
          maxNetworkRetries,
624
          connectionProxy,
625
          proxyCredential,
626
          apiBase,
627
          filesBase,
628
          connectBase);
629
    }
630
  }
631

632
  /**
633
   * Send raw request to Stripe API. This is the lowest level method for interacting with the Stripe
634
   * API. This method is useful for interacting with endpoints that are not covered yet in
635
   * stripe-java.
636
   *
637
   * @param method the HTTP method
638
   * @param relativeUrl the relative URL of the request, e.g. "/v1/charges"
639
   * @param content the body of the request as a string
640
   * @return the JSON response as a string
641
   */
642
  public StripeResponse rawRequest(
643
      final ApiResource.RequestMethod method, final String relativeUrl, final String content)
644
      throws StripeException {
645
    return rawRequest(method, relativeUrl, content, null);
×
646
  }
647

648
  /**
649
   * Send raw request to Stripe API. This is the lowest level method for interacting with the Stripe
650
   * API. This method is useful for interacting with endpoints that are not covered yet in
651
   * stripe-java.
652
   *
653
   * @param method the HTTP method
654
   * @param relativeUrl the relative URL of the request, e.g. "/v1/charges"
655
   * @param content the body of the request as a string
656
   * @param options the special modifiers of the request
657
   * @return the JSON response as a string
658
   */
659
  public StripeResponse rawRequest(
660
      final ApiResource.RequestMethod method,
661
      final String relativeUrl,
662
      final String content,
663
      RawRequestOptions options)
664
      throws StripeException {
665
    if (options == null) {
1✔
666
      options = RawRequestOptions.builder().build();
1✔
667
    }
668
    if (method != ApiResource.RequestMethod.POST && content != null && !content.equals("")) {
1✔
669
      throw new IllegalArgumentException(
1✔
670
          "content is not allowed for non-POST requests. Please pass null and add request parameters to the query string of the URL.");
671
    }
672
    RawApiRequest req = new RawApiRequest(BaseAddress.API, method, relativeUrl, content, options);
1✔
673
    req = req.addUsage("stripe_client");
1✔
674
    req = req.addUsage("raw_request");
1✔
675
    return this.getResponseGetter().rawRequest(req);
1✔
676
  }
677

678
  /** Deserializes StripeResponse returned by rawRequest into a similar class. */
679
  public StripeObject deserialize(String rawJson) throws StripeException {
680
    return StripeObject.deserializeStripeObject(rawJson, this.getResponseGetter());
1✔
681
  }
682
}
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