• 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

63.75
/src/main/java/com/stripe/model/Product.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.ProductCreateParams;
13
import com.stripe.param.ProductListParams;
14
import com.stripe.param.ProductRetrieveParams;
15
import com.stripe.param.ProductSearchParams;
16
import com.stripe.param.ProductUpdateParams;
17
import java.math.BigDecimal;
18
import java.util.List;
19
import java.util.Map;
20
import lombok.EqualsAndHashCode;
21
import lombok.Getter;
22
import lombok.Setter;
23

24
/**
25
 * Products describe the specific goods or services you offer to your customers. For example, you
26
 * might offer a Standard and Premium version of your goods or service; each version would be a
27
 * separate Product. They can be used in conjunction with <a
28
 * href="https://stripe.com/docs/api#prices">Prices</a> to configure pricing in Payment Links,
29
 * Checkout, and Subscriptions.
30
 *
31
 * <p>Related guides: <a
32
 * href="https://stripe.com/docs/billing/subscriptions/set-up-subscription">Set up a
33
 * subscription</a>, <a href="https://stripe.com/docs/payment-links">share a Payment Link</a>, <a
34
 * href="https://stripe.com/docs/payments/accept-a-payment#create-product-prices-upfront">accept
35
 * payments with Checkout</a>, and more about <a
36
 * href="https://stripe.com/docs/products-prices/overview">Products and Prices</a>
37
 */
