• 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

10.0
/src/main/java/com/stripe/model/InvoiceLineItem.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.InvoiceLineItemUpdateParams;
13
import java.math.BigDecimal;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.stream.Collectors;
17
import lombok.EqualsAndHashCode;
18
import lombok.Getter;
19
import lombok.Setter;
20

21
/**
22
 * Invoice Line Items represent the individual lines within an <a
23
 * href="https://stripe.com/docs/api/invoices">invoice</a> and only exist within the context of an
24
 * invoice.
25
 *
26
 * <p>Each line item is backed by either an <a
27
 * href="https://stripe.com/docs/api/invoiceitems">invoice item</a> or a <a
28
 * href="https://stripe.com/docs/api/subscription_items">subscription item</a>.
29
 */
30
@Getter
31
@Setter
32
@EqualsAndHashCode(callSuper = false)
33
public class InvoiceLineItem extends ApiResource implements HasId, MetadataStore<InvoiceLineItem> {
1✔
34
  /** The amount, in cents (or local equivalent). */
35
  @SerializedName("amount")
36
  Long amount;
37

38
  /**
39
   * The integer amount in cents (or local equivalent) representing the amount for this line item,
40
   * excluding all tax and discounts.
41
   */
42
  @SerializedName("amount_excluding_tax")
43
  Long amountExcludingTax;
44

45
  /**
46
   * Three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a>,
47
   * in lowercase. Must be a <a href="https://stripe.com/docs/currencies">supported currency</a>.
48
   */
49
  @SerializedName("currency")
50
  String currency;
51

52
  /** An arbitrary string attached to the object. Often useful for displaying to users. */
53
  @SerializedName("description")
54
  String description;
55

56
  /** The amount of discount calculated per discount for this line item. */
57
  @SerializedName("discount_amounts")
58
  List<InvoiceLineItem.DiscountAmount> discountAmounts;
59

60
  /** If true, discounts will apply to this line item. Always false for prorations. */
61
  @SerializedName("discountable")
62
  Boolean discountable;
63

64
  /**
65
   * The discounts applied to the invoice line item. Line item discounts are applied before invoice
66
   * discounts. Use {@code expand[]=discounts} to expand each discount.
67
   */
68
  @SerializedName("discounts")
69
  List<ExpandableField<Discount>> discounts;
70

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

76
  /** The ID of the invoice that contains this line item. */
77
  @SerializedName("invoice")
78
  String invoice;
79

80
  /**
81
   * The ID of the <a href="https://stripe.com/docs/api/invoiceitems">invoice item</a> associated
82
   * with this line item if any.
83
   */
84
  @SerializedName("invoice_item")
85
  @Getter(lombok.AccessLevel.NONE)
86
  @Setter(lombok.AccessLevel.NONE)
87
  ExpandableField<InvoiceItem> invoiceItem;
88

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

96
  /** The amount of margin calculated per margin for this line item. */
97
  @SerializedName("margin_amounts")
98
  List<InvoiceLineItem.MarginAmount> marginAmounts;
99

100
  /**
101
   * The margins applied to the line item. When set, the {@code default_margins} on the invoice do
102
   * not apply to the line item. Use {@code expand[]=margins} to expand each margin.
103
   */
104
  @SerializedName("margins")
105
  List<ExpandableField<Margin>> margins;
106

107
  /**
108
   * Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach
109
   * to an object. This can be useful for storing additional information about the object in a
110
   * structured format. Note that for line items with {@code type=subscription}, {@code metadata}
111
   * reflects the current metadata from the subscription associated with the line item, unless the
112
   * invoice line was directly updated with different metadata after creation.
113
   */
114
  @Getter(onMethod_ = {@Override})
115
  @SerializedName("metadata")
116
  Map<String, String> metadata;
117

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

126
  @SerializedName("period")
127
  Period period;
128

129
  /** The plan of the subscription, if the line item is a subscription or a proration. */
130
  @SerializedName("plan")
131
  Plan plan;
132

133
  /** The price of the line item. */
134
  @SerializedName("price")
135
  Price price;
136

137
  /** Whether this is a proration. */
138
  @SerializedName("proration")
139
  Boolean proration;
140

141
  /** Additional details for proration line items. */
142
  @SerializedName("proration_details")
143
  ProrationDetails prorationDetails;
144

145
  /** The quantity of the subscription, if the line item is a subscription or a proration. */
146
  @SerializedName("quantity")
147
  Long quantity;
148

149
  /** The subscription that the invoice item pertains to, if any. */
150
  @SerializedName("subscription")
151
  @Getter(lombok.AccessLevel.NONE)
152
  @Setter(lombok.AccessLevel.NONE)
153
  ExpandableField<Subscription> subscription;
154

155
  /**
156
   * The subscription item that generated this line item. Left empty if the line item is not an
157
   * explicit result of a subscription.
158
   */
159
  @SerializedName("subscription_item")
160
  @Getter(lombok.AccessLevel.NONE)
161
  @Setter(lombok.AccessLevel.NONE)
162
  ExpandableField<SubscriptionItem> subscriptionItem;
163

164
  /** The amount of tax calculated per tax rate for this line item. */
165
  @SerializedName("tax_amounts")
166
  List<InvoiceLineItem.TaxAmount> taxAmounts;
167

168
  /** The tax rates which apply to the line item. */
169
  @SerializedName("tax_rates")
170
  List<TaxRate> taxRates;
171

172
  /**
173
   * A string identifying the type of the source of this line item, either an {@code invoiceitem} or
174
   * a {@code subscription}.
175
   *
176
   * <p>One of {@code invoiceitem}, or {@code subscription}.
177
   */
178
  @SerializedName("type")
179
  String type;
180

181
  /**
182
   * The amount in cents (or local equivalent) representing the unit amount for this line item,
183
   * excluding all tax and discounts.
184
   */
185
  @SerializedName("unit_amount_excluding_tax")
186
  BigDecimal unitAmountExcludingTax;
187

188
  /** Get ID of expandable {@code invoiceItem} object. */
189
  public String getInvoiceItem() {
190
    return (this.invoiceItem != null) ? this.invoiceItem.getId() : null;
×
191
  }
192

193
  public void setInvoiceItem(String id) {
194
    this.invoiceItem = ApiResource.setExpandableFieldId(id, this.invoiceItem);
×
195
  }
×
196

197
  /** Get expanded {@code invoiceItem}. */
198
  public InvoiceItem getInvoiceItemObject() {
199
    return (this.invoiceItem != null) ? this.invoiceItem.getExpanded() : null;
×
200
  }
201

202
  public void setInvoiceItemObject(InvoiceItem expandableObject) {
203
    this.invoiceItem = new ExpandableField<InvoiceItem>(expandableObject.getId(), expandableObject);
×
204
  }
×
205

206
  /** Get ID of expandable {@code subscription} object. */
207
  public String getSubscription() {
208
    return (this.subscription != null) ? this.subscription.getId() : null;
×
209
  }
210

211
  public void setSubscription(String id) {
212
    this.subscription = ApiResource.setExpandableFieldId(id, this.subscription);
×
213
  }
×
214

215
  /** Get expanded {@code subscription}. */
216
  public Subscription getSubscriptionObject() {
217
    return (this.subscription != null) ? this.subscription.getExpanded() : null;
×
218
  }
219

220
  public void setSubscriptionObject(Subscription expandableObject) {
221
    this.subscription =
×
222
        new ExpandableField<Subscription>(expandableObject.getId(), expandableObject);
×
223
  }
×
224

225
  /** Get ID of expandable {@code subscriptionItem} object. */
226
  public String getSubscriptionItem() {
227
    return (this.subscriptionItem != null) ? this.subscriptionItem.getId() : null;
×
228
  }
229

230
  public void setSubscriptionItem(String id) {
231
    this.subscriptionItem = ApiResource.setExpandableFieldId(id, this.subscriptionItem);
×
232
  }
×
233

234
  /** Get expanded {@code subscriptionItem}. */
235
  public SubscriptionItem getSubscriptionItemObject() {
236
    return (this.subscriptionItem != null) ? this.subscriptionItem.getExpanded() : null;
×
237
  }
238

239
  public void setSubscriptionItemObject(SubscriptionItem expandableObject) {
240
    this.subscriptionItem =
×
241
        new ExpandableField<SubscriptionItem>(expandableObject.getId(), expandableObject);
×
242
  }
×
243

244
  /** Get IDs of expandable {@code discounts} object list. */
245
  public List<String> getDiscounts() {
246
    return (this.discounts != null)
×
247
        ? this.discounts.stream().map(x -> x.getId()).collect(Collectors.toList())
×
248
        : null;
×
249
  }
250

251
  public void setDiscounts(List<String> ids) {
252
    if (ids == null) {
×
253
      this.discounts = null;
×
254
      return;
×
255
    }
256
    if (this.discounts != null
×
257
        && this.discounts.stream().map(x -> x.getId()).collect(Collectors.toList()).equals(ids)) {
×
258
      // noop if the ids are equal to what are already present
259
      return;
×
260
    }
261
    this.discounts =
×
262
        (ids != null)
×
263
            ? ids.stream()
×
264
                .map(id -> new ExpandableField<Discount>(id, null))
×
265
                .collect(Collectors.toList())
×
266
            : null;
×
267
  }
×
268

269
  /** Get expanded {@code discounts}. */
270
  public List<Discount> getDiscountObjects() {
271
    return (this.discounts != null)
×
272
        ? this.discounts.stream().map(x -> x.getExpanded()).collect(Collectors.toList())
×
273
        : null;
×
274
  }
275

276
  public void setDiscountObjects(List<Discount> objs) {
277
    this.discounts =
×
278
        objs != null
×
279
            ? objs.stream()
×
280
                .map(x -> new ExpandableField<Discount>(x.getId(), x))
×
281
                .collect(Collectors.toList())
×
282
            : null;
×
283
  }
×
284

285
  /** Get IDs of expandable {@code margins} object list. */
286
  public List<String> getMargins() {
287
    return (this.margins != null)
×
288
        ? this.margins.stream().map(x -> x.getId()).collect(Collectors.toList())
×
289
        : null;
×
290
  }
291

292
  public void setMargins(List<String> ids) {
293
    if (ids == null) {
×
294
      this.margins = null;
×
295
      return;
×
296
    }
297
    if (this.margins != null
×
298
        && this.margins.stream().map(x -> x.getId()).collect(Collectors.toList()).equals(ids)) {
×
299
      // noop if the ids are equal to what are already present
300
      return;
×
301
    }
302
    this.margins =
×
303
        (ids != null)
×
304
            ? ids.stream()
×
305
                .map(id -> new ExpandableField<Margin>(id, null))
×
306
                .collect(Collectors.toList())
×
307
            : null;
×
308
  }
×
309

310
  /** Get expanded {@code margins}. */
311
  public List<Margin> getMarginObjects() {
312
    return (this.margins != null)
×
313
        ? this.margins.stream().map(x -> x.getExpanded()).collect(Collectors.toList())
×
314
        : null;
×
315
  }
316

317
  public void setMarginObjects(List<Margin> objs) {
318
    this.margins =
×
319
        objs != null
×
320
            ? objs.stream()
×
321
                .map(x -> new ExpandableField<Margin>(x.getId(), x))
×
322
                .collect(Collectors.toList())
×
323
            : null;
×
324
  }
×
325

326
  /**
327
   * Updates an invoice’s line item. Some fields, such as {@code tax_amounts}, only live on the
328
   * invoice line item, so they can only be updated through this endpoint. Other fields, such as
329
   * {@code amount}, live on both the invoice item and the invoice line item, so updates on this
330
   * endpoint will propagate to the invoice item as well. Updating an invoice’s line item is only
331
   * possible before the invoice is finalized.
332
   */
333
  @Override
334
  public InvoiceLineItem update(Map<String, Object> params) throws StripeException {
335
    return update(params, (RequestOptions) null);
×
336
  }
337

338
  /**
339
   * Updates an invoice’s line item. Some fields, such as {@code tax_amounts}, only live on the
340
   * invoice line item, so they can only be updated through this endpoint. Other fields, such as
341
   * {@code amount}, live on both the invoice item and the invoice line item, so updates on this
342
   * endpoint will propagate to the invoice item as well. Updating an invoice’s line item is only
343
   * possible before the invoice is finalized.
344
   */
345
  @Override
346
  public InvoiceLineItem update(Map<String, Object> params, RequestOptions options)
347
      throws StripeException {
348
    String path =
×
349
        String.format(
×
350
            "/v1/invoices/%s/lines/%s",
351
            ApiResource.urlEncodeId(this.getInvoice()), ApiResource.urlEncodeId(this.getId()));
×
352
    ApiRequest request =
×
353
        new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.POST, path, params, options);
UNCOV
354
    return getResponseGetter().request(request, InvoiceLineItem.class);
×
355
  }
