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

stripe / stripe-java / #14623

pending completion
#14623

Pull #1596

github-actions

web-flow
Merge 2db1cc836 into 0adfd1352
Pull Request #1596: Add StripeClient

10149 of 10149 new or added lines in 282 files covered. (100.0%)

14798 of 78436 relevant lines covered (18.87%)

0.19 hits per line

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

76.27
/src/main/java/com/stripe/model/Plan.java
1
// File generated from our OpenAPI spec
2
package com.stripe.model;
3

4
import com.google.gson.annotations.SerializedName;
5
import com.stripe.exception.StripeException;
6
import com.stripe.net.ApiMode;
7
import com.stripe.net.ApiRequestParams;
8
import com.stripe.net.ApiResource;
9
import com.stripe.net.BaseAddress;
10
import com.stripe.net.RequestOptions;
11
import com.stripe.net.StripeResponseGetter;
12
import com.stripe.param.PlanCreateParams;
13
import com.stripe.param.PlanListParams;
14
import com.stripe.param.PlanRetrieveParams;
15
import com.stripe.param.PlanUpdateParams;
16
import java.math.BigDecimal;
17
import java.util.List;
18
import java.util.Map;
19
import lombok.EqualsAndHashCode;
20
import lombok.Getter;
21
import lombok.Setter;
22

23
/**
24
 * You can now model subscriptions more flexibly using the <a
25
 * href="https://stripe.com/docs/api#prices">Prices API</a>. It replaces the Plans API and is
26
 * backwards compatible to simplify your migration.
27
 *
28
 * <p>Plans define the base price, currency, and billing cycle for recurring purchases of products.
29
 * <a href="https://stripe.com/docs/api#products">Products</a> help you track inventory or
30
 * provisioning, and plans help you track pricing. Different physical goods or levels of service
31
 * should be represented by products, and pricing options should be represented by plans. This
32
 * approach lets you change prices without having to change your provisioning scheme.
33
 *
34
 * <p>For example, you might have a single &quot;gold&quot; product that has plans for $10/month,
35
 * $100/year, €9/month, and €90/year.
36
 *
37
 * <p>Related guides: <a
38
 * href="https://stripe.com/docs/billing/subscriptions/set-up-subscription">Set up a
39
 * subscription</a> and more about <a
40
 * href="https://stripe.com/docs/products-prices/overview">products and prices</a>.
41
 */