38
@Getter
39
@Setter
40
@EqualsAndHashCode(callSuper = false)
41
public class Product extends ApiResource implements HasId, MetadataStore<Product> {
1✔
42
  /** Whether the product is currently available for purchase. */
43
  @SerializedName("active")
44
  Boolean active;
45

46
  /** Time at which the object was created. Measured in seconds since the Unix epoch. */
47
  @SerializedName("created")
48
  Long created;
49

50
  /**
51
   * The ID of the <a href="https://stripe.com/docs/api/prices">Price</a> object that is the default
52
   * price for this product.
53
   */
54
  @SerializedName("default_price")
55
  @Getter(lombok.AccessLevel.NONE)
56
  @Setter(lombok.AccessLevel.NONE)
57
  ExpandableField<Price> defaultPrice;
58

59
  /** Always true for a deleted object. */
60
  @SerializedName("deleted")
61
  Boolean deleted;
62

63
  /**
64
   * The product's description, meant to be displayable to the customer. Use this field to
65
   * optionally store a long form explanation of the product being sold for your own rendering
66
   * purposes.
67
   */
68
  @SerializedName("description")
69
  String description;
70

71
  /** Unique identifier for the object. */
72
  @Getter(onMethod_ = {@Override})
73
  @SerializedName("id")
74
  String id;
75

76
  /** A list of up to 8 URLs of images for this product, meant to be displayable to the customer. */
77
  @SerializedName("images")
78
  List<String> images;
79

80
  /**
81
   * Has the value {@code true} if the object exists in live mode or the value {@code false} if the
82
   * object exists in test mode.
83
   */
84
  @SerializedName("livemode")
85
  Boolean livemode;
86

87
  /**
88
   * A list of up to 15 marketing features for this product. These are displayed in <a
89
   * href="https://stripe.com/docs/payments/checkout/pricing-table">pricing tables</a>.
90
   */
91
  @SerializedName("marketing_features")
92
  List<Product.MarketingFeature> marketingFeatures;
93

94
  /**
95
   * Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach
96
   * to an object. This can be useful for storing additional information about the object in a
97
   * structured format.
98
   */
99
  @Getter(onMethod_ = {@Override})
100
  @SerializedName("metadata")
101
  Map<String, String> metadata;
102

103
  /** The product's name, meant to be displayable to the customer. */
104
  @SerializedName("name")
105
  String name;
106

107
  /**
108
   * String representing the object's type. Objects of the same type share the same value.
109
   *
110
   * <p>Equal to {@code product}.
111
   */
112
  @SerializedName("object")
113
  String object;
114

115
  /** The dimensions of this product for shipping purposes. */
116
  @SerializedName("package_dimensions")
117
  PackageDimensions packageDimensions;
118

119
  /** Provisioning configuration for this product. */
120
  @SerializedName("provisioning")
121
  Provisioning provisioning;
122

123
  /** Whether this product is shipped (i.e., physical goods). */
124
  @SerializedName("shippable")
125
  Boolean shippable;
126

127
  /**
128
   * Extra information about a product which will appear on your customer's credit card statement.
129
   * In the case that multiple products are billed at once, the first statement descriptor will be
130
   * used. Only used for subscription payments.
131
   */
132
  @SerializedName("statement_descriptor")
133
  String statementDescriptor;
134

135
  /** A <a href="https://stripe.com/docs/tax/tax-categories">tax code</a> ID. */
136
  @SerializedName("tax_code")
137
  @Getter(lombok.AccessLevel.NONE)
138
  @Setter(lombok.AccessLevel.NONE)
139
  ExpandableField<TaxCode> taxCode;
140

141
  /**
142
   * The type of the product. The product is either of type {@code good}, which is eligible for use
143
   * with Orders and SKUs, or {@code service}, which is eligible for use with Subscriptions and
144
   * Plans.
145
   *
146
   * <p>One of {@code good}, or {@code service}.
147
   */
148
  @SerializedName("type")
149
  String type;
150

151
  /**
152
   * A label that represents units of this product. When set, this will be included in customers'
153
   * receipts, invoices, Checkout, and the customer portal.
154
   */
155
  @SerializedName("unit_label")
156
  String unitLabel;
157

158
  /** Time at which the object was last updated. Measured in seconds since the Unix epoch. */
159
  @SerializedName("updated")
160
  Long updated;
161

162
  /** A URL of a publicly-accessible webpage for this product. */
163
  @SerializedName("url")
164
  String url;
165

166
  /** Get ID of expandable {@code defaultPrice} object. */
167
  public String getDefaultPrice() {
168
    return (this.defaultPrice != null) ? this.defaultPrice.getId() : null;
×
169
  }
170

171
  public void setDefaultPrice(String id) {
172
    this.defaultPrice = ApiResource.setExpandableFieldId(id, this.defaultPrice);
×
173
  }
×
174

175
  /** Get expanded {@code defaultPrice}. */
176
  public Price getDefaultPriceObject() {
177
    return (this.defaultPrice != null) ? this.defaultPrice.getExpanded() : null;
×
178
  }
179

180
  public void setDefaultPriceObject(Price expandableObject) {
181
    this.defaultPrice = new ExpandableField<Price>(expandableObject.getId(), expandableObject);
×
182
  }
×
183

184
  /** Get ID of expandable {@code taxCode} object. */
185
  public String getTaxCode() {
186
    return (this.taxCode != null) ? this.taxCode.getId() : null;
×
187
  }
188

189
  public void setTaxCode(String id) {
190
    this.taxCode = ApiResource.setExpandableFieldId(id, this.taxCode);
×
191
  }
×
192

193
  /** Get expanded {@code taxCode}. */
194
  public TaxCode getTaxCodeObject() {
195
    return (this.taxCode != null) ? this.taxCode.getExpanded() : null;
×
196
  }
197

198
  public void setTaxCodeObject(TaxCode expandableObject) {
199
    this.taxCode = new ExpandableField<TaxCode>(expandableObject.getId(), expandableObject);
×
200
  }
×
201

202
  /** Creates a new product object. */
203
  public static Product create(Map<String, Object> params) throws StripeException {
204
    return create(params, (RequestOptions) null);
1✔
205
  }
206

207
  /** Creates a new product object. */
208
  public static Product create(Map<String, Object> params, RequestOptions options)
209
      throws StripeException {
210
    String path = "/v1/products";
1✔
211
    ApiRequest request =
1✔
212
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.POST, path, params, options);
213
    return getGlobalResponseGetter().request(request, Product.class);
1✔
214
  }
215

216
  /** Creates a new product object. */
217
  public static Product create(ProductCreateParams params) throws StripeException {
218
    return create(params, (RequestOptions) null);
1✔
219
  }
220

221
  /** Creates a new product object. */
222
  public static Product create(ProductCreateParams params, RequestOptions options)
223
      throws StripeException {
224
    String path = "/v1/products";
1✔
225
    ApiResource.checkNullTypedParams(path, params);
1✔
226
    ApiRequest request =
1✔
227
        new ApiRequest(
228
            BaseAddress.API,
229
            ApiResource.RequestMethod.POST,
230
            path,
231
            ApiRequestParams.paramsToMap(params),
1✔
232
            options);
233
    return getGlobalResponseGetter().request(request, Product.class);
1✔
234
  }
235