356

357
  /**
358
   * Updates an invoice’s line item. Some fields, such as {@code tax_amounts}, only live on the
359
   * invoice line item, so they can only be updated through this endpoint. Other fields, such as
360
   * {@code amount}, live on both the invoice item and the invoice line item, so updates on this
361
   * endpoint will propagate to the invoice item as well. Updating an invoice’s line item is only
362
   * possible before the invoice is finalized.
363
   */
364
  public InvoiceLineItem update(InvoiceLineItemUpdateParams params) throws StripeException {
365
    return update(params, (RequestOptions) null);
×
366
  }
367

368
  /**
369
   * Updates an invoice’s line item. Some fields, such as {@code tax_amounts}, only live on the
370
   * invoice line item, so they can only be updated through this endpoint. Other fields, such as
371
   * {@code amount}, live on both the invoice item and the invoice line item, so updates on this
372
   * endpoint will propagate to the invoice item as well. Updating an invoice’s line item is only
373
   * possible before the invoice is finalized.
374
   */
375
  public InvoiceLineItem update(InvoiceLineItemUpdateParams params, RequestOptions options)
376
      throws StripeException {
377
    String path =
×
378
        String.format(
×
379
            "/v1/invoices/%s/lines/%s",
380
            ApiResource.urlEncodeId(this.getInvoice()), ApiResource.urlEncodeId(this.getId()));
×
381
    ApiResource.checkNullTypedParams(path, params);
×
382
    ApiRequest request =
×
383
        new ApiRequest(
384
            BaseAddress.API,
385
            ApiResource.RequestMethod.POST,
386
            path,
387
            ApiRequestParams.paramsToMap(params),
×
388
            options);
UNCOV
389
    return getResponseGetter().request(request, InvoiceLineItem.class);
×
390
  }
