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

stripe / stripe-java / #16380

30 Aug 2024 07:54PM UTC coverage: 12.882% (-0.004%) from 12.886%
#16380

push

github

web-flow
Merge from master after the changes to not pass api_mode from individual methods (#1857)

* Generate SDK for OpenAPI spec version 1230 (#1856)

* Bump version to 26.9.0

* No need for APIMode to be passed around from individual API methods (#1855)

* Generated code

* Update the code around raw request

* Update the v2 tests to use v2 path

16 of 23 new or added lines in 7 files covered. (69.57%)

706 existing lines in 213 files now uncovered.

18468 of 143365 relevant lines covered (12.88%)

0.13 hits per line

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

73.68
/src/main/java/com/stripe/service/SubscriptionService.java
1
// File generated from our OpenAPI spec
2
package com.stripe.service;
3

4
import com.google.gson.reflect.TypeToken;
5
import com.stripe.exception.StripeException;
6
import com.stripe.model.Discount;
7
import com.stripe.model.StripeCollection;
8
import com.stripe.model.StripeSearchResult;
9
import com.stripe.model.Subscription;
10
import com.stripe.net.ApiRequest;
11
import com.stripe.net.ApiRequestParams;
12
import com.stripe.net.ApiResource;
13
import com.stripe.net.ApiService;
14
import com.stripe.net.BaseAddress;
15
import com.stripe.net.RequestOptions;
16
import com.stripe.net.StripeResponseGetter;
17
import com.stripe.param.SubscriptionCancelParams;
18
import com.stripe.param.SubscriptionCreateParams;
19
import com.stripe.param.SubscriptionListParams;
20
import com.stripe.param.SubscriptionResumeParams;
21
import com.stripe.param.SubscriptionRetrieveParams;
22
import com.stripe.param.SubscriptionSearchParams;
23
import com.stripe.param.SubscriptionUpdateParams;
24

25
public final class SubscriptionService extends ApiService {
26
  public SubscriptionService(StripeResponseGetter responseGetter) {
27
    super(responseGetter);
1✔
28
  }
1✔
29

30
  /**
31
   * Cancels a customer’s subscription immediately. The customer will not be charged again for the
32
   * subscription.
33
   *
34
   * <p>Note, however, that any pending invoice items that you’ve created will still be charged for
35
   * at the end of the period, unless manually <a
36
   * href="https://stripe.com/docs/api#delete_invoiceitem">deleted</a>. If you’ve set the
37
   * subscription to cancel at the end of the period, any pending prorations will also be left in
38
   * place and collected at the end of the period. But if the subscription is set to cancel
39
   * immediately, pending prorations will be removed.
40
   *
41
   * <p>By default, upon subscription cancellation, Stripe will stop automatic collection of all
42
   * finalized invoices for the customer. This is intended to prevent unexpected payment attempts
43
   * after the customer has canceled a subscription. However, you can resume automatic collection of
44
   * the invoices manually after subscription cancellation to have us proceed. Or, you could check
45
   * for unpaid invoices before allowing the customer to cancel the subscription at all.
46
   */
47
  public Subscription cancel(String subscriptionExposedId, SubscriptionCancelParams params)
48
      throws StripeException {
49
    return cancel(subscriptionExposedId, params, (RequestOptions) null);
1✔
50
  }
51
  /**
52
   * Cancels a customer’s subscription immediately. The customer will not be charged again for the
53
   * subscription.
54
   *
55
   * <p>Note, however, that any pending invoice items that you’ve created will still be charged for
56
   * at the end of the period, unless manually <a
57
   * href="https://stripe.com/docs/api#delete_invoiceitem">deleted</a>. If you’ve set the
58
   * subscription to cancel at the end of the period, any pending prorations will also be left in
59
   * place and collected at the end of the period. But if the subscription is set to cancel
60
   * immediately, pending prorations will be removed.
61
   *
62
   * <p>By default, upon subscription cancellation, Stripe will stop automatic collection of all
63
   * finalized invoices for the customer. This is intended to prevent unexpected payment attempts
64
   * after the customer has canceled a subscription. However, you can resume automatic collection of
65
   * the invoices manually after subscription cancellation to have us proceed. Or, you could check
66
   * for unpaid invoices before allowing the customer to cancel the subscription at all.
67
   */
68
  public Subscription cancel(String subscriptionExposedId, RequestOptions options)
69
      throws StripeException {
70
    return cancel(subscriptionExposedId, (SubscriptionCancelParams) null, options);
×
71
  }
72
  /**
73
   * Cancels a customer’s subscription immediately. The customer will not be charged again for the
74
   * subscription.
75
   *
76
   * <p>Note, however, that any pending invoice items that you’ve created will still be charged for
77
   * at the end of the period, unless manually <a
78
   * href="https://stripe.com/docs/api#delete_invoiceitem">deleted</a>. If you’ve set the
79
   * subscription to cancel at the end of the period, any pending prorations will also be left in
80
   * place and collected at the end of the period. But if the subscription is set to cancel
81
   * immediately, pending prorations will be removed.
82
   *
83
   * <p>By default, upon subscription cancellation, Stripe will stop automatic collection of all
84
   * finalized invoices for the customer. This is intended to prevent unexpected payment attempts
85
   * after the customer has canceled a subscription. However, you can resume automatic collection of
86
   * the invoices manually after subscription cancellation to have us proceed. Or, you could check
87
   * for unpaid invoices before allowing the customer to cancel the subscription at all.
88
   */
89
  public Subscription cancel(String subscriptionExposedId) throws StripeException {
90
    return cancel(subscriptionExposedId, (SubscriptionCancelParams) null, (RequestOptions) null);
×
91
  }
92
  /**
93
   * Cancels a customer’s subscription immediately. The customer will not be charged again for the
94
   * subscription.
95
   *
96
   * <p>Note, however, that any pending invoice items that you’ve created will still be charged for
97
   * at the end of the period, unless manually <a
98
   * href="https://stripe.com/docs/api#delete_invoiceitem">deleted</a>. If you’ve set the
99
   * subscription to cancel at the end of the period, any pending prorations will also be left in
100
   * place and collected at the end of the period. But if the subscription is set to cancel
101
   * immediately, pending prorations will be removed.
102
   *
103
   * <p>By default, upon subscription cancellation, Stripe will stop automatic collection of all
104
   * finalized invoices for the customer. This is intended to prevent unexpected payment attempts
105
   * after the customer has canceled a subscription. However, you can resume automatic collection of
106
   * the invoices manually after subscription cancellation to have us proceed. Or, you could check
107
   * for unpaid invoices before allowing the customer to cancel the subscription at all.
108
   */
109
  public Subscription cancel(
110
      String subscriptionExposedId, SubscriptionCancelParams params, RequestOptions options)
111
      throws StripeException {
112
    String path =
1✔
113
        String.format("/v1/subscriptions/%s", ApiResource.urlEncodeId(subscriptionExposedId));
1✔
114
    ApiRequest request =
1✔
115
        new ApiRequest(
116
            BaseAddress.API,
117
            ApiResource.RequestMethod.DELETE,
118
            path,
119
            ApiRequestParams.paramsToMap(params),
1✔
120
            options);
121
    return this.request(request, Subscription.class);
1✔
122
  }
123
  /** Retrieves the subscription with the given ID. */
124
  public Subscription retrieve(String subscriptionExposedId, SubscriptionRetrieveParams params)
125
      throws StripeException {
126
    return retrieve(subscriptionExposedId, params, (RequestOptions) null);
1✔
127
  }
128
  /** Retrieves the subscription with the given ID. */
129
  public Subscription retrieve(String subscriptionExposedId, RequestOptions options)
130
      throws StripeException {
131
    return retrieve(subscriptionExposedId, (SubscriptionRetrieveParams) null, options);
×
132
  }
133
  /** Retrieves the subscription with the given ID. */
134
  public Subscription retrieve(String subscriptionExposedId) throws StripeException {
135
    return retrieve(
×
136
        subscriptionExposedId, (SubscriptionRetrieveParams) null, (RequestOptions) null);
137
  }
138
  /** Retrieves the subscription with the given ID. */
139
  public Subscription retrieve(
140
      String subscriptionExposedId, SubscriptionRetrieveParams params, RequestOptions options)
141
      throws StripeException {
142
    String path =
1✔
143
        String.format("/v1/subscriptions/%s", ApiResource.urlEncodeId(subscriptionExposedId));
1✔
144
    ApiRequest request =
1✔
145
        new ApiRequest(
146
            BaseAddress.API,
147
            ApiResource.RequestMethod.GET,
148
            path,
149
            ApiRequestParams.paramsToMap(params),
1✔
150
            options);
151
    return this.request(request, Subscription.class);
1✔
152
  }
153
  /**
154
   * Updates an existing subscription to match the specified parameters. When changing prices or
155
   * quantities, we optionally prorate the price we charge next month to make up for any price
156
   * changes. To preview how the proration is calculated, use the <a
157
   * href="https://stripe.com/docs/api/invoices/create_preview">create preview</a> endpoint.
158
   *
159
   * <p>By default, we prorate subscription changes. For example, if a customer signs up on May 1
160
   * for a 100 price, they’ll be billed 100 immediately. If on May 15 they switch to a 200 price,
161
   * then on June 1 they’ll be billed 250 (200 for a renewal of her subscription, plus a 50
162
   * prorating adjustment for half of the previous month’s 100 difference). Similarly, a downgrade
163
   * generates a credit that is applied to the next invoice. We also prorate when you make quantity
164
   * changes.
165
   *
166
   * <p>Switching prices does not normally change the billing date or generate an immediate charge
167
   * unless:
168
   *
169
   * <p>
170
   *
171
   * <ul>
172
   *   <li>The billing interval is changed (for example, from monthly to yearly).
173
   *   <li>The subscription moves from free to paid.
174
   *   <li>A trial starts or ends.
175
   * </ul>
176
   *
177
   * <p>In these cases, we apply a credit for the unused time on the previous price, immediately
178
   * charge the customer using the new price, and reset the billing date. Learn about how <a
179
   * href="https://stripe.com/billing/subscriptions/upgrade-downgrade#immediate-payment">Stripe
180
   * immediately attempts payment for subscription changes</a>.
181
   *
182
   * <p>If you want to charge for an upgrade immediately, pass {@code proration_behavior} as {@code
183
   * always_invoice} to create prorations, automatically invoice the customer for those proration
184
   * adjustments, and attempt to collect payment. If you pass {@code create_prorations}, the
185
   * prorations are created but not automatically invoiced. If you want to bill the customer for the
186
   * prorations before the subscription’s renewal date, you need to manually <a
187
   * href="https://stripe.com/docs/api/invoices/create">invoice the customer</a>.
188
   *
189
   * <p>If you don’t want to prorate, set the {@code proration_behavior} option to {@code none}.
190
   * With this option, the customer is billed 100 on May 1 and 200 on June 1. Similarly, if you set
191
   * {@code proration_behavior} to {@code none} when switching between different billing intervals
192
   * (for example, from monthly to yearly), we don’t generate any credits for the old subscription’s
193
   * unused time. We still reset the billing date and bill immediately for the new subscription.
194
   *
195
   * <p>Updating the quantity on a subscription many times in an hour may result in <a
196
   * href="https://stripe.com/docs/rate-limits">rate limiting</a>. If you need to bill for a
197
   * frequently changing quantity, consider integrating <a
198
   * href="https://stripe.com/docs/billing/subscriptions/usage-based">usage-based billing</a>
199
   * instead.
200
   */
201
  public Subscription update(String subscriptionExposedId, SubscriptionUpdateParams params)
202
      throws StripeException {
203
    return update(subscriptionExposedId, params, (RequestOptions) null);
1✔
204
  }
205
  /**
206
   * Updates an existing subscription to match the specified parameters. When changing prices or
207
   * quantities, we optionally prorate the price we charge next month to make up for any price
208
   * changes. To preview how the proration is calculated, use the <a
209
   * href="https://stripe.com/docs/api/invoices/create_preview">create preview</a> endpoint.
210
   *
211
   * <p>By default, we prorate subscription changes. For example, if a customer signs up on May 1
212
   * for a 100 price, they’ll be billed 100 immediately. If on May 15 they switch to a 200 price,
213
   * then on June 1 they’ll be billed 250 (200 for a renewal of her subscription, plus a 50
214
   * prorating adjustment for half of the previous month’s 100 difference). Similarly, a downgrade
215
   * generates a credit that is applied to the next invoice. We also prorate when you make quantity
216
   * changes.
217
   *
218
   * <p>Switching prices does not normally change the billing date or generate an immediate charge
219
   * unless:
220
   *
221
   * <p>
222
   *
223
   * <ul>
224
   *   <li>The billing interval is changed (for example, from monthly to yearly).
225
   *   <li>The subscription moves from free to paid.
226
   *   <li>A trial starts or ends.
227
   * </ul>
228
   *
229
   * <p>In these cases, we apply a credit for the unused time on the previous price, immediately
230
   * charge the customer using the new price, and reset the billing date. Learn about how <a
231
   * href="https://stripe.com/billing/subscriptions/upgrade-downgrade#immediate-payment">Stripe
232
   * immediately attempts payment for subscription changes</a>.
233
   *
234
   * <p>If you want to charge for an upgrade immediately, pass {@code proration_behavior} as {@code
235
   * always_invoice} to create prorations, automatically invoice the customer for those proration
236
   * adjustments, and attempt to collect payment. If you pass {@code create_prorations}, the
237
   * prorations are created but not automatically invoiced. If you want to bill the customer for the
238
   * prorations before the subscription’s renewal date, you need to manually <a
239
   * href="https://stripe.com/docs/api/invoices/create">invoice the customer</a>.
240
   *
241
   * <p>If you don’t want to prorate, set the {@code proration_behavior} option to {@code none}.
242
   * With this option, the customer is billed 100 on May 1 and 200 on June 1. Similarly, if you set
243
   * {@code proration_behavior} to {@code none} when switching between different billing intervals
244
   * (for example, from monthly to yearly), we don’t generate any credits for the old subscription’s
245
   * unused time. We still reset the billing date and bill immediately for the new subscription.
246
   *
247
   * <p>Updating the quantity on a subscription many times in an hour may result in <a
248
   * href="https://stripe.com/docs/rate-limits">rate limiting</a>. If you need to bill for a
249
   * frequently changing quantity, consider integrating <a
250
   * href="https://stripe.com/docs/billing/subscriptions/usage-based">usage-based billing</a>
251
   * instead.
252
   */
253
  public Subscription update(String subscriptionExposedId, RequestOptions options)
254
      throws StripeException {
255
    return update(subscriptionExposedId, (SubscriptionUpdateParams) null, options);
×
256
  }
257
  /**
258
   * Updates an existing subscription to match the specified parameters. When changing prices or
259
   * quantities, we optionally prorate the price we charge next month to make up for any price
260
   * changes. To preview how the proration is calculated, use the <a
261
   * href="https://stripe.com/docs/api/invoices/create_preview">create preview</a> endpoint.
262
   *
263
   * <p>By default, we prorate subscription changes. For example, if a customer signs up on May 1
264
   * for a 100 price, they’ll be billed 100 immediately. If on May 15 they switch to a 200 price,
265
   * then on June 1 they’ll be billed 250 (200 for a renewal of her subscription, plus a 50
266
   * prorating adjustment for half of the previous month’s 100 difference). Similarly, a downgrade
267
   * generates a credit that is applied to the next invoice. We also prorate when you make quantity
268
   * changes.
269
   *
270
   * <p>Switching prices does not normally change the billing date or generate an immediate charge
271
   * unless:
272
   *
273
   * <p>
274
   *
275
   * <ul>
276
   *   <li>The billing interval is changed (for example, from monthly to yearly).
277
   *   <li>The subscription moves from free to paid.
278
   *   <li>A trial starts or ends.
279
   * </ul>
280
   *
281
   * <p>In these cases, we apply a credit for the unused time on the previous price, immediately
282
   * charge the customer using the new price, and reset the billing date. Learn about how <a
283
   * href="https://stripe.com/billing/subscriptions/upgrade-downgrade#immediate-payment">Stripe
284
   * immediately attempts payment for subscription changes</a>.
285
   *
286
   * <p>If you want to charge for an upgrade immediately, pass {@code proration_behavior} as {@code
287
   * always_invoice} to create prorations, automatically invoice the customer for those proration
288
   * adjustments, and attempt to collect payment. If you pass {@code create_prorations}, the
289
   * prorations are created but not automatically invoiced. If you want to bill the customer for the
290
   * prorations before the subscription’s renewal date, you need to manually <a
291
   * href="https://stripe.com/docs/api/invoices/create">invoice the customer</a>.
292
   *
293
   * <p>If you don’t want to prorate, set the {@code proration_behavior} option to {@code none}.
294
   * With this option, the customer is billed 100 on May 1 and 200 on June 1. Similarly, if you set
295
   * {@code proration_behavior} to {@code none} when switching between different billing intervals
296
   * (for example, from monthly to yearly), we don’t generate any credits for the old subscription’s
297
   * unused time. We still reset the billing date and bill immediately for the new subscription.
298
   *
299
   * <p>Updating the quantity on a subscription many times in an hour may result in <a
300
   * href="https://stripe.com/docs/rate-limits">rate limiting</a>. If you need to bill for a
301
   * frequently changing quantity, consider integrating <a
302
   * href="https://stripe.com/docs/billing/subscriptions/usage-based">usage-based billing</a>
303
   * instead.
304
   */
305
  public Subscription update(String subscriptionExposedId) throws StripeException {
306
    return update(subscriptionExposedId, (SubscriptionUpdateParams) null, (RequestOptions) null);
×
307
  }
308
  /**
309
   * Updates an existing subscription to match the specified parameters. When changing prices or
310
   * quantities, we optionally prorate the price we charge next month to make up for any price
311
   * changes. To preview how the proration is calculated, use the <a
312
   * href="https://stripe.com/docs/api/invoices/create_preview">create preview</a> endpoint.
313
   *
314
   * <p>By default, we prorate subscription changes. For example, if a customer signs up on May 1
315
   * for a 100 price, they’ll be billed 100 immediately. If on May 15 they switch to a 200 price,
316
   * then on June 1 they’ll be billed 250 (200 for a renewal of her subscription, plus a 50
317
   * prorating adjustment for half of the previous month’s 100 difference). Similarly, a downgrade
318
   * generates a credit that is applied to the next invoice. We also prorate when you make quantity
319
   * changes.
320
   *
321
   * <p>Switching prices does not normally change the billing date or generate an immediate charge
322
   * unless:
323
   *
324
   * <p>
325
   *
326
   * <ul>
327
   *   <li>The billing interval is changed (for example, from monthly to yearly).
328
   *   <li>The subscription moves from free to paid.
329
   *   <li>A trial starts or ends.
330
   * </ul>
331
   *
332
   * <p>In these cases, we apply a credit for the unused time on the previous price, immediately
333
   * charge the customer using the new price, and reset the billing date. Learn about how <a
334
   * href="https://stripe.com/billing/subscriptions/upgrade-downgrade#immediate-payment">Stripe
335
   * immediately attempts payment for subscription changes</a>.
336
   *
337
   * <p>If you want to charge for an upgrade immediately, pass {@code proration_behavior} as {@code
338
   * always_invoice} to create prorations, automatically invoice the customer for those proration
339
   * adjustments, and attempt to collect payment. If you pass {@code create_prorations}, the
340
   * prorations are created but not automatically invoiced. If you want to bill the customer for the
341
   * prorations before the subscription’s renewal date, you need to manually <a
342
   * href="https://stripe.com/docs/api/invoices/create">invoice the customer</a>.
343
   *
344
   * <p>If you don’t want to prorate, set the {@code proration_behavior} option to {@code none}.
345
   * With this option, the customer is billed 100 on May 1 and 200 on June 1. Similarly, if you set
346
   * {@code proration_behavior} to {@code none} when switching between different billing intervals
347
   * (for example, from monthly to yearly), we don’t generate any credits for the old subscription’s
348
   * unused time. We still reset the billing date and bill immediately for the new subscription.
349
   *
350
   * <p>Updating the quantity on a subscription many times in an hour may result in <a
351
   * href="https://stripe.com/docs/rate-limits">rate limiting</a>. If you need to bill for a
352
   * frequently changing quantity, consider integrating <a
353
   * href="https://stripe.com/docs/billing/subscriptions/usage-based">usage-based billing</a>
354
   * instead.
355
   */
356
  public Subscription update(
357
      String subscriptionExposedId, SubscriptionUpdateParams params, RequestOptions options)
358
      throws StripeException {
359
    String path =
1✔
360
        String.format("/v1/subscriptions/%s", ApiResource.urlEncodeId(subscriptionExposedId));
1✔
361
    ApiRequest request =
1✔
362
        new ApiRequest(
363
            BaseAddress.API,
364
            ApiResource.RequestMethod.POST,
365
            path,
366
            ApiRequestParams.paramsToMap(params),
1✔
367
            options);
368
    return this.request(request, Subscription.class);
1✔
369
  }
370
  /** Removes the currently applied discount on a subscription. */
371
  public Discount deleteDiscount(String subscriptionExposedId) throws StripeException {
372
    return deleteDiscount(subscriptionExposedId, (RequestOptions) null);
1✔
373
  }
374
  /** Removes the currently applied discount on a subscription. */
375
  public Discount deleteDiscount(String subscriptionExposedId, RequestOptions options)
376
      throws StripeException {
377
    String path =
1✔
378
        String.format(
1✔
379
            "/v1/subscriptions/%s/discount", ApiResource.urlEncodeId(subscriptionExposedId));
1✔
380
    ApiRequest request =
1✔
381
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.DELETE, path, null, options);
382
    return this.request(request, Discount.class);
1✔
383
  }
384
  /**
385
   * By default, returns a list of subscriptions that have not been canceled. In order to list
386
   * canceled subscriptions, specify {@code status=canceled}.
387
   */
388
  public StripeCollection<Subscription> list(SubscriptionListParams params) throws StripeException {
389
    return list(params, (RequestOptions) null);
1✔
390
  }
391
  /**
392
   * By default, returns a list of subscriptions that have not been canceled. In order to list
393
   * canceled subscriptions, specify {@code status=canceled}.
394
   */
395
  public StripeCollection<Subscription> list(RequestOptions options) throws StripeException {
396
    return list((SubscriptionListParams) null, options);
×
397
  }
398
  /**
399
   * By default, returns a list of subscriptions that have not been canceled. In order to list
400
   * canceled subscriptions, specify {@code status=canceled}.
401
   */
402
  public StripeCollection<Subscription> list() throws StripeException {
403
    return list((SubscriptionListParams) null, (RequestOptions) null);
1✔
404
  }
405
  /**
406
   * By default, returns a list of subscriptions that have not been canceled. In order to list
407
   * canceled subscriptions, specify {@code status=canceled}.
408
   */
409
  public StripeCollection<Subscription> list(SubscriptionListParams params, RequestOptions options)
410
      throws StripeException {
411
    String path = "/v1/subscriptions";
1✔
412
    ApiRequest request =
1✔
413
        new ApiRequest(
414
            BaseAddress.API,
415
            ApiResource.RequestMethod.GET,
416
            path,
417
            ApiRequestParams.paramsToMap(params),
1✔
418
            options);
419
    return this.request(request, new TypeToken<StripeCollection<Subscription>>() {}.getType());
1✔
420
  }
421
  /**
422
   * Creates a new subscription on an existing customer. Each customer can have up to 500 active or
423
   * scheduled subscriptions.
424
   *
425
   * <p>When you create a subscription with {@code collection_method=charge_automatically}, the
426
   * first invoice is finalized as part of the request. The {@code payment_behavior} parameter
427
   * determines the exact behavior of the initial payment.
428
   *
429
   * <p>To start subscriptions where the first invoice always begins in a {@code draft} status, use
430
   * <a
431
   * href="https://stripe.com/docs/billing/subscriptions/subscription-schedules#managing">subscription
432
   * schedules</a> instead. Schedules provide the flexibility to model more complex billing
433
   * configurations that change over time.
434
   */
435
  public Subscription create(SubscriptionCreateParams params) throws StripeException {
436
    return create(params, (RequestOptions) null);
1✔
437
  }
438
  /**
439
   * Creates a new subscription on an existing customer. Each customer can have up to 500 active or
440
   * scheduled subscriptions.
441
   *
442
   * <p>When you create a subscription with {@code collection_method=charge_automatically}, the
443
   * first invoice is finalized as part of the request. The {@code payment_behavior} parameter
444
   * determines the exact behavior of the initial payment.
445
   *
446
   * <p>To start subscriptions where the first invoice always begins in a {@code draft} status, use
447
   * <a
448
   * href="https://stripe.com/docs/billing/subscriptions/subscription-schedules#managing">subscription
449
   * schedules</a> instead. Schedules provide the flexibility to model more complex billing
450
   * configurations that change over time.
451
   */
452
  public Subscription create(SubscriptionCreateParams params, RequestOptions options)
453
      throws StripeException {
454
    String path = "/v1/subscriptions";
1✔
455
    ApiRequest request =
1✔
456
        new ApiRequest(
457
            BaseAddress.API,
458
            ApiResource.RequestMethod.POST,
459
            path,
460
            ApiRequestParams.paramsToMap(params),
1✔
461
            options);
462
    return this.request(request, Subscription.class);
1✔
463
  }
464
  /**
465
   * Search for subscriptions you’ve previously created using Stripe’s <a
466
   * href="https://stripe.com/docs/search#search-query-language">Search Query Language</a>. Don’t
467
   * use search in read-after-write flows where strict consistency is necessary. Under normal
468
   * operating conditions, data is searchable in less than a minute. Occasionally, propagation of
469
   * new or updated data can be up to an hour behind during outages. Search functionality is not
470
   * available to merchants in India.
471
   */
472
  public StripeSearchResult<Subscription> search(SubscriptionSearchParams params)
473
      throws StripeException {
474
    return search(params, (RequestOptions) null);
1✔
475
  }
476
  /**
477
   * Search for subscriptions you’ve previously created using Stripe’s <a
478
   * href="https://stripe.com/docs/search#search-query-language">Search Query Language</a>. Don’t
479
   * use search in read-after-write flows where strict consistency is necessary. Under normal
480
   * operating conditions, data is searchable in less than a minute. Occasionally, propagation of
481
   * new or updated data can be up to an hour behind during outages. Search functionality is not
482
   * available to merchants in India.
483
   */
484
  public StripeSearchResult<Subscription> search(
485
      SubscriptionSearchParams params, RequestOptions options) throws StripeException {
486
    String path = "/v1/subscriptions/search";
1✔
487
    ApiRequest request =
1✔
488
        new ApiRequest(
489
            BaseAddress.API,
490
            ApiResource.RequestMethod.GET,
491
            path,
492
            ApiRequestParams.paramsToMap(params),
1✔
493
            options);
494
    return this.request(request, new TypeToken<StripeSearchResult<Subscription>>() {}.getType());
1✔
495
  }
496
  /**
497
   * Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor
498
   * and creating prorations. If a resumption invoice is generated, it must be paid or marked
499
   * uncollectible before the subscription will be unpaused. If payment succeeds the subscription
500
   * will become {@code active}, and if payment fails the subscription will be {@code past_due}. The
501
   * resumption invoice will void automatically if not paid by the expiration date.
502
   */
503
  public Subscription resume(String subscription, SubscriptionResumeParams params)
504
      throws StripeException {
505
    return resume(subscription, params, (RequestOptions) null);
×
506
  }
507
  /**
508
   * Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor
509
   * and creating prorations. If a resumption invoice is generated, it must be paid or marked
510
   * uncollectible before the subscription will be unpaused. If payment succeeds the subscription
511
   * will become {@code active}, and if payment fails the subscription will be {@code past_due}. The
512
   * resumption invoice will void automatically if not paid by the expiration date.
513
   */
514
  public Subscription resume(String subscription, RequestOptions options) throws StripeException {
515
    return resume(subscription, (SubscriptionResumeParams) null, options);
×
516
  }
517
  /**
518
   * Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor
519
   * and creating prorations. If a resumption invoice is generated, it must be paid or marked
520
   * uncollectible before the subscription will be unpaused. If payment succeeds the subscription
521
   * will become {@code active}, and if payment fails the subscription will be {@code past_due}. The
522
   * resumption invoice will void automatically if not paid by the expiration date.
523
   */
524
  public Subscription resume(String subscription) throws StripeException {
525
    return resume(subscription, (SubscriptionResumeParams) null, (RequestOptions) null);
×
526
  }
527
  /**
528
   * Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor
529
   * and creating prorations. If a resumption invoice is generated, it must be paid or marked
530
   * uncollectible before the subscription will be unpaused. If payment succeeds the subscription
531
   * will become {@code active}, and if payment fails the subscription will be {@code past_due}. The
532
   * resumption invoice will void automatically if not paid by the expiration date.
533
   */
534
  public Subscription resume(
535
      String subscription, SubscriptionResumeParams params, RequestOptions options)
536
      throws StripeException {
537
    String path =
×
538
        String.format("/v1/subscriptions/%s/resume", ApiResource.urlEncodeId(subscription));
×
539
    ApiRequest request =
×
540
        new ApiRequest(
541
            BaseAddress.API,
542
            ApiResource.RequestMethod.POST,
543
            path,
544
            ApiRequestParams.paramsToMap(params),
×
545
            options);
UNCOV
546
    return this.request(request, Subscription.class);
×
547
  }
548
}
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