236
  /**
237
   * Delete a product. Deleting a product is only possible if it has no prices associated with it.
238
   * Additionally, deleting a product with {@code type=good} is only possible if it has no SKUs
239
   * associated with it.
240
   */
241
  public Product delete() throws StripeException {
242
    return delete((Map<String, Object>) null, (RequestOptions) null);
1✔
243
  }
244

245
  /**
246
   * Delete a product. Deleting a product is only possible if it has no prices associated with it.
247
   * Additionally, deleting a product with {@code type=good} is only possible if it has no SKUs
248
   * associated with it.
249
   */
250
  public Product delete(RequestOptions options) throws StripeException {
251
    return delete((Map<String, Object>) null, options);
×
252
  }
253

254
  /**
255
   * Delete a product. Deleting a product is only possible if it has no prices associated with it.
256
   * Additionally, deleting a product with {@code type=good} is only possible if it has no SKUs
257
   * associated with it.
258
   */
259
  public Product delete(Map<String, Object> params) throws StripeException {
260
    return delete(params, (RequestOptions) null);
×
261
  }
262

263
  /**
264
   * Delete a product. Deleting a product is only possible if it has no prices associated with it.
265
   * Additionally, deleting a product with {@code type=good} is only possible if it has no SKUs
266
   * associated with it.
267
   */
268
  public Product delete(Map<String, Object> params, RequestOptions options) throws StripeException {
269
    String path = String.format("/v1/products/%s", ApiResource.urlEncodeId(this.getId()));
1✔
270
    ApiRequest request =
1✔
271
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.DELETE, path, params, options);
272
    return getResponseGetter().request(request, Product.class);
1✔
273
  }
274

275
  /**
276
   * Returns a list of your products. The products are returned sorted by creation date, with the
277
   * most recently created products appearing first.
278
   */
279
  public static ProductCollection list(Map<String, Object> params) throws StripeException {
280
    return list(params, (RequestOptions) null);
1✔
281
  }
282

283
  /**
284
   * Returns a list of your products. The products are returned sorted by creation date, with the
285
   * most recently created products appearing first.
286
   */
287
  public static ProductCollection list(Map<String, Object> params, RequestOptions options)
288
      throws StripeException {
289
    String path = "/v1/products";
1✔
290
    ApiRequest request =
1✔
291
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.GET, path, params, options);
292
    return getGlobalResponseGetter().request(request, ProductCollection.class);
1✔
293
  }
294

295
  /**
296
   * Returns a list of your products. The products are returned sorted by creation date, with the
297
   * most recently created products appearing first.
298
   */
299
  public static ProductCollection list(ProductListParams params) throws StripeException {
300
    return list(params, (RequestOptions) null);
1✔
301
  }
302

303
  /**
304
   * Returns a list of your products. The products are returned sorted by creation date, with the
305
   * most recently created products appearing first.
306
   */
307
  public static ProductCollection list(ProductListParams params, RequestOptions options)
308
      throws StripeException {
309
    String path = "/v1/products";
1✔
310
    ApiResource.checkNullTypedParams(path, params);
1✔
311
    ApiRequest request =
1✔
312
        new ApiRequest(
313
            BaseAddress.API,
314
            ApiResource.RequestMethod.GET,
315
            path,
316
            ApiRequestParams.paramsToMap(params),
1✔
317
            options);
318
    return getGlobalResponseGetter().request(request, ProductCollection.class);
1✔
319
  }
320

321
  /**
322
   * Retrieves the details of an existing product. Supply the unique product ID from either a
323
   * product creation request or the product list, and Stripe will return the corresponding product
324
   * information.
325
   */
326
  public static Product retrieve(String id) throws StripeException {
327
    return retrieve(id, (Map<String, Object>) null, (RequestOptions) null);
1✔
328
  }
329

330
  /**
331
   * Retrieves the details of an existing product. Supply the unique product ID from either a
332
   * product creation request or the product list, and Stripe will return the corresponding product
333
   * information.
334
   */
335
  public static Product retrieve(String id, RequestOptions options) throws StripeException {
336
    return retrieve(id, (Map<String, Object>) null, options);
×
337
  }
338

339
  /**
340
   * Retrieves the details of an existing product. Supply the unique product ID from either a
341
   * product creation request or the product list, and Stripe will return the corresponding product
342
   * information.
343
   */
344
  public static Product retrieve(String id, Map<String, Object> params, RequestOptions options)