391

392
  @Getter
393
  @Setter
394
  @EqualsAndHashCode(callSuper = false)
395
  public static class DiscountAmount extends StripeObject {
×
396
    /** The amount, in cents (or local equivalent), of the discount. */
397
    @SerializedName("amount")
398
    Long amount;
399

400
    /** The discount that was applied to get this discount amount. */
401
    @SerializedName("discount")
402
    @Getter(lombok.AccessLevel.NONE)
403
    @Setter(lombok.AccessLevel.NONE)
404
    ExpandableField<Discount> discount;
405

406
    /** Get ID of expandable {@code discount} object. */
407
    public String getDiscount() {
408
      return (this.discount != null) ? this.discount.getId() : null;
×
409
    }
410

411
    public void setDiscount(String id) {
412
      this.discount = ApiResource.setExpandableFieldId(id, this.discount);
×
413
    }
×
414

415
    /** Get expanded {@code discount}. */
416
    public Discount getDiscountObject() {
417
      return (this.discount != null) ? this.discount.getExpanded() : null;
×
418
    }
419

420
    public void setDiscountObject(Discount expandableObject) {
421
      this.discount = new ExpandableField<Discount>(expandableObject.getId(), expandableObject);
×
422
    }
×
423
  }
424

425
  @Getter
426
  @Setter
