• 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

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.ApiRequest;
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
  /** The meter tracking the usage of a metered price. */
141
  @SerializedName("meter")
142
  String meter;
143

144
  /** A brief description of the plan, hidden from customers. */
145
  @SerializedName("nickname")
146
  String nickname;
147

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

156
  /** The product whose pricing this plan determines. */
157
  @SerializedName("product")
158
  @Getter(lombok.AccessLevel.NONE)
159
  @Setter(lombok.AccessLevel.NONE)
160
  ExpandableField<Product> product;
161

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

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

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

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

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

203
  /** Get ID of expandable {@code product} object. */
204
  public String getProduct() {
205
    return (this.product != null) ? this.product.getId() : null;
1✔
206
  }
207

208
  public void setProduct(String id) {
209
    this.product = ApiResource.setExpandableFieldId(id, this.product);
×
210
  }
×
211

212
  /** Get expanded {@code product}. */
213
  public Product getProductObject() {
214
    return (this.product != null) ? this.product.getExpanded() : null;
1✔
215
  }
216

217
  public void setProductObject(Product expandableObject) {
218
    this.product = new ExpandableField<Product>(expandableObject.getId(), expandableObject);
×
219
  }
×
220

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

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

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

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

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

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

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

286
  /** Deleting plans means new subscribers can’t be added. Existing subscribers aren’t affected. */
287
  public Plan delete(Map<String, Object> params, RequestOptions options) throws StripeException {
288
    String path = String.format("/v1/plans/%s", ApiResource.urlEncodeId(this.getId()));
1✔
289
    ApiRequest request =
1✔
290
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.DELETE, path, params, options);
291
    return getResponseGetter().request(request, Plan.class);
1✔
292
  }
293

294
  /** Returns a list of your plans. */
295
  public static PlanCollection list(Map<String, Object> params) throws StripeException {
296
    return list(params, (RequestOptions) null);
1✔
297
  }
298

299
  /** Returns a list of your plans. */
300
  public static PlanCollection list(Map<String, Object> params, RequestOptions options)
301
      throws StripeException {
302
    String path = "/v1/plans";
1✔
303
    ApiRequest request =
1✔
304
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.GET, path, params, options);
305
    return getGlobalResponseGetter().request(request, PlanCollection.class);
1✔
306
  }
307

308
  /** Returns a list of your plans. */
309
  public static PlanCollection list(PlanListParams params) throws StripeException {
310
    return list(params, (RequestOptions) null);
1✔
311
  }
312

313
  /** Returns a list of your plans. */
314
  public static PlanCollection list(PlanListParams params, RequestOptions options)
315
      throws StripeException {
316
    String path = "/v1/plans";
1✔
317
    ApiResource.checkNullTypedParams(path, params);
1✔
318
    ApiRequest request =
1✔
319
        new ApiRequest(
320
            BaseAddress.API,
321
            ApiResource.RequestMethod.GET,
322
            path,
323
            ApiRequestParams.paramsToMap(params),
1✔
324
            options);
325
    return getGlobalResponseGetter().request(request, PlanCollection.class);
1✔
326
  }
327

328
  /** Retrieves the plan with the given ID. */
329
  public static Plan retrieve(String plan) throws StripeException {
330
    return retrieve(plan, (Map<String, Object>) null, (RequestOptions) null);
1✔
331
  }
332

333
  /** Retrieves the plan with the given ID. */
334
  public static Plan retrieve(String plan, RequestOptions options) throws StripeException {
335
    return retrieve(plan, (Map<String, Object>) null, options);
×
336
  }
337

338
  /** Retrieves the plan with the given ID. */
339
  public static Plan retrieve(String plan, Map<String, Object> params, RequestOptions options)
340
      throws StripeException {
341
    String path = String.format("/v1/plans/%s", ApiResource.urlEncodeId(plan));
1✔
342
    ApiRequest request =
1✔
343
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.GET, path, params, options);
344
    return getGlobalResponseGetter().request(request, Plan.class);
1✔
345
  }
346

347
  /** Retrieves the plan with the given ID. */
348
  public static Plan retrieve(String plan, PlanRetrieveParams params, RequestOptions options)
349
      throws StripeException {
350
    String path = String.format("/v1/plans/%s", ApiResource.urlEncodeId(plan));
×
351
    ApiResource.checkNullTypedParams(path, params);
×
352
    ApiRequest request =
×
353
        new ApiRequest(
354
            BaseAddress.API,
355
            ApiResource.RequestMethod.GET,
356
            path,
357
            ApiRequestParams.paramsToMap(params),
×
358
            options);
UNCOV
359
    return getGlobalResponseGetter().request(request, Plan.class);
×
360
  }
361

362
  /**
363
   * Updates the specified plan by setting the values of the parameters passed. Any parameters not
364
   * provided are left unchanged. By design, you cannot change a plan’s ID, amount, currency, or
365
   * billing cycle.
366
   */
367
  @Override
368
  public Plan update(Map<String, Object> params) throws StripeException {
369
    return update(params, (RequestOptions) null);
1✔
370
  }
371

372
  /**
373
   * Updates the specified plan by setting the values of the parameters passed. Any parameters not
374
   * provided are left unchanged. By design, you cannot change a plan’s ID, amount, currency, or
375
   * billing cycle.
376
   */
377
  @Override
378
  public Plan update(Map<String, Object> params, RequestOptions options) throws StripeException {
379
    String path = String.format("/v1/plans/%s", ApiResource.urlEncodeId(this.getId()));
1✔
380
    ApiRequest request =
1✔
381
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.POST, path, params, options);
382
    return getResponseGetter().request(request, Plan.class);
1✔
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
  public Plan update(PlanUpdateParams params) throws StripeException {
391
    return update(params, (RequestOptions) null);
1✔
392
  }
393

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

412
  @Getter
413
  @Setter
414
  @EqualsAndHashCode(callSuper = false)
415
  public static class Tier extends StripeObject {
×
416
    /** Price for the entire tier. */
417
    @SerializedName("flat_amount")
418
    Long flatAmount;
419

420
    /** Same as {@code flat_amount}, but contains a decimal value with at most 12 decimal places. */
421
    @SerializedName("flat_amount_decimal")
422
    BigDecimal flatAmountDecimal;
423

424
    /** Per unit price for units relevant to the tier. */
425
    @SerializedName("unit_amount")
426
    Long unitAmount;
427

428
    /** Same as {@code unit_amount}, but contains a decimal value with at most 12 decimal places. */
429
    @SerializedName("unit_amount_decimal")
430
    BigDecimal unitAmountDecimal;
431

432
    /** Up to and including to this quantity will be contained in the tier. */
433
    @SerializedName("up_to")
434
    Long upTo;
435
  }
436

437
  @Getter
438
  @Setter
439
  @EqualsAndHashCode(callSuper = false)
440
  public static class TransformUsage extends StripeObject {
×
441
    /** Divide usage by this number. */
442
    @SerializedName("divide_by")
443
    Long divideBy;
444

445
    /**
446
     * After division, either round the result {@code up} or {@code down}.
447
     *
448
     * <p>One of {@code down}, or {@code up}.
449
     */
450
    @SerializedName("round")
451
    String round;
452
  }
453

454
  @Override
455
  public void setResponseGetter(StripeResponseGetter responseGetter) {
456
    super.setResponseGetter(responseGetter);
1✔
457
    trySetResponseGetter(product, responseGetter);
1✔
458
    trySetResponseGetter(transformUsage, responseGetter);
1✔
459
  }
1✔
460
}
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