42
@Getter
43
@Setter
44
@EqualsAndHashCode(callSuper = false)
45
public class Plan extends ApiResource implements HasId, MetadataStore<Plan> {
1✔
46
  /** Whether the plan can be used for new purchases. */
47
  @SerializedName("active")
48
  Boolean active;
49

50
  /**
51
   * Specifies a usage aggregation strategy for plans of {@code usage_type=metered}. Allowed values
52
   * are {@code sum} for summing up all usage during a period, {@code last_during_period} for using
53
   * the last usage record reported within a period, {@code last_ever} for using the last usage
54
   * record ever (across period bounds) or {@code max} which uses the usage record with the maximum
55
   * reported usage during a period. Defaults to {@code sum}.
56
   *
57
   * <p>One of {@code last_during_period}, {@code last_ever}, {@code max}, or {@code sum}.
58
   */
59
  @SerializedName("aggregate_usage")
60
  String aggregateUsage;
61

62
  /**
63
   * The unit amount in cents (or local equivalent) to be charged, represented as a whole integer if
64
   * possible. Only set if {@code billing_scheme=per_unit}.
65
   */
66
  @SerializedName("amount")
67
  Long amount;
68

69
  /**
70
   * The unit amount in cents (or local equivalent) to be charged, represented as a decimal string
71
   * with at most 12 decimal places. Only set if {@code billing_scheme=per_unit}.
72
   */
73
  @SerializedName("amount_decimal")
74
  BigDecimal amountDecimal;
75

76
  /**
77
   * Describes how to compute the price per period. Either {@code per_unit} or {@code tiered}.
78
   * {@code per_unit} indicates that the fixed amount (specified in {@code amount}) will be charged
79
   * per unit in {@code quantity} (for plans with {@code usage_type=licensed}), or per unit of total
80
   * usage (for plans with {@code usage_type=metered}). {@code tiered} indicates that the unit
81
   * pricing will be computed using a tiering strategy as defined using the {@code tiers} and {@code
82
   * tiers_mode} attributes.
83
   *
84
   * <p>One of {@code per_unit}, or {@code tiered}.
85
   */
86
  @SerializedName("billing_scheme")
87
  String billingScheme;
88

89
  /** Time at which the object was created. Measured in seconds since the Unix epoch. */
90
  @SerializedName("created")
91
  Long created;
92

93
  /**
94
   * Three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a>,
95
   * in lowercase. Must be a <a href="https://stripe.com/docs/currencies">supported currency</a>.
96
   */
97
  @SerializedName("currency")
98
  String currency;
99

100
  /** Always true for a deleted object. */
101
  @SerializedName("deleted")
102
  Boolean deleted;
103

104
  /** Unique identifier for the object. */
105
  @Getter(onMethod_ = {@Override})
106
  @SerializedName("id")
107
  String id;
108

109
  /**
110
   * The frequency at which a subscription is billed. One of {@code day}, {@code week}, {@code
111
   * month} or {@code year}.
112
   */
113
  @SerializedName("interval")
114
  String interval;
115

116
  /**
117
   * The number of intervals (specified in the {@code interval} attribute) between subscription
118
   * billings. For example, {@code interval=month} and {@code interval_count=3} bills every 3
119
   * months.
120
   */
121
  @SerializedName("interval_count")
122
  Long intervalCount;
123

124
  /**
125
   * Has the value {@code true} if the object exists in live mode or the value {@code false} if the
126
   * object exists in test mode.
127
   */
128
  @SerializedName("livemode")
129
  Boolean livemode;
130

131
  /**
132
   * Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach
133
   * to an object. This can be useful for storing additional information about the object in a
134
   * structured format.
135
   */
136
  @Getter(onMethod_ = {@Override})
137
  @SerializedName("metadata")
138
  Map<String, String> metadata;
139

140
  /** A brief description of the plan, hidden from customers. */
141
  @SerializedName("nickname")
142
  String nickname;
143

144
  /**
145
   * String representing the object's type. Objects of the same type share the same value.
146
   *
147
   * <p>Equal to {@code plan}.
148
   */
149
  @SerializedName("object")
150
  String object;
151

152
  /** The product whose pricing this plan determines. */
153
  @SerializedName("product")
154
  @Getter(lombok.AccessLevel.NONE)
155
  @Setter(lombok.AccessLevel.NONE)
156
  ExpandableField<Product> product;
157

158
  /**
159
   * Each element represents a pricing tier. This parameter requires {@code billing_scheme} to be
160
   * set to {@code tiered}. See also the documentation for {@code billing_scheme}.
161
   */
162
  @SerializedName("tiers")
163
  List<Plan.Tier> tiers;
164

165
  /**
166
   * Defines if the tiering price should be {@code graduated} or {@code volume} based. In {@code
167
   * volume}-based tiering, the maximum quantity within a period determines the per unit price. In
168
   * {@code graduated} tiering, pricing can change as the quantity grows.
169
   *
170
   * <p>One of {@code graduated}, or {@code volume}.
171
   */
172
  @SerializedName("tiers_mode")
173
  String tiersMode;
174

175
  /**
176
   * Apply a transformation to the reported usage or set quantity before computing the amount
177
   * billed. Cannot be combined with {@code tiers}.
178
   */
179
  @SerializedName("transform_usage")
180
  TransformUsage transformUsage;
181

182
  /**
183
   * Default number of trial days when subscribing a customer to this plan using <a
184
   * href="https://stripe.com/docs/api#create_subscription-trial_from_plan">{@code
185
   * trial_from_plan=true}</a>.
186
   */
187
  @SerializedName("trial_period_days")
188
  Long trialPeriodDays;
189

190
  /**
191
   * Configures how the quantity per period should be determined. Can be either {@code metered} or
192
   * {@code licensed}. {@code licensed} automatically bills the {@code quantity} set when adding it
193
   * to a subscription. {@code metered} aggregates the total usage based on usage records. Defaults
194
   * to {@code licensed}.
195
   */
196
  @SerializedName("usage_type")
197
  String usageType;
198

199
  /** Get ID of expandable {@code product} object. */
200
  public String getProduct() {
201
    return (this.product != null) ? this.product.getId() : null;
1✔
202
  }
203

204
  public void setProduct(String id) {
205
    this.product = ApiResource.setExpandableFieldId(id, this.product);
×
206
  }
×
207

208
  /** Get expanded {@code product}. */
209
  public Product getProductObject() {
210
    return (this.product != null) ? this.product.getExpanded() : null;
1✔
211
  }
212

213
  public void setProductObject(Product expandableObject) {
214
    this.product = new ExpandableField<Product>(expandableObject.getId(), expandableObject);
×
215
  }
×
216

217
  /**
218
   * You can now model subscriptions more flexibly using the <a
219
   * href="https://stripe.com/docs/api#prices">Prices API</a>. It replaces the Plans API and is
220
   * backwards compatible to simplify your migration.
221
   */
222
  public static Plan create(Map<String, Object> params) throws StripeException {
223
    return create(params, (RequestOptions) null);
1✔
224
  }
225

226
  /**
227
   * You can now model subscriptions more flexibly using the <a
228
   * href="https://stripe.com/docs/api#prices">Prices API</a>. It replaces the Plans API and is
229
   * backwards compatible to simplify your migration.
230
   */
231
  public static Plan create(Map<String, Object> params, RequestOptions options)
232
      throws StripeException {
233
    String url = "/v1/plans";
1✔
234
    return getGlobalResponseGetter()
1✔
235
        .request(
1✔
236
            BaseAddress.API,
237
            ApiResource.RequestMethod.POST,
238
            url,
239
            params,
240
            Plan.class,
241
            options,
242
            ApiMode.V1);
243
  }
244

245
  /**
246
   * You can now model subscriptions more flexibly using the <a
247
   * href="https://stripe.com/docs/api#prices">Prices API</a>. It replaces the Plans API and is
248
   * backwards compatible to simplify your migration.
249
   */
250
  public static Plan create(PlanCreateParams params) throws StripeException {
251
    return create(params, (RequestOptions) null);
1✔
252
  }
253

254
  /**
255
   * You can now model subscriptions more flexibly using the <a
256
   * href="https://stripe.com/docs/api#prices">Prices API</a>. It replaces the Plans API and is
257
   * backwards compatible to simplify your migration.
258
   */
259
  public static Plan create(PlanCreateParams params, RequestOptions options)
260
      throws StripeException {
261
    String url = "/v1/plans";
1✔
262
    ApiResource.checkNullTypedParams(url, params);
1✔
263
    return getGlobalResponseGetter()
1✔
264
        .request(
1✔
265
            BaseAddress.API,
266
            ApiResource.RequestMethod.POST,
267
            url,
268
            ApiRequestParams.paramsToMap(params),
1✔
269
            Plan.class,
270
            options,
271
            ApiMode.V1);
272
  }
273

274
  /** Deleting plans means new subscribers can’t be added. Existing subscribers aren’t affected. */
275
  public Plan delete() throws StripeException {
276
    return delete((Map<String, Object>) null, (RequestOptions) null);
1✔
277
  }
278

279
  /** Deleting plans means new subscribers can’t be added. Existing subscribers aren’t affected. */
280
  public Plan delete(RequestOptions options) throws StripeException {
281
    return delete((Map<String, Object>) null, options);
×
282
  }
283

284
  /** Deleting plans means new subscribers can’t be added. Existing subscribers aren’t affected. */
285
  public Plan delete(Map<String, Object> params) throws StripeException {
286
    return delete(params, (RequestOptions) null);
×
287
  }
288

289
  /** Deleting plans means new subscribers can’t be added. Existing subscribers aren’t affected. */
290
  public Plan delete(Map<String, Object> params, RequestOptions options) throws StripeException {
291
    String url = String.format("/v1/plans/%s", ApiResource.urlEncodeId(this.getId()));
1✔
292
    return getResponseGetter()
1✔
293
        .request(
1✔
294
            BaseAddress.API,
295
            ApiResource.RequestMethod.DELETE,
296
            url,
297
            params,
298
            Plan.class,
299
            options,
300
            ApiMode.V1);
301
  }
302

303
  /** Returns a list of your plans. */
304
  public static PlanCollection list(Map<String, Object> params) throws StripeException {
305
    return list(params, (RequestOptions) null);
1✔
306
  }
307

308
  /** Returns a list of your plans. */
309
  public static PlanCollection list(Map<String, Object> params, RequestOptions options)
310
      throws StripeException {
311
    String url = "/v1/plans";
1✔
312
    return getGlobalResponseGetter()
1✔
313
        .request(
1✔
314
            BaseAddress.API,
315
            ApiResource.RequestMethod.GET,
316
            url,
317
            params,
318
            PlanCollection.class,
319
            options,
320
            ApiMode.V1);
321
  }
322

323
  /** Returns a list of your plans. */
324
  public static PlanCollection list(PlanListParams params) throws StripeException {
325
    return list(params, (RequestOptions) null);
1✔
326
  }
327

328
  /** Returns a list of your plans. */
329
  public static PlanCollection list(PlanListParams params, RequestOptions options)
330
      throws StripeException {
331
    String url = "/v1/plans";
1✔
332
    ApiResource.checkNullTypedParams(url, params);
1✔
333
    return getGlobalResponseGetter()
1✔
334
        .request(
1✔
335
            BaseAddress.API,
336
            ApiResource.RequestMethod.GET,
337
            url,
338
            ApiRequestParams.paramsToMap(params),
1✔
339
            PlanCollection.class,
340
            options,
341
            ApiMode.V1);
342
  }
343

344
  /** Retrieves the plan with the given ID. */
345
  public static Plan retrieve(String plan) throws StripeException {
346
    return retrieve(plan, (Map<String, Object>) null, (RequestOptions) null);
1✔
347
  }
348

349
  /** Retrieves the plan with the given ID. */
350
  public static Plan retrieve(String plan, RequestOptions options) throws StripeException {
351
    return retrieve(plan, (Map<String, Object>) null, options);
×
352
  }
353

354
  /** Retrieves the plan with the given ID. */
355
  public static Plan retrieve(String plan, Map<String, Object> params, RequestOptions options)
356
      throws StripeException {
357
    String url = String.format("/v1/plans/%s", ApiResource.urlEncodeId(plan));
1✔
358
    return getGlobalResponseGetter()
1✔
359
        .request(
1✔
360
            BaseAddress.API,
361
            ApiResource.RequestMethod.GET,
362
            url,
363
            params,
364
            Plan.class,
365
            options,
366
            ApiMode.V1);
367
  }
368

369
  /** Retrieves the plan with the given ID. */
370
  public static Plan retrieve(String plan, PlanRetrieveParams params, RequestOptions options)
371
      throws StripeException {
372
    String url = String.format("/v1/plans/%s", ApiResource.urlEncodeId(plan));
×
373
    ApiResource.checkNullTypedParams(url, params);
×
374
    return getGlobalResponseGetter()
×
375
        .request(
×
376
            BaseAddress.API,
377
            ApiResource.RequestMethod.GET,
378
            url,
379
            ApiRequestParams.paramsToMap(params),
×
380
            Plan.class,
381
            options,
382
            ApiMode.V1);
383
  }
384

385
  /**
386
   * Updates the specified plan by setting the values of the parameters passed. Any parameters not
387
   * provided are left unchanged. By design, you cannot change a plan’s ID, amount, currency, or
388
   * billing cycle.
389
   */
390
  @Override
391
  public Plan update(Map<String, Object> params) throws StripeException {
392
    return update(params, (RequestOptions) null);
1✔
393
  }
394

395
  /**
396
   * Updates the specified plan by setting the values of the parameters passed. Any parameters not
397
   * provided are left unchanged. By design, you cannot change a plan’s ID, amount, currency, or
398
   * billing cycle.
399
   */
400
  @Override
401
  public Plan update(Map<String, Object> params, RequestOptions options) throws StripeException {
402
    String url = String.format("/v1/plans/%s", ApiResource.urlEncodeId(this.getId()));
1✔
403
    return getResponseGetter()
1✔
404
        .request(
1✔
405
            BaseAddress.API,
406
            ApiResource.RequestMethod.POST,
407
            url,
408
            params,
409
            Plan.class,
410
            options,
411
            ApiMode.V1);
412
  }
413

414
  /**
415
   * Updates the specified plan by setting the values of the parameters passed. Any parameters not
416
   * provided are left unchanged. By design, you cannot change a plan’s ID, amount, currency, or
417
   * billing cycle.
418
   */
419
  public Plan update(PlanUpdateParams params) throws StripeException {
420
    return update(params, (RequestOptions) null);
1✔
421
  }
422

423
  /**
424
   * Updates the specified plan by setting the values of the parameters passed. Any parameters not
425
   * provided are left unchanged. By design, you cannot change a plan’s ID, amount, currency, or
426
   * billing cycle.
427
   */
428
  public Plan update(PlanUpdateParams params, RequestOptions options) throws StripeException {
429
    String url = String.format("/v1/plans/%s", ApiResource.urlEncodeId(this.getId()));
1✔
430
    ApiResource.checkNullTypedParams(url, params);
1✔
431
    return getResponseGetter()
1✔
432
        .request(
1✔
433
            BaseAddress.API,
434
            ApiResource.RequestMethod.POST,
435
            url,
436
            ApiRequestParams.paramsToMap(params),
1✔
437
            Plan.class,
438
            options,
439
            ApiMode.V1);
440
  }
441

442
  @Getter
443
  @Setter
444
  @EqualsAndHashCode(callSuper = false)
445
  public static class Tier extends StripeObject {
×
446
    /** Price for the entire tier. */
447
    @SerializedName("flat_amount")
448
    Long flatAmount;
449

450
    /** Same as {@code flat_amount}, but contains a decimal value with at most 12 decimal places. */
451
    @SerializedName("flat_amount_decimal")
452
    BigDecimal flatAmountDecimal;
453

454
    /** Per unit price for units relevant to the tier. */
455
    @SerializedName("unit_amount")
456
    Long unitAmount;
457

458
    /** Same as {@code unit_amount}, but contains a decimal value with at most 12 decimal places. */
459
    @SerializedName("unit_amount_decimal")
460
    BigDecimal unitAmountDecimal;
461

462
    /** Up to and including to this quantity will be contained in the tier. */
463
    @SerializedName("up_to")
464
    Long upTo;
465
  }
466

467
  @Getter
468
  @Setter
469
  @EqualsAndHashCode(callSuper = false)
470
  public static class TransformUsage extends StripeObject {
×
471
    /** Divide usage by this number. */
472
    @SerializedName("divide_by")
473
    Long divideBy;
474

475
    /**
476
     * After division, either round the result {@code up} or {@code down}.
477
     *
478
     * <p>One of {@code down}, or {@code up}.
479
     */
480
    @SerializedName("round")
481
    String round;
482
  }
483

484
  @Override
485
  public void setResponseGetter(StripeResponseGetter responseGetter) {
486
    super.setResponseGetter(responseGetter);
1✔
487
    trySetResponseGetter(product, responseGetter);
1✔
488
    trySetResponseGetter(transformUsage, responseGetter);
1✔
489
  }
1✔
490
}
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

© 2025 Coveralls, Inc