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

stripe / stripe-java / #14665

16 Aug 2023 06:23PM UTC coverage: 18.919% (+4.6%) from 14.344%
#14665

push

github-actions

web-flow
stripe-java v23 release (#1622)

11114 of 11114 new or added lines in 307 files covered. (100.0%)

14987 of 79217 relevant lines covered (18.92%)

0.19 hits per line

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

82.69
/src/main/java/com/stripe/model/Coupon.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.CouponCreateParams;
13
import com.stripe.param.CouponListParams;
14
import com.stripe.param.CouponRetrieveParams;
15
import com.stripe.param.CouponUpdateParams;
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
 * A coupon contains information about a percent-off or amount-off discount you might want to apply
25
 * to a customer. Coupons may be applied to <a
26
 * href="https://stripe.com/docs/api#subscriptions">subscriptions</a>, <a
27
 * href="https://stripe.com/docs/api#invoices">invoices</a>, <a
28
 * href="https://stripe.com/docs/api/checkout/sessions">checkout sessions</a>, <a
29
 * href="https://stripe.com/docs/api#quotes">quotes</a>, and more. Coupons do not work with
30
 * conventional one-off <a href="https://stripe.com/docs/api#create_charge">charges</a> or <a
31
 * href="https://stripe.com/docs/api/payment_intents">payment intents</a>.
32
 */
33
@Getter
34
@Setter
35
@EqualsAndHashCode(callSuper = false)
36
public class Coupon extends ApiResource implements HasId, MetadataStore<Coupon> {
1✔
37
  /**
38
   * Amount (in the {@code currency} specified) that will be taken off the subtotal of any invoices
39
   * for this customer.
40
   */
41
  @SerializedName("amount_off")
42
  Long amountOff;
43

44
  @SerializedName("applies_to")
45
  AppliesTo appliesTo;
46

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

51
  /**
52
   * If {@code amount_off} has been set, the three-letter <a
53
   * href="https://stripe.com/docs/currencies">ISO code for the currency</a> of the amount to take
54
   * off.
55
   */
56
  @SerializedName("currency")
57
  String currency;
58

59
  /**
60
   * Coupons defined in each available currency option. Each key must be a three-letter <a
61
   * href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a> and a <a
62
   * href="https://stripe.com/docs/currencies">supported currency</a>.
63
   */
64
  @SerializedName("currency_options")
65
  Map<String, Coupon.CurrencyOption> currencyOptions;
66

67
  /** Always true for a deleted object. */
68
  @SerializedName("deleted")
69
  Boolean deleted;
70

71
  /**
72
   * One of {@code forever}, {@code once}, and {@code repeating}. Describes how long a customer who
73
   * applies this coupon will get the discount.
74
   */
75
  @SerializedName("duration")
76
  String duration;
77

78
  /**
79
   * If {@code duration} is {@code repeating}, the number of months the coupon applies. Null if
80
   * coupon {@code duration} is {@code forever} or {@code once}.
81
   */
82
  @SerializedName("duration_in_months")
83
  Long durationInMonths;
84

85
  /** Unique identifier for the object. */
86
  @Getter(onMethod_ = {@Override})
87
  @SerializedName("id")
88
  String id;
89

90
  /**
91
   * Has the value {@code true} if the object exists in live mode or the value {@code false} if the
92
   * object exists in test mode.
93
   */
94
  @SerializedName("livemode")
95
  Boolean livemode;
96

97
  /**
98
   * Maximum number of times this coupon can be redeemed, in total, across all customers, before it
99
   * is no longer valid.
100
   */
101
  @SerializedName("max_redemptions")
102
  Long maxRedemptions;
103

104
  /**
105
   * Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach
106
   * to an object. This can be useful for storing additional information about the object in a
107
   * structured format.
108
   */
109
  @Getter(onMethod_ = {@Override})
110
  @SerializedName("metadata")
111
  Map<String, String> metadata;
112

113
  /** Name of the coupon displayed to customers on for instance invoices or receipts. */
114
  @SerializedName("name")
115
  String name;
116

117
  /**
118
   * String representing the object's type. Objects of the same type share the same value.
119
   *
120
   * <p>Equal to {@code coupon}.
121
   */
122
  @SerializedName("object")
123
  String object;
124

125
  /**
126
   * Percent that will be taken off the subtotal of any invoices for this customer for the duration
127
   * of the coupon. For example, a coupon with percent_off of 50 will make a $ (or local
128
   * equivalent)100 invoice $ (or local equivalent)50 instead.
129
   */
130
  @SerializedName("percent_off")
131
  BigDecimal percentOff;
132

133
  /** Date after which the coupon can no longer be redeemed. */
134
  @SerializedName("redeem_by")
135
  Long redeemBy;
136

137
  /** Number of times this coupon has been applied to a customer. */
138
  @SerializedName("times_redeemed")
139
  Long timesRedeemed;
140

141
  /**
142
   * Taking account of the above properties, whether this coupon can still be applied to a customer.
143
   */
144
  @SerializedName("valid")
145
  Boolean valid;
146

147
  /**
148
   * You can create coupons easily via the <a href="https://dashboard.stripe.com/coupons">coupon
149
   * management</a> page of the Stripe dashboard. Coupon creation is also accessible via the API if
150
   * you need to create coupons on the fly.
151
   *
152
   * <p>A coupon has either a {@code percent_off} or an {@code amount_off} and {@code currency}. If
153
   * you set an {@code amount_off}, that amount will be subtracted from any invoice’s subtotal. For
154
   * example, an invoice with a subtotal of 100 will have a final total of 0 if a coupon with an
155
   * {@code amount_off} of 200 is applied to it and an invoice with a subtotal of 300 will have a
156
   * final total of 100 if a coupon with an {@code amount_off} of 200 is applied to it.
157
   */
158
  public static Coupon create(Map<String, Object> params) throws StripeException {
159
    return create(params, (RequestOptions) null);
1✔
160
  }
161

162
  /**
163
   * You can create coupons easily via the <a href="https://dashboard.stripe.com/coupons">coupon
164
   * management</a> page of the Stripe dashboard. Coupon creation is also accessible via the API if
165
   * you need to create coupons on the fly.
166
   *
167
   * <p>A coupon has either a {@code percent_off} or an {@code amount_off} and {@code currency}. If
168
   * you set an {@code amount_off}, that amount will be subtracted from any invoice’s subtotal. For
169
   * example, an invoice with a subtotal of 100 will have a final total of 0 if a coupon with an
170
   * {@code amount_off} of 200 is applied to it and an invoice with a subtotal of 300 will have a
171
   * final total of 100 if a coupon with an {@code amount_off} of 200 is applied to it.
172
   */
173
  public static Coupon create(Map<String, Object> params, RequestOptions options)
174
      throws StripeException {
175
    String path = "/v1/coupons";
1✔
176
    return getGlobalResponseGetter()
1✔
177
        .request(
1✔
178
            BaseAddress.API,
179
            ApiResource.RequestMethod.POST,
180
            path,
181
            params,
182
            Coupon.class,
183
            options,
184
            ApiMode.V1);
185
  }
186

187
  /**
188
   * You can create coupons easily via the <a href="https://dashboard.stripe.com/coupons">coupon
189
   * management</a> page of the Stripe dashboard. Coupon creation is also accessible via the API if
190
   * you need to create coupons on the fly.
191
   *
192
   * <p>A coupon has either a {@code percent_off} or an {@code amount_off} and {@code currency}. If
193
   * you set an {@code amount_off}, that amount will be subtracted from any invoice’s subtotal. For
194
   * example, an invoice with a subtotal of 100 will have a final total of 0 if a coupon with an
195
   * {@code amount_off} of 200 is applied to it and an invoice with a subtotal of 300 will have a
196
   * final total of 100 if a coupon with an {@code amount_off} of 200 is applied to it.
197
   */
198
  public static Coupon create(CouponCreateParams params) throws StripeException {
199
    return create(params, (RequestOptions) null);
1✔
200
  }
201

202
  /**
203
   * You can create coupons easily via the <a href="https://dashboard.stripe.com/coupons">coupon
204
   * management</a> page of the Stripe dashboard. Coupon creation is also accessible via the API if
205
   * you need to create coupons on the fly.
206
   *
207
   * <p>A coupon has either a {@code percent_off} or an {@code amount_off} and {@code currency}. If
208
   * you set an {@code amount_off}, that amount will be subtracted from any invoice’s subtotal. For
209
   * example, an invoice with a subtotal of 100 will have a final total of 0 if a coupon with an
210
   * {@code amount_off} of 200 is applied to it and an invoice with a subtotal of 300 will have a
211
   * final total of 100 if a coupon with an {@code amount_off} of 200 is applied to it.
212
   */
213
  public static Coupon create(CouponCreateParams params, RequestOptions options)
214
      throws StripeException {
215
    String path = "/v1/coupons";
1✔
216
    ApiResource.checkNullTypedParams(path, params);
1✔
217
    return getGlobalResponseGetter()
1✔
218
        .request(
1✔
219
            BaseAddress.API,
220
            ApiResource.RequestMethod.POST,
221
            path,
222
            ApiRequestParams.paramsToMap(params),
1✔
223
            Coupon.class,
224
            options,
225
            ApiMode.V1);
226
  }
227

228
  /**
229
   * You can delete coupons via the <a href="https://dashboard.stripe.com/coupons">coupon
230
   * management</a> page of the Stripe dashboard. However, deleting a coupon does not affect any
231
   * customers who have already applied the coupon; it means that new customers can’t redeem the
232
   * coupon. You can also delete coupons via the API.
233
   */
234
  public Coupon delete() throws StripeException {
235
    return delete((Map<String, Object>) null, (RequestOptions) null);
1✔
236
  }
237

238
  /**
239
   * You can delete coupons via the <a href="https://dashboard.stripe.com/coupons">coupon
240
   * management</a> page of the Stripe dashboard. However, deleting a coupon does not affect any
241
   * customers who have already applied the coupon; it means that new customers can’t redeem the
242
   * coupon. You can also delete coupons via the API.
243
   */
244
  public Coupon delete(RequestOptions options) throws StripeException {
245
    return delete((Map<String, Object>) null, options);
×
246
  }
247

248
  /**
249
   * You can delete coupons via the <a href="https://dashboard.stripe.com/coupons">coupon
250
   * management</a> page of the Stripe dashboard. However, deleting a coupon does not affect any
251
   * customers who have already applied the coupon; it means that new customers can’t redeem the
252
   * coupon. You can also delete coupons via the API.
253
   */
254
  public Coupon delete(Map<String, Object> params) throws StripeException {
255
    return delete(params, (RequestOptions) null);
×
256
  }
257

258
  /**
259
   * You can delete coupons via the <a href="https://dashboard.stripe.com/coupons">coupon
260
   * management</a> page of the Stripe dashboard. However, deleting a coupon does not affect any
261
   * customers who have already applied the coupon; it means that new customers can’t redeem the
262
   * coupon. You can also delete coupons via the API.
263
   */
264
  public Coupon delete(Map<String, Object> params, RequestOptions options) throws StripeException {
265
    String path = String.format("/v1/coupons/%s", ApiResource.urlEncodeId(this.getId()));
1✔
266
    return getResponseGetter()
1✔
267
        .request(
1✔
268
            BaseAddress.API,
269
            ApiResource.RequestMethod.DELETE,
270
            path,
271
            params,
272
            Coupon.class,
273
            options,
274
            ApiMode.V1);
275
  }
276

277
  /** Returns a list of your coupons. */
278
  public static CouponCollection list(Map<String, Object> params) throws StripeException {
279
    return list(params, (RequestOptions) null);
1✔
280
  }
281

282
  /** Returns a list of your coupons. */
283
  public static CouponCollection list(Map<String, Object> params, RequestOptions options)
284
      throws StripeException {
285
    String path = "/v1/coupons";
1✔
286
    return getGlobalResponseGetter()
1✔
287
        .request(
1✔
288
            BaseAddress.API,
289
            ApiResource.RequestMethod.GET,
290
            path,
291
            params,
292
            CouponCollection.class,
293
            options,
294
            ApiMode.V1);
295
  }
296

297
  /** Returns a list of your coupons. */
298
  public static CouponCollection list(CouponListParams params) throws StripeException {
299
    return list(params, (RequestOptions) null);
1✔
300
  }
301

302
  /** Returns a list of your coupons. */
303
  public static CouponCollection list(CouponListParams params, RequestOptions options)
304
      throws StripeException {
305
    String path = "/v1/coupons";
1✔
306
    ApiResource.checkNullTypedParams(path, params);
1✔
307
    return getGlobalResponseGetter()
1✔
308
        .request(
1✔
309
            BaseAddress.API,
310
            ApiResource.RequestMethod.GET,
311
            path,
312
            ApiRequestParams.paramsToMap(params),
1✔
313
            CouponCollection.class,
314
            options,
315
            ApiMode.V1);
316
  }
317

318
  /** Retrieves the coupon with the given ID. */
319
  public static Coupon retrieve(String coupon) throws StripeException {
320
    return retrieve(coupon, (Map<String, Object>) null, (RequestOptions) null);
1✔
321
  }
322

323
  /** Retrieves the coupon with the given ID. */
324
  public static Coupon retrieve(String coupon, RequestOptions options) throws StripeException {
325
    return retrieve(coupon, (Map<String, Object>) null, options);
×
326
  }
327

328
  /** Retrieves the coupon with the given ID. */
329
  public static Coupon retrieve(String coupon, Map<String, Object> params, RequestOptions options)
330
      throws StripeException {
331
    String path = String.format("/v1/coupons/%s", ApiResource.urlEncodeId(coupon));
1✔
332
    return getGlobalResponseGetter()
1✔
333
        .request(
1✔
334
            BaseAddress.API,
335
            ApiResource.RequestMethod.GET,
336
            path,
337
            params,
338
            Coupon.class,
339
            options,
340
            ApiMode.V1);
341
  }
342

343
  /** Retrieves the coupon with the given ID. */
344
  public static Coupon retrieve(String coupon, CouponRetrieveParams params, RequestOptions options)
345
      throws StripeException {
346
    String path = String.format("/v1/coupons/%s", ApiResource.urlEncodeId(coupon));
×
347
    ApiResource.checkNullTypedParams(path, params);
×
348
    return getGlobalResponseGetter()
×
349
        .request(
×
350
            BaseAddress.API,
351
            ApiResource.RequestMethod.GET,
352
            path,
353
            ApiRequestParams.paramsToMap(params),
×
354
            Coupon.class,
355
            options,
356
            ApiMode.V1);
357
  }
358

359
  /**
360
   * Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by
361
   * design, not editable.
362
   */
363
  @Override
364
  public Coupon update(Map<String, Object> params) throws StripeException {
365
    return update(params, (RequestOptions) null);
1✔
366
  }
367

368
  /**
369
   * Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by
370
   * design, not editable.
371
   */
372
  @Override
373
  public Coupon update(Map<String, Object> params, RequestOptions options) throws StripeException {
374
    String path = String.format("/v1/coupons/%s", ApiResource.urlEncodeId(this.getId()));
1✔
375
    return getResponseGetter()
1✔
376
        .request(
1✔
377
            BaseAddress.API,
378
            ApiResource.RequestMethod.POST,
379
            path,
380
            params,
381
            Coupon.class,
382
            options,
383
            ApiMode.V1);
384
  }
385

386
  /**
387
   * Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by
388
   * design, not editable.
389
   */
390
  public Coupon update(CouponUpdateParams params) throws StripeException {
391
    return update(params, (RequestOptions) null);
1✔
392
  }
393

394
  /**
395
   * Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by
396
   * design, not editable.
397
   */
398
  public Coupon update(CouponUpdateParams params, RequestOptions options) throws StripeException {
399
    String path = String.format("/v1/coupons/%s", ApiResource.urlEncodeId(this.getId()));
1✔
400
    ApiResource.checkNullTypedParams(path, params);
1✔
401
    return getResponseGetter()
1✔
402
        .request(
1✔
403
            BaseAddress.API,
404
            ApiResource.RequestMethod.POST,
405
            path,
406
            ApiRequestParams.paramsToMap(params),
1✔
407
            Coupon.class,
408
            options,
409
            ApiMode.V1);
410
  }
411

412
  @Getter
413
  @Setter
414
  @EqualsAndHashCode(callSuper = false)
415
  public static class AppliesTo extends StripeObject {
1✔
416
    /** A list of product IDs this coupon applies to. */
417
    @SerializedName("products")
418
    List<String> products;
419
  }
420

421
  @Getter
422
  @Setter
423
  @EqualsAndHashCode(callSuper = false)
424
  public static class CurrencyOption extends StripeObject {
×
425
    /**
426
     * Amount (in the {@code currency} specified) that will be taken off the subtotal of any
427
     * invoices for this customer.
428
     */
429
    @SerializedName("amount_off")
430
    Long amountOff;
431
  }
432

433
  @Override
434
  public void setResponseGetter(StripeResponseGetter responseGetter) {
435
    super.setResponseGetter(responseGetter);
1✔
436
    trySetResponseGetter(appliesTo, responseGetter);
1✔
437
  }
1✔
438
}
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