345
      throws StripeException {
346
    String path = String.format("/v1/products/%s", ApiResource.urlEncodeId(id));
1✔
347
    ApiRequest request =
1✔
348
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.GET, path, params, options);
349
    return getGlobalResponseGetter().request(request, Product.class);
1✔
350
  }
351

352
  /**
353
   * Retrieves the details of an existing product. Supply the unique product ID from either a
354
   * product creation request or the product list, and Stripe will return the corresponding product
355
   * information.
356
   */
357
  public static Product retrieve(String id, ProductRetrieveParams params, RequestOptions options)
358
      throws StripeException {
359
    String path = String.format("/v1/products/%s", ApiResource.urlEncodeId(id));
×
360
    ApiResource.checkNullTypedParams(path, params);
×
361
    ApiRequest request =
×
362
        new ApiRequest(
363
            BaseAddress.API,
364
            ApiResource.RequestMethod.GET,
365
            path,
366
            ApiRequestParams.paramsToMap(params),
×
367
            options);
UNCOV
368
    return getGlobalResponseGetter().request(request, Product.class);
×
369
  }
370

371
  /**
372
   * Search for products you’ve previously created using Stripe’s <a
373
   * href="https://stripe.com/docs/search#search-query-language">Search Query Language</a>. Don’t
374
   * use search in read-after-write flows where strict consistency is necessary. Under normal
375
   * operating conditions, data is searchable in less than a minute. Occasionally, propagation of
376
   * new or updated data can be up to an hour behind during outages. Search functionality is not
377
   * available to merchants in India.
378
   */
379
  public static ProductSearchResult search(Map<String, Object> params) throws StripeException {
380
    return search(params, (RequestOptions) null);
×
381
  }
382

383
  /**
384
   * Search for products you’ve previously created using Stripe’s <a
385
   * href="https://stripe.com/docs/search#search-query-language">Search Query Language</a>. Don’t
386
   * use search in read-after-write flows where strict consistency is necessary. Under normal
387
   * operating conditions, data is searchable in less than a minute. Occasionally, propagation of
388
   * new or updated data can be up to an hour behind during outages. Search functionality is not
389
   * available to merchants in India.
390
   */
391
  public static ProductSearchResult search(Map<String, Object> params, RequestOptions options)
392
      throws StripeException {
393
    String path = "/v1/products/search";
×
394
    ApiRequest request =
×
395
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.GET, path, params, options);
UNCOV
396
    return getGlobalResponseGetter().request(request, ProductSearchResult.class);
×
397
  }
398

399
  /**
400
   * Search for products you’ve previously created using Stripe’s <a
401
   * href="https://stripe.com/docs/search#search-query-language">Search Query Language</a>. Don’t
402
   * use search in read-after-write flows where strict consistency is necessary. Under normal
403
   * operating conditions, data is searchable in less than a minute. Occasionally, propagation of
404
   * new or updated data can be up to an hour behind during outages. Search functionality is not
405
   * available to merchants in India.
406
   */
407
  public static ProductSearchResult search(ProductSearchParams params) throws StripeException {
408
    return search(params, (RequestOptions) null);
1✔
409
  }
410

411
  /**
412
   * Search for products you’ve previously created using Stripe’s <a
413
   * href="https://stripe.com/docs/search#search-query-language">Search Query Language</a>. Don’t
414
   * use search in read-after-write flows where strict consistency is necessary. Under normal
415
   * operating conditions, data is searchable in less than a minute. Occasionally, propagation of
416
   * new or updated data can be up to an hour behind during outages. Search functionality is not
417
   * available to merchants in India.
418
   */
419
  public static ProductSearchResult search(ProductSearchParams params, RequestOptions options)
420
      throws StripeException {
421
    String path = "/v1/products/search";
1✔
422
    ApiResource.checkNullTypedParams(path, params);
1✔
423
    ApiRequest request =
1✔
424
        new ApiRequest(
425
            BaseAddress.API,
426
            ApiResource.RequestMethod.GET,
427
            path,
428
            ApiRequestParams.paramsToMap(params),
1✔
429
            options);
430
    return getGlobalResponseGetter().request(request, ProductSearchResult.class);
1✔
431
  }
432

433
  /**
434
   * Updates the specific product by setting the values of the parameters passed. Any parameters not
435
   * provided will be left unchanged.
436
   */
437
  @Override
438
  public Product update(Map<String, Object> params) throws StripeException {
439
    return update(params, (RequestOptions) null);
1✔
440
  }
441