427
  @EqualsAndHashCode(callSuper = false)
428
  public static class MarginAmount extends StripeObject {
×
429
    /** The amount, in cents (or local equivalent), of the reduction in line item amount. */
430
    @SerializedName("amount")
431
    Long amount;
432

433
    /** The margin that was applied to get this margin amount. */
434
    @SerializedName("margin")
435
    @Getter(lombok.AccessLevel.NONE)
436
    @Setter(lombok.AccessLevel.NONE)
437
    ExpandableField<Margin> margin;
438

439
    /** Get ID of expandable {@code margin} object. */
440
    public String getMargin() {
441
      return (this.margin != null) ? this.margin.getId() : null;
×
442
    }
443

444
    public void setMargin(String id) {
445
      this.margin = ApiResource.setExpandableFieldId(id, this.margin);
×
446
    }
×
447

448
    /** Get expanded {@code margin}. */
449
    public Margin getMarginObject() {
450
      return (this.margin != null) ? this.margin.getExpanded() : null;
×
451
    }
452

453
    public void setMarginObject(Margin expandableObject) {
454
      this.margin = new ExpandableField<Margin>(expandableObject.getId(), expandableObject);
×
455
    }
×
456
  }
457

458
  @Getter
459
  @Setter
460
  @EqualsAndHashCode(callSuper = false)
