-
Notifications
You must be signed in to change notification settings - Fork 355
/
InvoiceLineItem.java
558 lines (479 loc) · 19.1 KB
/
InvoiceLineItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
// File generated from our OpenAPI spec
package com.stripe.model;
import com.google.gson.annotations.SerializedName;
import com.stripe.exception.StripeException;
import com.stripe.net.ApiMode;
import com.stripe.net.ApiRequest;
import com.stripe.net.ApiRequestParams;
import com.stripe.net.ApiResource;
import com.stripe.net.BaseAddress;
import com.stripe.net.RequestOptions;
import com.stripe.net.StripeResponseGetter;
import com.stripe.param.InvoiceLineItemUpdateParams;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public class InvoiceLineItem extends ApiResource implements HasId, MetadataStore<InvoiceLineItem> {
/** The amount, in cents (or local equivalent). */
@SerializedName("amount")
Long amount;
/**
* The integer amount in cents (or local equivalent) representing the amount for this line item,
* excluding all tax and discounts.
*/
@SerializedName("amount_excluding_tax")
Long amountExcludingTax;
/**
* Three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a>,
* in lowercase. Must be a <a href="https://stripe.com/docs/currencies">supported currency</a>.
*/
@SerializedName("currency")
String currency;
/** An arbitrary string attached to the object. Often useful for displaying to users. */
@SerializedName("description")
String description;
/** The amount of discount calculated per discount for this line item. */
@SerializedName("discount_amounts")
List<InvoiceLineItem.DiscountAmount> discountAmounts;
/** If true, discounts will apply to this line item. Always false for prorations. */
@SerializedName("discountable")
Boolean discountable;
/**
* The discounts applied to the invoice line item. Line item discounts are applied before invoice
* discounts. Use {@code expand[]=discounts} to expand each discount.
*/
@SerializedName("discounts")
List<ExpandableField<Discount>> discounts;
/** Unique identifier for the object. */
@Getter(onMethod_ = {@Override})
@SerializedName("id")
String id;
/** The ID of the invoice that contains this line item. */
@SerializedName("invoice")
String invoice;
/**
* The ID of the <a href="https://stripe.com/docs/api/invoiceitems">invoice item</a> associated
* with this line item if any.
*/
@SerializedName("invoice_item")
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
ExpandableField<InvoiceItem> invoiceItem;
/**
* Has the value {@code true} if the object exists in live mode or the value {@code false} if the
* object exists in test mode.
*/
@SerializedName("livemode")
Boolean livemode;
/** The amount of margin calculated per margin for this line item. */
@SerializedName("margin_amounts")
List<InvoiceLineItem.MarginAmount> marginAmounts;
/**
* The margins applied to the line item. When set, the {@code default_margins} on the invoice do
* not apply to the line item. Use {@code expand[]=margins} to expand each margin.
*/
@SerializedName("margins")
List<ExpandableField<Margin>> margins;
/**
* Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach
* to an object. This can be useful for storing additional information about the object in a
* structured format. Note that for line items with {@code type=subscription}, {@code metadata}
* reflects the current metadata from the subscription associated with the line item, unless the
* invoice line was directly updated with different metadata after creation.
*/
@Getter(onMethod_ = {@Override})
@SerializedName("metadata")
Map<String, String> metadata;
/**
* String representing the object's type. Objects of the same type share the same value.
*
* <p>Equal to {@code line_item}.
*/
@SerializedName("object")
String object;
@SerializedName("period")
Period period;
/** The plan of the subscription, if the line item is a subscription or a proration. */
@SerializedName("plan")
Plan plan;
/** The price of the line item. */
@SerializedName("price")
Price price;
/** Whether this is a proration. */
@SerializedName("proration")
Boolean proration;
/** Additional details for proration line items. */
@SerializedName("proration_details")
ProrationDetails prorationDetails;
/** The quantity of the subscription, if the line item is a subscription or a proration. */
@SerializedName("quantity")
Long quantity;
/** The subscription that the invoice item pertains to, if any. */
@SerializedName("subscription")
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
ExpandableField<Subscription> subscription;
/**
* The subscription item that generated this line item. Left empty if the line item is not an
* explicit result of a subscription.
*/
@SerializedName("subscription_item")
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
ExpandableField<SubscriptionItem> subscriptionItem;
/** The amount of tax calculated per tax rate for this line item. */
@SerializedName("tax_amounts")
List<InvoiceLineItem.TaxAmount> taxAmounts;
/** The tax rates which apply to the line item. */
@SerializedName("tax_rates")
List<TaxRate> taxRates;
/**
* A string identifying the type of the source of this line item, either an {@code invoiceitem} or
* a {@code subscription}.
*
* <p>One of {@code invoiceitem}, or {@code subscription}.
*/
@SerializedName("type")
String type;
/**
* The amount in cents (or local equivalent) representing the unit amount for this line item,
* excluding all tax and discounts.
*/
@SerializedName("unit_amount_excluding_tax")
BigDecimal unitAmountExcludingTax;
/** Get ID of expandable {@code invoiceItem} object. */
public String getInvoiceItem() {
return (this.invoiceItem != null) ? this.invoiceItem.getId() : null;
}
public void setInvoiceItem(String id) {
this.invoiceItem = ApiResource.setExpandableFieldId(id, this.invoiceItem);
}
/** Get expanded {@code invoiceItem}. */
public InvoiceItem getInvoiceItemObject() {
return (this.invoiceItem != null) ? this.invoiceItem.getExpanded() : null;
}
public void setInvoiceItemObject(InvoiceItem expandableObject) {
this.invoiceItem = new ExpandableField<InvoiceItem>(expandableObject.getId(), expandableObject);
}
/** Get ID of expandable {@code subscription} object. */
public String getSubscription() {
return (this.subscription != null) ? this.subscription.getId() : null;
}
public void setSubscription(String id) {
this.subscription = ApiResource.setExpandableFieldId(id, this.subscription);
}
/** Get expanded {@code subscription}. */
public Subscription getSubscriptionObject() {
return (this.subscription != null) ? this.subscription.getExpanded() : null;
}
public void setSubscriptionObject(Subscription expandableObject) {
this.subscription =
new ExpandableField<Subscription>(expandableObject.getId(), expandableObject);
}
/** Get ID of expandable {@code subscriptionItem} object. */
public String getSubscriptionItem() {
return (this.subscriptionItem != null) ? this.subscriptionItem.getId() : null;
}
public void setSubscriptionItem(String id) {
this.subscriptionItem = ApiResource.setExpandableFieldId(id, this.subscriptionItem);
}
/** Get expanded {@code subscriptionItem}. */
public SubscriptionItem getSubscriptionItemObject() {
return (this.subscriptionItem != null) ? this.subscriptionItem.getExpanded() : null;
}
public void setSubscriptionItemObject(SubscriptionItem expandableObject) {
this.subscriptionItem =
new ExpandableField<SubscriptionItem>(expandableObject.getId(), expandableObject);
}
/** Get IDs of expandable {@code discounts} object list. */
public List<String> getDiscounts() {
return (this.discounts != null)
? this.discounts.stream().map(x -> x.getId()).collect(Collectors.toList())
: null;
}
public void setDiscounts(List<String> ids) {
if (ids == null) {
this.discounts = null;
return;
}
if (this.discounts != null
&& this.discounts.stream().map(x -> x.getId()).collect(Collectors.toList()).equals(ids)) {
// noop if the ids are equal to what are already present
return;
}
this.discounts =
(ids != null)
? ids.stream()
.map(id -> new ExpandableField<Discount>(id, null))
.collect(Collectors.toList())
: null;
}
/** Get expanded {@code discounts}. */
public List<Discount> getDiscountObjects() {
return (this.discounts != null)
? this.discounts.stream().map(x -> x.getExpanded()).collect(Collectors.toList())
: null;
}
public void setDiscountObjects(List<Discount> objs) {
this.discounts =
objs != null
? objs.stream()
.map(x -> new ExpandableField<Discount>(x.getId(), x))
.collect(Collectors.toList())
: null;
}
/** Get IDs of expandable {@code margins} object list. */
public List<String> getMargins() {
return (this.margins != null)
? this.margins.stream().map(x -> x.getId()).collect(Collectors.toList())
: null;
}
public void setMargins(List<String> ids) {
if (ids == null) {
this.margins = null;
return;
}
if (this.margins != null
&& this.margins.stream().map(x -> x.getId()).collect(Collectors.toList()).equals(ids)) {
// noop if the ids are equal to what are already present
return;
}
this.margins =
(ids != null)
? ids.stream()
.map(id -> new ExpandableField<Margin>(id, null))
.collect(Collectors.toList())
: null;
}
/** Get expanded {@code margins}. */
public List<Margin> getMarginObjects() {
return (this.margins != null)
? this.margins.stream().map(x -> x.getExpanded()).collect(Collectors.toList())
: null;
}
public void setMarginObjects(List<Margin> objs) {
this.margins =
objs != null
? objs.stream()
.map(x -> new ExpandableField<Margin>(x.getId(), x))
.collect(Collectors.toList())
: null;
}
/**
* Updates an invoice’s line item. Some fields, such as {@code tax_amounts}, only live on the
* invoice line item, so they can only be updated through this endpoint. Other fields, such as
* {@code amount}, live on both the invoice item and the invoice line item, so updates on this
* endpoint will propagate to the invoice item as well. Updating an invoice’s line item is only
* possible before the invoice is finalized.
*/
@Override
public InvoiceLineItem update(Map<String, Object> params) throws StripeException {
return update(params, (RequestOptions) null);
}
/**
* Updates an invoice’s line item. Some fields, such as {@code tax_amounts}, only live on the
* invoice line item, so they can only be updated through this endpoint. Other fields, such as
* {@code amount}, live on both the invoice item and the invoice line item, so updates on this
* endpoint will propagate to the invoice item as well. Updating an invoice’s line item is only
* possible before the invoice is finalized.
*/
@Override
public InvoiceLineItem update(Map<String, Object> params, RequestOptions options)
throws StripeException {
String path =
String.format(
"/v1/invoices/%s/lines/%s",
ApiResource.urlEncodeId(this.getInvoice()), ApiResource.urlEncodeId(this.getId()));
ApiRequest request =
new ApiRequest(
BaseAddress.API, ApiResource.RequestMethod.POST, path, params, options, ApiMode.V1);
return getResponseGetter().request(request, InvoiceLineItem.class);
}
/**
* Updates an invoice’s line item. Some fields, such as {@code tax_amounts}, only live on the
* invoice line item, so they can only be updated through this endpoint. Other fields, such as
* {@code amount}, live on both the invoice item and the invoice line item, so updates on this
* endpoint will propagate to the invoice item as well. Updating an invoice’s line item is only
* possible before the invoice is finalized.
*/
public InvoiceLineItem update(InvoiceLineItemUpdateParams params) throws StripeException {
return update(params, (RequestOptions) null);
}
/**
* Updates an invoice’s line item. Some fields, such as {@code tax_amounts}, only live on the
* invoice line item, so they can only be updated through this endpoint. Other fields, such as
* {@code amount}, live on both the invoice item and the invoice line item, so updates on this
* endpoint will propagate to the invoice item as well. Updating an invoice’s line item is only
* possible before the invoice is finalized.
*/
public InvoiceLineItem update(InvoiceLineItemUpdateParams params, RequestOptions options)
throws StripeException {
String path =
String.format(
"/v1/invoices/%s/lines/%s",
ApiResource.urlEncodeId(this.getInvoice()), ApiResource.urlEncodeId(this.getId()));
ApiResource.checkNullTypedParams(path, params);
ApiRequest request =
new ApiRequest(
BaseAddress.API,
ApiResource.RequestMethod.POST,
path,
ApiRequestParams.paramsToMap(params),
options,
ApiMode.V1);
return getResponseGetter().request(request, InvoiceLineItem.class);
}
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public static class DiscountAmount extends StripeObject {
/** The amount, in cents (or local equivalent), of the discount. */
@SerializedName("amount")
Long amount;
/** The discount that was applied to get this discount amount. */
@SerializedName("discount")
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
ExpandableField<Discount> discount;
/** Get ID of expandable {@code discount} object. */
public String getDiscount() {
return (this.discount != null) ? this.discount.getId() : null;
}
public void setDiscount(String id) {
this.discount = ApiResource.setExpandableFieldId(id, this.discount);
}
/** Get expanded {@code discount}. */
public Discount getDiscountObject() {
return (this.discount != null) ? this.discount.getExpanded() : null;
}
public void setDiscountObject(Discount expandableObject) {
this.discount = new ExpandableField<Discount>(expandableObject.getId(), expandableObject);
}
}
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public static class MarginAmount extends StripeObject {
/** The amount, in cents (or local equivalent), of the reduction in line item amount. */
@SerializedName("amount")
Long amount;
/** The margin that was applied to get this margin amount. */
@SerializedName("margin")
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
ExpandableField<Margin> margin;
/** Get ID of expandable {@code margin} object. */
public String getMargin() {
return (this.margin != null) ? this.margin.getId() : null;
}
public void setMargin(String id) {
this.margin = ApiResource.setExpandableFieldId(id, this.margin);
}
/** Get expanded {@code margin}. */
public Margin getMarginObject() {
return (this.margin != null) ? this.margin.getExpanded() : null;
}
public void setMarginObject(Margin expandableObject) {
this.margin = new ExpandableField<Margin>(expandableObject.getId(), expandableObject);
}
}
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public static class Period extends StripeObject {
/**
* The end of the period, which must be greater than or equal to the start. This value is
* inclusive.
*/
@SerializedName("end")
Long end;
/** The start of the period. This value is inclusive. */
@SerializedName("start")
Long start;
}
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public static class ProrationDetails extends StripeObject {
/**
* For a credit proration {@code line_item}, the original debit line_items to which the credit
* proration applies.
*/
@SerializedName("credited_items")
CreditedItems creditedItems;
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public static class CreditedItems extends StripeObject {
/** Invoice containing the credited invoice line items. */
@SerializedName("invoice")
String invoice;
/** Credited invoice line items. */
@SerializedName("invoice_line_items")
List<String> invoiceLineItems;
}
}
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public static class TaxAmount extends StripeObject {
/** The amount, in cents (or local equivalent), of the tax. */
@SerializedName("amount")
Long amount;
/** Whether this tax amount is inclusive or exclusive. */
@SerializedName("inclusive")
Boolean inclusive;
/** The tax rate that was applied to get this tax amount. */
@SerializedName("tax_rate")
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
ExpandableField<TaxRate> taxRate;
/**
* The reasoning behind this tax, for example, if the product is tax exempt. The possible values
* for this field may be extended as new tax rules are supported.
*
* <p>One of {@code customer_exempt}, {@code not_collecting}, {@code not_subject_to_tax}, {@code
* not_supported}, {@code portion_product_exempt}, {@code portion_reduced_rated}, {@code
* portion_standard_rated}, {@code product_exempt}, {@code product_exempt_holiday}, {@code
* proportionally_rated}, {@code reduced_rated}, {@code reverse_charge}, {@code standard_rated},
* {@code taxable_basis_reduced}, or {@code zero_rated}.
*/
@SerializedName("taxability_reason")
String taxabilityReason;
/** The amount on which tax is calculated, in cents (or local equivalent). */
@SerializedName("taxable_amount")
Long taxableAmount;
/** Get ID of expandable {@code taxRate} object. */
public String getTaxRate() {
return (this.taxRate != null) ? this.taxRate.getId() : null;
}
public void setTaxRate(String id) {
this.taxRate = ApiResource.setExpandableFieldId(id, this.taxRate);
}
/** Get expanded {@code taxRate}. */
public TaxRate getTaxRateObject() {
return (this.taxRate != null) ? this.taxRate.getExpanded() : null;
}
public void setTaxRateObject(TaxRate expandableObject) {
this.taxRate = new ExpandableField<TaxRate>(expandableObject.getId(), expandableObject);
}
}
@Override
public void setResponseGetter(StripeResponseGetter responseGetter) {
super.setResponseGetter(responseGetter);
trySetResponseGetter(invoiceItem, responseGetter);
trySetResponseGetter(period, responseGetter);
trySetResponseGetter(plan, responseGetter);
trySetResponseGetter(price, responseGetter);
trySetResponseGetter(prorationDetails, responseGetter);
trySetResponseGetter(subscription, responseGetter);
trySetResponseGetter(subscriptionItem, responseGetter);
}
}