442
  /**
443
   * Updates the specific product by setting the values of the parameters passed. Any parameters not
444
   * provided will be left unchanged.
445
   */
446
  @Override
447
  public Product update(Map<String, Object> params, RequestOptions options) throws StripeException {
448
    String path = String.format("/v1/products/%s", ApiResource.urlEncodeId(this.getId()));
1✔
449
    ApiRequest request =
1✔
450
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.POST, path, params, options);
451
    return getResponseGetter().request(request, Product.class);
1✔
452
  }
453

454
  /**
455
   * Updates the specific product by setting the values of the parameters passed. Any parameters not
456
   * provided will be left unchanged.
457
   */
458
  public Product update(ProductUpdateParams params) throws StripeException {
459
    return update(params, (RequestOptions) null);
1✔
460
  }
461

462
  /**
463
   * Updates the specific product by setting the values of the parameters passed. Any parameters not
464
   * provided will be left unchanged.
465
   */
466
  public Product update(ProductUpdateParams params, RequestOptions options) throws StripeException {
467
    String path = String.format("/v1/products/%s", ApiResource.urlEncodeId(this.getId()));
1✔
468
    ApiResource.checkNullTypedParams(path, params);
1✔
469
    ApiRequest request =
1✔
470
        new ApiRequest(
471
            BaseAddress.API,
472
            ApiResource.RequestMethod.POST,
473
            path,
474
            ApiRequestParams.paramsToMap(params),
1✔
475
            options);
476
    return getResponseGetter().request(request, Product.class);
1✔
477
  }
478

479
  @Getter
480
  @Setter
481
  @EqualsAndHashCode(callSuper = false)
482
  public static class MarketingFeature extends StripeObject {
×
483
    /** The marketing feature name. Up to 80 characters long. */
484
    @SerializedName("name")
485
    String name;
486
  }
487

488
  @Getter
489
  @Setter
490
  @EqualsAndHashCode(callSuper = false)
491
  public static class PackageDimensions extends StripeObject {
×
492
    /** Height, in inches. */
493
    @SerializedName("height")
494
    BigDecimal height;
495

496
    /** Length, in inches. */
497
    @SerializedName("length")
498
    BigDecimal length;
499

500
    /** Weight, in ounces. */
501
    @SerializedName("weight")
502
    BigDecimal weight;
503

504
    /** Width, in inches. */
505
    @SerializedName("width")
506
    BigDecimal width;
507
  }
508

509
  @Getter
510
  @Setter
511
  @EqualsAndHashCode(callSuper = false)
512
  public static class Provisioning extends StripeObject {
×
513
    @SerializedName("gift_card")
514
    GiftCard giftCard;
515

516
    /**
517
     * The type of provisioning, only {@code gift_card} currently supported.
518
     *
519
     * <p>Equal to {@code gift_card}.
520
     */
521
    @SerializedName("type")
522
    String type;
523

524
    @Getter
525
    @Setter
526
    @EqualsAndHashCode(callSuper = false)
527
    public static class GiftCard extends StripeObject {
×
528
      @SerializedName("fixed_amount")
529
      FixedAmount fixedAmount;
530

531
      /**
532
       * The specific type of gift_card provisioning, only {@code fixed_amount} currently supported.
533
       *
534
       * <p>Equal to {@code fixed_amount}.
535
       */
536
      @SerializedName("type")
537
      String type;
538

539
      @Getter
540
      @Setter
541
      @EqualsAndHashCode(callSuper = false)
542
      public static class FixedAmount extends StripeObject {
×
543
        /** The initial amount with which the provisioned gift card will be created. */
544
        @SerializedName("amount")
545
        Long amount;
546

547
        /**
548
         * Three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency
549
         * code</a>, in lowercase. Must be a <a href="https://stripe.com/docs/currencies">supported
550
         * currency</a>.
551
         */
552
        @SerializedName("currency")
553
        String currency;
554
      }
555
    }
556
  }
557

558
  @Override
559
  public void setResponseGetter(StripeResponseGetter responseGetter) {
560
    super.setResponseGetter(responseGetter);
1✔
561
    trySetResponseGetter(defaultPrice, responseGetter);
1✔
562
    trySetResponseGetter(packageDimensions, responseGetter);
1✔
563
    trySetResponseGetter(provisioning, responseGetter);
1✔
564
    trySetResponseGetter(taxCode, responseGetter);
1✔
565
  }
1✔
566
}
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