461
  public static class Period extends StripeObject {
1✔
462
    /**
463
     * The end of the period, which must be greater than or equal to the start. This value is
464
     * inclusive.
465
     */
466
    @SerializedName("end")
467
    Long end;
468

469
    /** The start of the period. This value is inclusive. */
470
    @SerializedName("start")
471
    Long start;
472
  }
473

474
  @Getter
475
  @Setter
476
  @EqualsAndHashCode(callSuper = false)
477
  public static class ProrationDetails extends StripeObject {
1✔
478
    /**
479
     * For a credit proration {@code line_item}, the original debit line_items to which the credit
480
     * proration applies.
481
     */
482
    @SerializedName("credited_items")
483
    CreditedItems creditedItems;
484

485
    @Getter
486
    @Setter
487
    @EqualsAndHashCode(callSuper = false)
488
    public static class CreditedItems extends StripeObject {
×
489
      /** Invoice containing the credited invoice line items. */
490
      @SerializedName("invoice")
491
      String invoice;
492

493
      /** Credited invoice line items. */
494
      @SerializedName("invoice_line_items")
495
      List<String> invoiceLineItems;
496
    }
497
  }
498

499
  @Getter
500
  @Setter
501
  @EqualsAndHashCode(callSuper = false)
502
  public static class TaxAmount extends StripeObject {
×
503
    /** The amount, in cents (or local equivalent), of the tax. */
504
    @SerializedName("amount")
505
    Long amount;
506

507
    /** Whether this tax amount is inclusive or exclusive. */
508
    @SerializedName("inclusive")
509
    Boolean inclusive;
510

511
    /** The tax rate that was applied to get this tax amount. */
512
    @SerializedName("tax_rate")
513
    @Getter(lombok.AccessLevel.NONE)
514
    @Setter(lombok.AccessLevel.NONE)
515
    ExpandableField<TaxRate> taxRate;
516

517
    /**
518
     * The reasoning behind this tax, for example, if the product is tax exempt. The possible values
519
     * for this field may be extended as new tax rules are supported.
520
     *
521
     * <p>One of {@code customer_exempt}, {@code not_collecting}, {@code not_subject_to_tax}, {@code
522
     * not_supported}, {@code portion_product_exempt}, {@code portion_reduced_rated}, {@code
523
     * portion_standard_rated}, {@code product_exempt}, {@code product_exempt_holiday}, {@code
524
     * proportionally_rated}, {@code reduced_rated}, {@code reverse_charge}, {@code standard_rated},
525
     * {@code taxable_basis_reduced}, or {@code zero_rated}.
526
     */
527
    @SerializedName("taxability_reason")
528
    String taxabilityReason;
529

530
    /** The amount on which tax is calculated, in cents (or local equivalent). */
531
    @SerializedName("taxable_amount")
532
    Long taxableAmount;
533

534
    /** Get ID of expandable {@code taxRate} object. */
535
    public String getTaxRate() {
536
      return (this.taxRate != null) ? this.taxRate.getId() : null;
×
537
    }
538

539
    public void setTaxRate(String id) {
540
      this.taxRate = ApiResource.setExpandableFieldId(id, this.taxRate);
×
541
    }
×
542

543
    /** Get expanded {@code taxRate}. */
544
    public TaxRate getTaxRateObject() {
545
      return (this.taxRate != null) ? this.taxRate.getExpanded() : null;
×
546
    }
547

548
    public void setTaxRateObject(TaxRate expandableObject) {
549
      this.taxRate = new ExpandableField<TaxRate>(expandableObject.getId(), expandableObject);
×
550
    }
×
551
  }
552

553
  @Override
554
  public void setResponseGetter(StripeResponseGetter responseGetter) {
555
    super.setResponseGetter(responseGetter);
1✔
556
    trySetResponseGetter(invoiceItem, responseGetter);
1✔
557
    trySetResponseGetter(period, responseGetter);
1✔
558
    trySetResponseGetter(plan, responseGetter);
1✔
559
    trySetResponseGetter(price, responseGetter);
1✔
560
    trySetResponseGetter(prorationDetails, responseGetter);
1✔
561
    trySetResponseGetter(subscription, responseGetter);
1✔
562
    trySetResponseGetter(subscriptionItem, responseGetter);
1✔
563
  }
1✔
564
}
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