From 0cff72f260e4a11e680868d7a3e129d08bea897b Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 21 Nov 2023 12:54:52 -0800 Subject: [PATCH 1/9] wip --- .../com/stripe/model/InvoiceLineItem.java | 95 +- .../param/InvoiceLineItemUpdateParams.java | 1590 +++++++++++++++++ .../service/InvoiceLineItemService.java | 58 + 3 files changed, 1742 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/stripe/param/InvoiceLineItemUpdateParams.java diff --git a/src/main/java/com/stripe/model/InvoiceLineItem.java b/src/main/java/com/stripe/model/InvoiceLineItem.java index 011e4b30a70..9948ab86987 100644 --- a/src/main/java/com/stripe/model/InvoiceLineItem.java +++ b/src/main/java/com/stripe/model/InvoiceLineItem.java @@ -2,7 +2,14 @@ package com.stripe.model; import com.google.gson.annotations.SerializedName; +import com.stripe.exception.StripeException; +import com.stripe.net.ApiMode; +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; @@ -14,7 +21,7 @@ @Getter @Setter @EqualsAndHashCode(callSuper = false) -public class InvoiceLineItem extends StripeObject implements HasId { +public class InvoiceLineItem extends ApiResource implements HasId, MetadataStore { /** The amount, in cents (or local equivalent). */ @SerializedName("amount") Long amount; @@ -79,6 +86,7 @@ public class InvoiceLineItem extends StripeObject implements HasId { * structured format. Note that for line items with {@code type=subscription} this will reflect * the metadata of the subscription that caused the line item to be created. */ + @Getter(onMethod_ = {@Override}) @SerializedName("metadata") Map metadata; @@ -249,6 +257,79 @@ public void setDiscountObjects(List objs) { : 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(String invoice, Map params) throws StripeException { + return update(invoice, 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(String invoice, Map params, RequestOptions options) + throws StripeException { + String path = + String.format( + "/v1/invoices/%s/lines/%s", + ApiResource.urlEncodeId(invoice), ApiResource.urlEncodeId(this.getId())); + return getResponseGetter() + .request( + BaseAddress.API, + ApiResource.RequestMethod.POST, + path, + params, + InvoiceLineItem.class, + options, + ApiMode.V1); + } + + /** + * 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(String invoice, InvoiceLineItemUpdateParams params) + throws StripeException { + return update(invoice, 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( + String invoice, InvoiceLineItemUpdateParams params, RequestOptions options) + throws StripeException { + String path = + String.format( + "/v1/invoices/%s/lines/%s", + ApiResource.urlEncodeId(invoice), ApiResource.urlEncodeId(this.getId())); + ApiResource.checkNullTypedParams(path, params); + return getResponseGetter() + .request( + BaseAddress.API, + ApiResource.RequestMethod.POST, + path, + ApiRequestParams.paramsToMap(params), + InvoiceLineItem.class, + options, + ApiMode.V1); + } + @Getter @Setter @EqualsAndHashCode(callSuper = false) @@ -376,4 +457,16 @@ public void setTaxRateObject(TaxRate expandableObject) { this.taxRate = new ExpandableField(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); + } } diff --git a/src/main/java/com/stripe/param/InvoiceLineItemUpdateParams.java b/src/main/java/com/stripe/param/InvoiceLineItemUpdateParams.java new file mode 100644 index 00000000000..a0bc54f9bdc --- /dev/null +++ b/src/main/java/com/stripe/param/InvoiceLineItemUpdateParams.java @@ -0,0 +1,1590 @@ +// File generated from our OpenAPI spec +package com.stripe.param; + +import com.google.gson.annotations.SerializedName; +import com.stripe.net.ApiRequestParams; +import com.stripe.param.common.EmptyParam; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import lombok.Getter; + +@Getter +public class InvoiceLineItemUpdateParams extends ApiRequestParams { + /** + * The integer amount in cents (or local equivalent) of the charge to be applied to the upcoming + * invoice. If you want to apply a credit to the customer's account, pass a negative amount. + */ + @SerializedName("amount") + Long amount; + + /** + * An arbitrary string which you can attach to the invoice item. The description is displayed in + * the invoice for easy tracking. + */ + @SerializedName("description") + Object description; + + /** + * Controls whether discounts apply to this line item. Defaults to false for prorations or + * negative line items, and true for all other line items. Cannot be set to true for prorations. + */ + @SerializedName("discountable") + Boolean discountable; + + /** + * The coupons & existing discounts which apply to the line item. Item discounts are applied + * before invoice discounts. Pass an empty string to remove previously-defined discounts. + */ + @SerializedName("discounts") + Object discounts; + + /** Specifies which fields in the response should be expanded. */ + @SerializedName("expand") + List expand; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** + * Set of key-value pairs that you can attach + * to an object. This can be useful for storing additional information about the object in a + * structured format. Individual keys can be unset by posting an empty value to them. All keys can + * be unset by posting an empty value to {@code metadata}. + */ + @SerializedName("metadata") + Object metadata; + + /** + * The period associated with this invoice item. When set to different values, the period will be + * rendered on the invoice. If you have Stripe Revenue Recognition enabled, the + * period will be used to recognize and defer revenue. See the Revenue + * Recognition documentation for details. + */ + @SerializedName("period") + Period period; + + /** The ID of the price object. */ + @SerializedName("price") + Object price; + + /** + * Data used to generate a new Price object + * inline. + */ + @SerializedName("price_data") + PriceData priceData; + + /** Non-negative integer. The quantity of units for the line item. */ + @SerializedName("quantity") + Long quantity; + + /** + * A list of up to 10 tax amounts for this line item. This can be useful if you calculate taxes on + * your own or use a third-party to calculate them. You cannot set tax amounts if any line item + * has tax_rates + * or if the invoice has default_tax_rates + * or uses automatic tax. Pass an empty string + * to remove previously defined tax amounts. + */ + @SerializedName("tax_amounts") + Object taxAmounts; + + /** + * The tax rates which apply to the line item. When set, the {@code default_tax_rates} on the + * invoice do not apply to this line item. Pass an empty string to remove previously-defined tax + * rates. + */ + @SerializedName("tax_rates") + Object taxRates; + + private InvoiceLineItemUpdateParams( + Long amount, + Object description, + Boolean discountable, + Object discounts, + List expand, + Map extraParams, + Object metadata, + Period period, + Object price, + PriceData priceData, + Long quantity, + Object taxAmounts, + Object taxRates) { + this.amount = amount; + this.description = description; + this.discountable = discountable; + this.discounts = discounts; + this.expand = expand; + this.extraParams = extraParams; + this.metadata = metadata; + this.period = period; + this.price = price; + this.priceData = priceData; + this.quantity = quantity; + this.taxAmounts = taxAmounts; + this.taxRates = taxRates; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Long amount; + + private Object description; + + private Boolean discountable; + + private Object discounts; + + private List expand; + + private Map extraParams; + + private Object metadata; + + private Period period; + + private Object price; + + private PriceData priceData; + + private Long quantity; + + private Object taxAmounts; + + private Object taxRates; + + /** Finalize and obtain parameter instance from this builder. */ + public InvoiceLineItemUpdateParams build() { + return new InvoiceLineItemUpdateParams( + this.amount, + this.description, + this.discountable, + this.discounts, + this.expand, + this.extraParams, + this.metadata, + this.period, + this.price, + this.priceData, + this.quantity, + this.taxAmounts, + this.taxRates); + } + + /** + * The integer amount in cents (or local equivalent) of the charge to be applied to the upcoming + * invoice. If you want to apply a credit to the customer's account, pass a negative amount. + */ + public Builder setAmount(Long amount) { + this.amount = amount; + return this; + } + + /** + * An arbitrary string which you can attach to the invoice item. The description is displayed in + * the invoice for easy tracking. + */ + public Builder setDescription(String description) { + this.description = description; + return this; + } + + /** + * An arbitrary string which you can attach to the invoice item. The description is displayed in + * the invoice for easy tracking. + */ + public Builder setDescription(EmptyParam description) { + this.description = description; + return this; + } + + /** + * Controls whether discounts apply to this line item. Defaults to false for prorations or + * negative line items, and true for all other line items. Cannot be set to true for prorations. + */ + public Builder setDiscountable(Boolean discountable) { + this.discountable = discountable; + return this; + } + + /** + * Add an element to `discounts` list. A list is initialized for the first `add/addAll` call, + * and subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams#discounts} for the field documentation. + */ + @SuppressWarnings("unchecked") + public Builder addDiscount(InvoiceLineItemUpdateParams.Discount element) { + if (this.discounts == null || this.discounts instanceof EmptyParam) { + this.discounts = new ArrayList(); + } + ((List) this.discounts).add(element); + return this; + } + + /** + * Add all elements to `discounts` list. A list is initialized for the first `add/addAll` call, + * and subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams#discounts} for the field documentation. + */ + @SuppressWarnings("unchecked") + public Builder addAllDiscount(List elements) { + if (this.discounts == null || this.discounts instanceof EmptyParam) { + this.discounts = new ArrayList(); + } + ((List) this.discounts).addAll(elements); + return this; + } + + /** + * The coupons & existing discounts which apply to the line item. Item discounts are applied + * before invoice discounts. Pass an empty string to remove previously-defined discounts. + */ + public Builder setDiscounts(EmptyParam discounts) { + this.discounts = discounts; + return this; + } + + /** + * The coupons & existing discounts which apply to the line item. Item discounts are applied + * before invoice discounts. Pass an empty string to remove previously-defined discounts. + */ + public Builder setDiscounts(List discounts) { + this.discounts = discounts; + return this; + } + + /** + * Add an element to `expand` list. A list is initialized for the first `add/addAll` call, and + * subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams#expand} for the field documentation. + */ + public Builder addExpand(String element) { + if (this.expand == null) { + this.expand = new ArrayList<>(); + } + this.expand.add(element); + return this; + } + + /** + * Add all elements to `expand` list. A list is initialized for the first `add/addAll` call, and + * subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams#expand} for the field documentation. + */ + public Builder addAllExpand(List elements) { + if (this.expand == null) { + this.expand = new ArrayList<>(); + } + this.expand.addAll(elements); + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * InvoiceLineItemUpdateParams#extraParams} for the field documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link InvoiceLineItemUpdateParams#extraParams} for the field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** + * Add a key/value pair to `metadata` map. A map is initialized for the first `put/putAll` call, + * and subsequent calls add additional key/value pairs to the original map. See {@link + * InvoiceLineItemUpdateParams#metadata} for the field documentation. + */ + @SuppressWarnings("unchecked") + public Builder putMetadata(String key, String value) { + if (this.metadata == null || this.metadata instanceof EmptyParam) { + this.metadata = new HashMap(); + } + ((Map) this.metadata).put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `metadata` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link InvoiceLineItemUpdateParams#metadata} for the field documentation. + */ + @SuppressWarnings("unchecked") + public Builder putAllMetadata(Map map) { + if (this.metadata == null || this.metadata instanceof EmptyParam) { + this.metadata = new HashMap(); + } + ((Map) this.metadata).putAll(map); + return this; + } + + /** + * Set of key-value pairs that you can attach + * to an object. This can be useful for storing additional information about the object in a + * structured format. Individual keys can be unset by posting an empty value to them. All keys + * can be unset by posting an empty value to {@code metadata}. + */ + public Builder setMetadata(EmptyParam metadata) { + this.metadata = metadata; + return this; + } + + /** + * Set of key-value pairs that you can attach + * to an object. This can be useful for storing additional information about the object in a + * structured format. Individual keys can be unset by posting an empty value to them. All keys + * can be unset by posting an empty value to {@code metadata}. + */ + public Builder setMetadata(Map metadata) { + this.metadata = metadata; + return this; + } + + /** + * The period associated with this invoice item. When set to different values, the period will + * be rendered on the invoice. If you have Stripe Revenue Recognition enabled, + * the period will be used to recognize and defer revenue. See the Revenue + * Recognition documentation for details. + */ + public Builder setPeriod(InvoiceLineItemUpdateParams.Period period) { + this.period = period; + return this; + } + + /** The ID of the price object. */ + public Builder setPrice(String price) { + this.price = price; + return this; + } + + /** The ID of the price object. */ + public Builder setPrice(EmptyParam price) { + this.price = price; + return this; + } + + /** + * Data used to generate a new Price object + * inline. + */ + public Builder setPriceData(InvoiceLineItemUpdateParams.PriceData priceData) { + this.priceData = priceData; + return this; + } + + /** Non-negative integer. The quantity of units for the line item. */ + public Builder setQuantity(Long quantity) { + this.quantity = quantity; + return this; + } + + /** + * Add an element to `taxAmounts` list. A list is initialized for the first `add/addAll` call, + * and subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams#taxAmounts} for the field documentation. + */ + @SuppressWarnings("unchecked") + public Builder addTaxAmount(InvoiceLineItemUpdateParams.TaxAmount element) { + if (this.taxAmounts == null || this.taxAmounts instanceof EmptyParam) { + this.taxAmounts = new ArrayList(); + } + ((List) this.taxAmounts).add(element); + return this; + } + + /** + * Add all elements to `taxAmounts` list. A list is initialized for the first `add/addAll` call, + * and subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams#taxAmounts} for the field documentation. + */ + @SuppressWarnings("unchecked") + public Builder addAllTaxAmount(List elements) { + if (this.taxAmounts == null || this.taxAmounts instanceof EmptyParam) { + this.taxAmounts = new ArrayList(); + } + ((List) this.taxAmounts).addAll(elements); + return this; + } + + /** + * A list of up to 10 tax amounts for this line item. This can be useful if you calculate taxes + * on your own or use a third-party to calculate them. You cannot set tax amounts if any line + * item has tax_rates + * or if the invoice has default_tax_rates + * or uses automatic tax. Pass an empty + * string to remove previously defined tax amounts. + */ + public Builder setTaxAmounts(EmptyParam taxAmounts) { + this.taxAmounts = taxAmounts; + return this; + } + + /** + * A list of up to 10 tax amounts for this line item. This can be useful if you calculate taxes + * on your own or use a third-party to calculate them. You cannot set tax amounts if any line + * item has tax_rates + * or if the invoice has default_tax_rates + * or uses automatic tax. Pass an empty + * string to remove previously defined tax amounts. + */ + public Builder setTaxAmounts(List taxAmounts) { + this.taxAmounts = taxAmounts; + return this; + } + + /** + * Add an element to `taxRates` list. A list is initialized for the first `add/addAll` call, and + * subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams#taxRates} for the field documentation. + */ + @SuppressWarnings("unchecked") + public Builder addTaxRate(String element) { + if (this.taxRates == null || this.taxRates instanceof EmptyParam) { + this.taxRates = new ArrayList(); + } + ((List) this.taxRates).add(element); + return this; + } + + /** + * Add all elements to `taxRates` list. A list is initialized for the first `add/addAll` call, + * and subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams#taxRates} for the field documentation. + */ + @SuppressWarnings("unchecked") + public Builder addAllTaxRate(List elements) { + if (this.taxRates == null || this.taxRates instanceof EmptyParam) { + this.taxRates = new ArrayList(); + } + ((List) this.taxRates).addAll(elements); + return this; + } + + /** + * The tax rates which apply to the line item. When set, the {@code default_tax_rates} on the + * invoice do not apply to this line item. Pass an empty string to remove previously-defined tax + * rates. + */ + public Builder setTaxRates(EmptyParam taxRates) { + this.taxRates = taxRates; + return this; + } + + /** + * The tax rates which apply to the line item. When set, the {@code default_tax_rates} on the + * invoice do not apply to this line item. Pass an empty string to remove previously-defined tax + * rates. + */ + public Builder setTaxRates(List taxRates) { + this.taxRates = taxRates; + return this; + } + } + + @Getter + public static class Discount { + /** ID of the coupon to create a new discount for. */ + @SerializedName("coupon") + Object coupon; + + /** ID of an existing discount on the object (or one of its ancestors) to reuse. */ + @SerializedName("discount") + Object discount; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + private Discount(Object coupon, Object discount, Map extraParams) { + this.coupon = coupon; + this.discount = discount; + this.extraParams = extraParams; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Object coupon; + + private Object discount; + + private Map extraParams; + + /** Finalize and obtain parameter instance from this builder. */ + public InvoiceLineItemUpdateParams.Discount build() { + return new InvoiceLineItemUpdateParams.Discount( + this.coupon, this.discount, this.extraParams); + } + + /** ID of the coupon to create a new discount for. */ + public Builder setCoupon(String coupon) { + this.coupon = coupon; + return this; + } + + /** ID of the coupon to create a new discount for. */ + public Builder setCoupon(EmptyParam coupon) { + this.coupon = coupon; + return this; + } + + /** ID of an existing discount on the object (or one of its ancestors) to reuse. */ + public Builder setDiscount(String discount) { + this.discount = discount; + return this; + } + + /** ID of an existing discount on the object (or one of its ancestors) to reuse. */ + public Builder setDiscount(EmptyParam discount) { + this.discount = discount; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * InvoiceLineItemUpdateParams.Discount#extraParams} for the field documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link InvoiceLineItemUpdateParams.Discount#extraParams} for the field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + } + } + + @Getter + public static class Period { + /** + * Required. The end of the period, which must be greater than or equal to the + * start. This value is inclusive. + */ + @SerializedName("end") + Long end; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** Required. The start of the period. This value is inclusive. */ + @SerializedName("start") + Long start; + + private Period(Long end, Map extraParams, Long start) { + this.end = end; + this.extraParams = extraParams; + this.start = start; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Long end; + + private Map extraParams; + + private Long start; + + /** Finalize and obtain parameter instance from this builder. */ + public InvoiceLineItemUpdateParams.Period build() { + return new InvoiceLineItemUpdateParams.Period(this.end, this.extraParams, this.start); + } + + /** + * Required. The end of the period, which must be greater than or equal to + * the start. This value is inclusive. + */ + public Builder setEnd(Long end) { + this.end = end; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * InvoiceLineItemUpdateParams.Period#extraParams} for the field documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link InvoiceLineItemUpdateParams.Period#extraParams} for the field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** Required. The start of the period. This value is inclusive. */ + public Builder setStart(Long start) { + this.start = start; + return this; + } + } + } + + @Getter + public static class PriceData { + /** + * Required. Three-letter ISO currency code, in lowercase. + * Must be a supported currency. + */ + @SerializedName("currency") + Object currency; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** + * The ID of the product that this price will belong to. One of {@code product} or {@code + * product_data} is required. + */ + @SerializedName("product") + Object product; + + /** + * Data used to generate a new product object inline. One of {@code product} or {@code + * product_data} is required. + */ + @SerializedName("product_data") + ProductData productData; + + /** + * Only required if a default + * tax behavior was not provided in the Stripe Tax settings. Specifies whether the price is + * considered inclusive of taxes or exclusive of taxes. One of {@code inclusive}, {@code + * exclusive}, or {@code unspecified}. Once specified as either {@code inclusive} or {@code + * exclusive}, it cannot be changed. + */ + @SerializedName("tax_behavior") + TaxBehavior taxBehavior; + + /** + * A non-negative integer in cents (or local equivalent) representing how much to charge. One of + * {@code unit_amount} or {@code unit_amount_decimal} is required. + */ + @SerializedName("unit_amount") + Long unitAmount; + + /** + * Same as {@code unit_amount}, but accepts a decimal value in cents (or local equivalent) with + * at most 12 decimal places. Only one of {@code unit_amount} and {@code unit_amount_decimal} + * can be set. + */ + @SerializedName("unit_amount_decimal") + Object unitAmountDecimal; + + private PriceData( + Object currency, + Map extraParams, + Object product, + ProductData productData, + TaxBehavior taxBehavior, + Long unitAmount, + Object unitAmountDecimal) { + this.currency = currency; + this.extraParams = extraParams; + this.product = product; + this.productData = productData; + this.taxBehavior = taxBehavior; + this.unitAmount = unitAmount; + this.unitAmountDecimal = unitAmountDecimal; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Object currency; + + private Map extraParams; + + private Object product; + + private ProductData productData; + + private TaxBehavior taxBehavior; + + private Long unitAmount; + + private Object unitAmountDecimal; + + /** Finalize and obtain parameter instance from this builder. */ + public InvoiceLineItemUpdateParams.PriceData build() { + return new InvoiceLineItemUpdateParams.PriceData( + this.currency, + this.extraParams, + this.product, + this.productData, + this.taxBehavior, + this.unitAmount, + this.unitAmountDecimal); + } + + /** + * Required. Three-letter ISO currency code, in + * lowercase. Must be a supported currency. + */ + public Builder setCurrency(String currency) { + this.currency = currency; + return this; + } + + /** + * Required. Three-letter ISO currency code, in + * lowercase. Must be a supported currency. + */ + public Builder setCurrency(EmptyParam currency) { + this.currency = currency; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * InvoiceLineItemUpdateParams.PriceData#extraParams} for the field documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link InvoiceLineItemUpdateParams.PriceData#extraParams} for the field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** + * The ID of the product that this price will belong to. One of {@code product} or {@code + * product_data} is required. + */ + public Builder setProduct(String product) { + this.product = product; + return this; + } + + /** + * The ID of the product that this price will belong to. One of {@code product} or {@code + * product_data} is required. + */ + public Builder setProduct(EmptyParam product) { + this.product = product; + return this; + } + + /** + * Data used to generate a new product object inline. One of {@code product} or {@code + * product_data} is required. + */ + public Builder setProductData(InvoiceLineItemUpdateParams.PriceData.ProductData productData) { + this.productData = productData; + return this; + } + + /** + * Only required if a default + * tax behavior was not provided in the Stripe Tax settings. Specifies whether the price + * is considered inclusive of taxes or exclusive of taxes. One of {@code inclusive}, {@code + * exclusive}, or {@code unspecified}. Once specified as either {@code inclusive} or {@code + * exclusive}, it cannot be changed. + */ + public Builder setTaxBehavior(InvoiceLineItemUpdateParams.PriceData.TaxBehavior taxBehavior) { + this.taxBehavior = taxBehavior; + return this; + } + + /** + * A non-negative integer in cents (or local equivalent) representing how much to charge. One + * of {@code unit_amount} or {@code unit_amount_decimal} is required. + */ + public Builder setUnitAmount(Long unitAmount) { + this.unitAmount = unitAmount; + return this; + } + + /** + * Same as {@code unit_amount}, but accepts a decimal value in cents (or local equivalent) + * with at most 12 decimal places. Only one of {@code unit_amount} and {@code + * unit_amount_decimal} can be set. + */ + public Builder setUnitAmountDecimal(BigDecimal unitAmountDecimal) { + this.unitAmountDecimal = unitAmountDecimal; + return this; + } + + /** + * Same as {@code unit_amount}, but accepts a decimal value in cents (or local equivalent) + * with at most 12 decimal places. Only one of {@code unit_amount} and {@code + * unit_amount_decimal} can be set. + */ + public Builder setUnitAmountDecimal(EmptyParam unitAmountDecimal) { + this.unitAmountDecimal = unitAmountDecimal; + return this; + } + } + + @Getter + public static class ProductData { + /** + * The product's description, meant to be displayable to the customer. Use this field to + * optionally store a long form explanation of the product being sold for your own rendering + * purposes. + */ + @SerializedName("description") + Object description; + + /** + * Map of extra parameters for custom features not available in this client library. The + * content in this map is not serialized under this field's {@code @SerializedName} value. + * Instead, each key/value pair is serialized as if the key is a root-level field (serialized) + * name in this param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** + * A list of up to 8 URLs of images for this product, meant to be displayable to the customer. + */ + @SerializedName("images") + List images; + + /** + * Set of key-value pairs that you can + * attach to an object. This can be useful for storing additional information about the object + * in a structured format. Individual keys can be unset by posting an empty value to them. All + * keys can be unset by posting an empty value to {@code metadata}. + */ + @SerializedName("metadata") + Map metadata; + + /** Required. The product's name, meant to be displayable to the customer. */ + @SerializedName("name") + Object name; + + /** A tax code ID. */ + @SerializedName("tax_code") + Object taxCode; + + private ProductData( + Object description, + Map extraParams, + List images, + Map metadata, + Object name, + Object taxCode) { + this.description = description; + this.extraParams = extraParams; + this.images = images; + this.metadata = metadata; + this.name = name; + this.taxCode = taxCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Object description; + + private Map extraParams; + + private List images; + + private Map metadata; + + private Object name; + + private Object taxCode; + + /** Finalize and obtain parameter instance from this builder. */ + public InvoiceLineItemUpdateParams.PriceData.ProductData build() { + return new InvoiceLineItemUpdateParams.PriceData.ProductData( + this.description, + this.extraParams, + this.images, + this.metadata, + this.name, + this.taxCode); + } + + /** + * The product's description, meant to be displayable to the customer. Use this field to + * optionally store a long form explanation of the product being sold for your own rendering + * purposes. + */ + public Builder setDescription(String description) { + this.description = description; + return this; + } + + /** + * The product's description, meant to be displayable to the customer. Use this field to + * optionally store a long form explanation of the product being sold for your own rendering + * purposes. + */ + public Builder setDescription(EmptyParam description) { + this.description = description; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original + * map. See {@link InvoiceLineItemUpdateParams.PriceData.ProductData#extraParams} for the + * field documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original + * map. See {@link InvoiceLineItemUpdateParams.PriceData.ProductData#extraParams} for the + * field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** + * Add an element to `images` list. A list is initialized for the first `add/addAll` call, + * and subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams.PriceData.ProductData#images} for the field documentation. + */ + public Builder addImage(String element) { + if (this.images == null) { + this.images = new ArrayList<>(); + } + this.images.add(element); + return this; + } + + /** + * Add all elements to `images` list. A list is initialized for the first `add/addAll` call, + * and subsequent calls adds additional elements to the original list. See {@link + * InvoiceLineItemUpdateParams.PriceData.ProductData#images} for the field documentation. + */ + public Builder addAllImage(List elements) { + if (this.images == null) { + this.images = new ArrayList<>(); + } + this.images.addAll(elements); + return this; + } + + /** + * Add a key/value pair to `metadata` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * InvoiceLineItemUpdateParams.PriceData.ProductData#metadata} for the field documentation. + */ + public Builder putMetadata(String key, String value) { + if (this.metadata == null) { + this.metadata = new HashMap<>(); + } + this.metadata.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `metadata` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original + * map. See {@link InvoiceLineItemUpdateParams.PriceData.ProductData#metadata} for the field + * documentation. + */ + public Builder putAllMetadata(Map map) { + if (this.metadata == null) { + this.metadata = new HashMap<>(); + } + this.metadata.putAll(map); + return this; + } + + /** + * Required. The product's name, meant to be displayable to the customer. + */ + public Builder setName(String name) { + this.name = name; + return this; + } + + /** + * Required. The product's name, meant to be displayable to the customer. + */ + public Builder setName(EmptyParam name) { + this.name = name; + return this; + } + + /** A tax code ID. */ + public Builder setTaxCode(String taxCode) { + this.taxCode = taxCode; + return this; + } + + /** A tax code ID. */ + public Builder setTaxCode(EmptyParam taxCode) { + this.taxCode = taxCode; + return this; + } + } + } + + public enum TaxBehavior implements ApiRequestParams.EnumParam { + @SerializedName("exclusive") + EXCLUSIVE("exclusive"), + + @SerializedName("inclusive") + INCLUSIVE("inclusive"), + + @SerializedName("unspecified") + UNSPECIFIED("unspecified"); + + @Getter(onMethod_ = {@Override}) + private final String value; + + TaxBehavior(String value) { + this.value = value; + } + } + } + + @Getter + public static class TaxAmount { + /** Required. The amount, in cents (or local equivalent), of the tax. */ + @SerializedName("amount") + Long amount; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** + * Required. Data to find or create a TaxRate object. + * + *

Stripe automatically creates or reuses a TaxRate object for each tax amount. If the {@code + * tax_rate_data} exactly matches a previous value, Stripe will reuse the TaxRate object. + * TaxRate objects created automatically by Stripe are immediately archived, do not appear in + * the line item’s {@code tax_rates}, and cannot be directly added to invoices, payments, or + * line items. + */ + @SerializedName("tax_rate_data") + TaxRateData taxRateData; + + /** + * Required. The amount on which tax is calculated, in cents (or local + * equivalent). + */ + @SerializedName("taxable_amount") + Long taxableAmount; + + private TaxAmount( + Long amount, Map extraParams, TaxRateData taxRateData, Long taxableAmount) { + this.amount = amount; + this.extraParams = extraParams; + this.taxRateData = taxRateData; + this.taxableAmount = taxableAmount; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Long amount; + + private Map extraParams; + + private TaxRateData taxRateData; + + private Long taxableAmount; + + /** Finalize and obtain parameter instance from this builder. */ + public InvoiceLineItemUpdateParams.TaxAmount build() { + return new InvoiceLineItemUpdateParams.TaxAmount( + this.amount, this.extraParams, this.taxRateData, this.taxableAmount); + } + + /** Required. The amount, in cents (or local equivalent), of the tax. */ + public Builder setAmount(Long amount) { + this.amount = amount; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * InvoiceLineItemUpdateParams.TaxAmount#extraParams} for the field documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link InvoiceLineItemUpdateParams.TaxAmount#extraParams} for the field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** + * Required. Data to find or create a TaxRate object. + * + *

Stripe automatically creates or reuses a TaxRate object for each tax amount. If the + * {@code tax_rate_data} exactly matches a previous value, Stripe will reuse the TaxRate + * object. TaxRate objects created automatically by Stripe are immediately archived, do not + * appear in the line item’s {@code tax_rates}, and cannot be directly added to invoices, + * payments, or line items. + */ + public Builder setTaxRateData(InvoiceLineItemUpdateParams.TaxAmount.TaxRateData taxRateData) { + this.taxRateData = taxRateData; + return this; + } + + /** + * Required. The amount on which tax is calculated, in cents (or local + * equivalent). + */ + public Builder setTaxableAmount(Long taxableAmount) { + this.taxableAmount = taxableAmount; + return this; + } + } + + @Getter + public static class TaxRateData { + /** + * Two-letter country code (ISO + * 3166-1 alpha-2). + */ + @SerializedName("country") + Object country; + + /** + * An arbitrary string attached to the tax rate for your internal use only. It will not be + * visible to your customers. + */ + @SerializedName("description") + Object description; + + /** + * Required. The display name of the tax rate, which will be shown to users. + */ + @SerializedName("display_name") + Object displayName; + + /** + * Map of extra parameters for custom features not available in this client library. The + * content in this map is not serialized under this field's {@code @SerializedName} value. + * Instead, each key/value pair is serialized as if the key is a root-level field (serialized) + * name in this param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** Required. This specifies if the tax rate is inclusive or exclusive. */ + @SerializedName("inclusive") + Boolean inclusive; + + /** + * The jurisdiction for the tax rate. You can use this label field for tax reporting purposes. + * It also appears on your customer’s invoice. + */ + @SerializedName("jurisdiction") + Object jurisdiction; + + /** + * Required. The statutory tax rate percent. This field accepts decimal + * values between 0 and 100 inclusive with at most 4 decimal places. To accommodate + * fixed-amount taxes, set the percentage to zero. Stripe will not display zero percentages on + * the invoice unless the {@code amount} of the tax is also zero. + */ + @SerializedName("percentage") + BigDecimal percentage; + + /** + * ISO 3166-2 subdivision code, + * without country prefix. For example, "NY" for New York, United States. + */ + @SerializedName("state") + Object state; + + /** The high-level tax type, such as {@code vat} or {@code sales_tax}. */ + @SerializedName("tax_type") + TaxType taxType; + + private TaxRateData( + Object country, + Object description, + Object displayName, + Map extraParams, + Boolean inclusive, + Object jurisdiction, + BigDecimal percentage, + Object state, + TaxType taxType) { + this.country = country; + this.description = description; + this.displayName = displayName; + this.extraParams = extraParams; + this.inclusive = inclusive; + this.jurisdiction = jurisdiction; + this.percentage = percentage; + this.state = state; + this.taxType = taxType; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Object country; + + private Object description; + + private Object displayName; + + private Map extraParams; + + private Boolean inclusive; + + private Object jurisdiction; + + private BigDecimal percentage; + + private Object state; + + private TaxType taxType; + + /** Finalize and obtain parameter instance from this builder. */ + public InvoiceLineItemUpdateParams.TaxAmount.TaxRateData build() { + return new InvoiceLineItemUpdateParams.TaxAmount.TaxRateData( + this.country, + this.description, + this.displayName, + this.extraParams, + this.inclusive, + this.jurisdiction, + this.percentage, + this.state, + this.taxType); + } + + /** + * Two-letter country code (ISO + * 3166-1 alpha-2). + */ + public Builder setCountry(String country) { + this.country = country; + return this; + } + + /** + * Two-letter country code (ISO + * 3166-1 alpha-2). + */ + public Builder setCountry(EmptyParam country) { + this.country = country; + return this; + } + + /** + * An arbitrary string attached to the tax rate for your internal use only. It will not be + * visible to your customers. + */ + public Builder setDescription(String description) { + this.description = description; + return this; + } + + /** + * An arbitrary string attached to the tax rate for your internal use only. It will not be + * visible to your customers. + */ + public Builder setDescription(EmptyParam description) { + this.description = description; + return this; + } + + /** + * Required. The display name of the tax rate, which will be shown to + * users. + */ + public Builder setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Required. The display name of the tax rate, which will be shown to + * users. + */ + public Builder setDisplayName(EmptyParam displayName) { + this.displayName = displayName; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original + * map. See {@link InvoiceLineItemUpdateParams.TaxAmount.TaxRateData#extraParams} for the + * field documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original + * map. See {@link InvoiceLineItemUpdateParams.TaxAmount.TaxRateData#extraParams} for the + * field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** Required. This specifies if the tax rate is inclusive or exclusive. */ + public Builder setInclusive(Boolean inclusive) { + this.inclusive = inclusive; + return this; + } + + /** + * The jurisdiction for the tax rate. You can use this label field for tax reporting + * purposes. It also appears on your customer’s invoice. + */ + public Builder setJurisdiction(String jurisdiction) { + this.jurisdiction = jurisdiction; + return this; + } + + /** + * The jurisdiction for the tax rate. You can use this label field for tax reporting + * purposes. It also appears on your customer’s invoice. + */ + public Builder setJurisdiction(EmptyParam jurisdiction) { + this.jurisdiction = jurisdiction; + return this; + } + + /** + * Required. The statutory tax rate percent. This field accepts decimal + * values between 0 and 100 inclusive with at most 4 decimal places. To accommodate + * fixed-amount taxes, set the percentage to zero. Stripe will not display zero percentages + * on the invoice unless the {@code amount} of the tax is also zero. + */ + public Builder setPercentage(BigDecimal percentage) { + this.percentage = percentage; + return this; + } + + /** + * ISO 3166-2 subdivision code, + * without country prefix. For example, "NY" for New York, United States. + */ + public Builder setState(String state) { + this.state = state; + return this; + } + + /** + * ISO 3166-2 subdivision code, + * without country prefix. For example, "NY" for New York, United States. + */ + public Builder setState(EmptyParam state) { + this.state = state; + return this; + } + + /** The high-level tax type, such as {@code vat} or {@code sales_tax}. */ + public Builder setTaxType( + InvoiceLineItemUpdateParams.TaxAmount.TaxRateData.TaxType taxType) { + this.taxType = taxType; + return this; + } + } + + public enum TaxType implements ApiRequestParams.EnumParam { + @SerializedName("amusement_tax") + AMUSEMENT_TAX("amusement_tax"), + + @SerializedName("communications_tax") + COMMUNICATIONS_TAX("communications_tax"), + + @SerializedName("gst") + GST("gst"), + + @SerializedName("hst") + HST("hst"), + + @SerializedName("igst") + IGST("igst"), + + @SerializedName("jct") + JCT("jct"), + + @SerializedName("lease_tax") + LEASE_TAX("lease_tax"), + + @SerializedName("pst") + PST("pst"), + + @SerializedName("qst") + QST("qst"), + + @SerializedName("rst") + RST("rst"), + + @SerializedName("sales_tax") + SALES_TAX("sales_tax"), + + @SerializedName("service_tax") + SERVICE_TAX("service_tax"), + + @SerializedName("vat") + VAT("vat"); + + @Getter(onMethod_ = {@Override}) + private final String value; + + TaxType(String value) { + this.value = value; + } + } + } + } +} diff --git a/src/main/java/com/stripe/service/InvoiceLineItemService.java b/src/main/java/com/stripe/service/InvoiceLineItemService.java index b1dc41dd745..6e3b149c6f4 100644 --- a/src/main/java/com/stripe/service/InvoiceLineItemService.java +++ b/src/main/java/com/stripe/service/InvoiceLineItemService.java @@ -13,6 +13,7 @@ import com.stripe.net.RequestOptions; import com.stripe.net.StripeResponseGetter; import com.stripe.param.InvoiceLineItemListParams; +import com.stripe.param.InvoiceLineItemUpdateParams; public final class InvoiceLineItemService extends ApiService { public InvoiceLineItemService(StripeResponseGetter responseGetter) { @@ -64,4 +65,61 @@ public StripeCollection list( options, ApiMode.V1); } + /** + * 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( + String invoice, String lineItemId, InvoiceLineItemUpdateParams params) + throws StripeException { + return update(invoice, lineItemId, 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(String invoice, String lineItemId, RequestOptions options) + throws StripeException { + return update(invoice, lineItemId, (InvoiceLineItemUpdateParams) null, options); + } + /** + * 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(String invoice, String lineItemId) throws StripeException { + return update(invoice, lineItemId, (InvoiceLineItemUpdateParams) null, (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( + String invoice, String lineItemId, InvoiceLineItemUpdateParams params, RequestOptions options) + throws StripeException { + String path = + String.format( + "/v1/invoices/%s/lines/%s", + ApiResource.urlEncodeId(invoice), ApiResource.urlEncodeId(lineItemId)); + return getResponseGetter() + .request( + BaseAddress.API, + ApiResource.RequestMethod.POST, + path, + ApiRequestParams.paramsToMap(params), + InvoiceLineItem.class, + options, + ApiMode.V1); + } } From bd6667870a46da40645bb343e8229a2429219bb7 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 21 Nov 2023 13:55:00 -0800 Subject: [PATCH 2/9] update --- .../com/stripe/model/InvoiceLineItem.java | 95 +- .../param/InvoiceLineItemUpdateParams.java | 1590 ----------------- .../service/InvoiceLineItemService.java | 58 - 3 files changed, 1 insertion(+), 1742 deletions(-) delete mode 100644 src/main/java/com/stripe/param/InvoiceLineItemUpdateParams.java diff --git a/src/main/java/com/stripe/model/InvoiceLineItem.java b/src/main/java/com/stripe/model/InvoiceLineItem.java index 9948ab86987..011e4b30a70 100644 --- a/src/main/java/com/stripe/model/InvoiceLineItem.java +++ b/src/main/java/com/stripe/model/InvoiceLineItem.java @@ -2,14 +2,7 @@ package com.stripe.model; import com.google.gson.annotations.SerializedName; -import com.stripe.exception.StripeException; -import com.stripe.net.ApiMode; -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; @@ -21,7 +14,7 @@ @Getter @Setter @EqualsAndHashCode(callSuper = false) -public class InvoiceLineItem extends ApiResource implements HasId, MetadataStore { +public class InvoiceLineItem extends StripeObject implements HasId { /** The amount, in cents (or local equivalent). */ @SerializedName("amount") Long amount; @@ -86,7 +79,6 @@ public class InvoiceLineItem extends ApiResource implements HasId, MetadataStore * structured format. Note that for line items with {@code type=subscription} this will reflect * the metadata of the subscription that caused the line item to be created. */ - @Getter(onMethod_ = {@Override}) @SerializedName("metadata") Map metadata; @@ -257,79 +249,6 @@ public void setDiscountObjects(List objs) { : 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(String invoice, Map params) throws StripeException { - return update(invoice, 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(String invoice, Map params, RequestOptions options) - throws StripeException { - String path = - String.format( - "/v1/invoices/%s/lines/%s", - ApiResource.urlEncodeId(invoice), ApiResource.urlEncodeId(this.getId())); - return getResponseGetter() - .request( - BaseAddress.API, - ApiResource.RequestMethod.POST, - path, - params, - InvoiceLineItem.class, - options, - ApiMode.V1); - } - - /** - * 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(String invoice, InvoiceLineItemUpdateParams params) - throws StripeException { - return update(invoice, 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( - String invoice, InvoiceLineItemUpdateParams params, RequestOptions options) - throws StripeException { - String path = - String.format( - "/v1/invoices/%s/lines/%s", - ApiResource.urlEncodeId(invoice), ApiResource.urlEncodeId(this.getId())); - ApiResource.checkNullTypedParams(path, params); - return getResponseGetter() - .request( - BaseAddress.API, - ApiResource.RequestMethod.POST, - path, - ApiRequestParams.paramsToMap(params), - InvoiceLineItem.class, - options, - ApiMode.V1); - } - @Getter @Setter @EqualsAndHashCode(callSuper = false) @@ -457,16 +376,4 @@ public void setTaxRateObject(TaxRate expandableObject) { this.taxRate = new ExpandableField(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); - } } diff --git a/src/main/java/com/stripe/param/InvoiceLineItemUpdateParams.java b/src/main/java/com/stripe/param/InvoiceLineItemUpdateParams.java deleted file mode 100644 index a0bc54f9bdc..00000000000 --- a/src/main/java/com/stripe/param/InvoiceLineItemUpdateParams.java +++ /dev/null @@ -1,1590 +0,0 @@ -// File generated from our OpenAPI spec -package com.stripe.param; - -import com.google.gson.annotations.SerializedName; -import com.stripe.net.ApiRequestParams; -import com.stripe.param.common.EmptyParam; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import lombok.Getter; - -@Getter -public class InvoiceLineItemUpdateParams extends ApiRequestParams { - /** - * The integer amount in cents (or local equivalent) of the charge to be applied to the upcoming - * invoice. If you want to apply a credit to the customer's account, pass a negative amount. - */ - @SerializedName("amount") - Long amount; - - /** - * An arbitrary string which you can attach to the invoice item. The description is displayed in - * the invoice for easy tracking. - */ - @SerializedName("description") - Object description; - - /** - * Controls whether discounts apply to this line item. Defaults to false for prorations or - * negative line items, and true for all other line items. Cannot be set to true for prorations. - */ - @SerializedName("discountable") - Boolean discountable; - - /** - * The coupons & existing discounts which apply to the line item. Item discounts are applied - * before invoice discounts. Pass an empty string to remove previously-defined discounts. - */ - @SerializedName("discounts") - Object discounts; - - /** Specifies which fields in the response should be expanded. */ - @SerializedName("expand") - List expand; - - /** - * Map of extra parameters for custom features not available in this client library. The content - * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each - * key/value pair is serialized as if the key is a root-level field (serialized) name in this - * param object. Effectively, this map is flattened to its parent instance. - */ - @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) - Map extraParams; - - /** - * Set of key-value pairs that you can attach - * to an object. This can be useful for storing additional information about the object in a - * structured format. Individual keys can be unset by posting an empty value to them. All keys can - * be unset by posting an empty value to {@code metadata}. - */ - @SerializedName("metadata") - Object metadata; - - /** - * The period associated with this invoice item. When set to different values, the period will be - * rendered on the invoice. If you have Stripe Revenue Recognition enabled, the - * period will be used to recognize and defer revenue. See the Revenue - * Recognition documentation for details. - */ - @SerializedName("period") - Period period; - - /** The ID of the price object. */ - @SerializedName("price") - Object price; - - /** - * Data used to generate a new Price object - * inline. - */ - @SerializedName("price_data") - PriceData priceData; - - /** Non-negative integer. The quantity of units for the line item. */ - @SerializedName("quantity") - Long quantity; - - /** - * A list of up to 10 tax amounts for this line item. This can be useful if you calculate taxes on - * your own or use a third-party to calculate them. You cannot set tax amounts if any line item - * has tax_rates - * or if the invoice has default_tax_rates - * or uses automatic tax. Pass an empty string - * to remove previously defined tax amounts. - */ - @SerializedName("tax_amounts") - Object taxAmounts; - - /** - * The tax rates which apply to the line item. When set, the {@code default_tax_rates} on the - * invoice do not apply to this line item. Pass an empty string to remove previously-defined tax - * rates. - */ - @SerializedName("tax_rates") - Object taxRates; - - private InvoiceLineItemUpdateParams( - Long amount, - Object description, - Boolean discountable, - Object discounts, - List expand, - Map extraParams, - Object metadata, - Period period, - Object price, - PriceData priceData, - Long quantity, - Object taxAmounts, - Object taxRates) { - this.amount = amount; - this.description = description; - this.discountable = discountable; - this.discounts = discounts; - this.expand = expand; - this.extraParams = extraParams; - this.metadata = metadata; - this.period = period; - this.price = price; - this.priceData = priceData; - this.quantity = quantity; - this.taxAmounts = taxAmounts; - this.taxRates = taxRates; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Long amount; - - private Object description; - - private Boolean discountable; - - private Object discounts; - - private List expand; - - private Map extraParams; - - private Object metadata; - - private Period period; - - private Object price; - - private PriceData priceData; - - private Long quantity; - - private Object taxAmounts; - - private Object taxRates; - - /** Finalize and obtain parameter instance from this builder. */ - public InvoiceLineItemUpdateParams build() { - return new InvoiceLineItemUpdateParams( - this.amount, - this.description, - this.discountable, - this.discounts, - this.expand, - this.extraParams, - this.metadata, - this.period, - this.price, - this.priceData, - this.quantity, - this.taxAmounts, - this.taxRates); - } - - /** - * The integer amount in cents (or local equivalent) of the charge to be applied to the upcoming - * invoice. If you want to apply a credit to the customer's account, pass a negative amount. - */ - public Builder setAmount(Long amount) { - this.amount = amount; - return this; - } - - /** - * An arbitrary string which you can attach to the invoice item. The description is displayed in - * the invoice for easy tracking. - */ - public Builder setDescription(String description) { - this.description = description; - return this; - } - - /** - * An arbitrary string which you can attach to the invoice item. The description is displayed in - * the invoice for easy tracking. - */ - public Builder setDescription(EmptyParam description) { - this.description = description; - return this; - } - - /** - * Controls whether discounts apply to this line item. Defaults to false for prorations or - * negative line items, and true for all other line items. Cannot be set to true for prorations. - */ - public Builder setDiscountable(Boolean discountable) { - this.discountable = discountable; - return this; - } - - /** - * Add an element to `discounts` list. A list is initialized for the first `add/addAll` call, - * and subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams#discounts} for the field documentation. - */ - @SuppressWarnings("unchecked") - public Builder addDiscount(InvoiceLineItemUpdateParams.Discount element) { - if (this.discounts == null || this.discounts instanceof EmptyParam) { - this.discounts = new ArrayList(); - } - ((List) this.discounts).add(element); - return this; - } - - /** - * Add all elements to `discounts` list. A list is initialized for the first `add/addAll` call, - * and subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams#discounts} for the field documentation. - */ - @SuppressWarnings("unchecked") - public Builder addAllDiscount(List elements) { - if (this.discounts == null || this.discounts instanceof EmptyParam) { - this.discounts = new ArrayList(); - } - ((List) this.discounts).addAll(elements); - return this; - } - - /** - * The coupons & existing discounts which apply to the line item. Item discounts are applied - * before invoice discounts. Pass an empty string to remove previously-defined discounts. - */ - public Builder setDiscounts(EmptyParam discounts) { - this.discounts = discounts; - return this; - } - - /** - * The coupons & existing discounts which apply to the line item. Item discounts are applied - * before invoice discounts. Pass an empty string to remove previously-defined discounts. - */ - public Builder setDiscounts(List discounts) { - this.discounts = discounts; - return this; - } - - /** - * Add an element to `expand` list. A list is initialized for the first `add/addAll` call, and - * subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams#expand} for the field documentation. - */ - public Builder addExpand(String element) { - if (this.expand == null) { - this.expand = new ArrayList<>(); - } - this.expand.add(element); - return this; - } - - /** - * Add all elements to `expand` list. A list is initialized for the first `add/addAll` call, and - * subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams#expand} for the field documentation. - */ - public Builder addAllExpand(List elements) { - if (this.expand == null) { - this.expand = new ArrayList<>(); - } - this.expand.addAll(elements); - return this; - } - - /** - * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` - * call, and subsequent calls add additional key/value pairs to the original map. See {@link - * InvoiceLineItemUpdateParams#extraParams} for the field documentation. - */ - public Builder putExtraParam(String key, Object value) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.put(key, value); - return this; - } - - /** - * Add all map key/value pairs to `extraParams` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. - * See {@link InvoiceLineItemUpdateParams#extraParams} for the field documentation. - */ - public Builder putAllExtraParam(Map map) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.putAll(map); - return this; - } - - /** - * Add a key/value pair to `metadata` map. A map is initialized for the first `put/putAll` call, - * and subsequent calls add additional key/value pairs to the original map. See {@link - * InvoiceLineItemUpdateParams#metadata} for the field documentation. - */ - @SuppressWarnings("unchecked") - public Builder putMetadata(String key, String value) { - if (this.metadata == null || this.metadata instanceof EmptyParam) { - this.metadata = new HashMap(); - } - ((Map) this.metadata).put(key, value); - return this; - } - - /** - * Add all map key/value pairs to `metadata` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. - * See {@link InvoiceLineItemUpdateParams#metadata} for the field documentation. - */ - @SuppressWarnings("unchecked") - public Builder putAllMetadata(Map map) { - if (this.metadata == null || this.metadata instanceof EmptyParam) { - this.metadata = new HashMap(); - } - ((Map) this.metadata).putAll(map); - return this; - } - - /** - * Set of key-value pairs that you can attach - * to an object. This can be useful for storing additional information about the object in a - * structured format. Individual keys can be unset by posting an empty value to them. All keys - * can be unset by posting an empty value to {@code metadata}. - */ - public Builder setMetadata(EmptyParam metadata) { - this.metadata = metadata; - return this; - } - - /** - * Set of key-value pairs that you can attach - * to an object. This can be useful for storing additional information about the object in a - * structured format. Individual keys can be unset by posting an empty value to them. All keys - * can be unset by posting an empty value to {@code metadata}. - */ - public Builder setMetadata(Map metadata) { - this.metadata = metadata; - return this; - } - - /** - * The period associated with this invoice item. When set to different values, the period will - * be rendered on the invoice. If you have Stripe Revenue Recognition enabled, - * the period will be used to recognize and defer revenue. See the Revenue - * Recognition documentation for details. - */ - public Builder setPeriod(InvoiceLineItemUpdateParams.Period period) { - this.period = period; - return this; - } - - /** The ID of the price object. */ - public Builder setPrice(String price) { - this.price = price; - return this; - } - - /** The ID of the price object. */ - public Builder setPrice(EmptyParam price) { - this.price = price; - return this; - } - - /** - * Data used to generate a new Price object - * inline. - */ - public Builder setPriceData(InvoiceLineItemUpdateParams.PriceData priceData) { - this.priceData = priceData; - return this; - } - - /** Non-negative integer. The quantity of units for the line item. */ - public Builder setQuantity(Long quantity) { - this.quantity = quantity; - return this; - } - - /** - * Add an element to `taxAmounts` list. A list is initialized for the first `add/addAll` call, - * and subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams#taxAmounts} for the field documentation. - */ - @SuppressWarnings("unchecked") - public Builder addTaxAmount(InvoiceLineItemUpdateParams.TaxAmount element) { - if (this.taxAmounts == null || this.taxAmounts instanceof EmptyParam) { - this.taxAmounts = new ArrayList(); - } - ((List) this.taxAmounts).add(element); - return this; - } - - /** - * Add all elements to `taxAmounts` list. A list is initialized for the first `add/addAll` call, - * and subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams#taxAmounts} for the field documentation. - */ - @SuppressWarnings("unchecked") - public Builder addAllTaxAmount(List elements) { - if (this.taxAmounts == null || this.taxAmounts instanceof EmptyParam) { - this.taxAmounts = new ArrayList(); - } - ((List) this.taxAmounts).addAll(elements); - return this; - } - - /** - * A list of up to 10 tax amounts for this line item. This can be useful if you calculate taxes - * on your own or use a third-party to calculate them. You cannot set tax amounts if any line - * item has tax_rates - * or if the invoice has default_tax_rates - * or uses automatic tax. Pass an empty - * string to remove previously defined tax amounts. - */ - public Builder setTaxAmounts(EmptyParam taxAmounts) { - this.taxAmounts = taxAmounts; - return this; - } - - /** - * A list of up to 10 tax amounts for this line item. This can be useful if you calculate taxes - * on your own or use a third-party to calculate them. You cannot set tax amounts if any line - * item has tax_rates - * or if the invoice has default_tax_rates - * or uses automatic tax. Pass an empty - * string to remove previously defined tax amounts. - */ - public Builder setTaxAmounts(List taxAmounts) { - this.taxAmounts = taxAmounts; - return this; - } - - /** - * Add an element to `taxRates` list. A list is initialized for the first `add/addAll` call, and - * subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams#taxRates} for the field documentation. - */ - @SuppressWarnings("unchecked") - public Builder addTaxRate(String element) { - if (this.taxRates == null || this.taxRates instanceof EmptyParam) { - this.taxRates = new ArrayList(); - } - ((List) this.taxRates).add(element); - return this; - } - - /** - * Add all elements to `taxRates` list. A list is initialized for the first `add/addAll` call, - * and subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams#taxRates} for the field documentation. - */ - @SuppressWarnings("unchecked") - public Builder addAllTaxRate(List elements) { - if (this.taxRates == null || this.taxRates instanceof EmptyParam) { - this.taxRates = new ArrayList(); - } - ((List) this.taxRates).addAll(elements); - return this; - } - - /** - * The tax rates which apply to the line item. When set, the {@code default_tax_rates} on the - * invoice do not apply to this line item. Pass an empty string to remove previously-defined tax - * rates. - */ - public Builder setTaxRates(EmptyParam taxRates) { - this.taxRates = taxRates; - return this; - } - - /** - * The tax rates which apply to the line item. When set, the {@code default_tax_rates} on the - * invoice do not apply to this line item. Pass an empty string to remove previously-defined tax - * rates. - */ - public Builder setTaxRates(List taxRates) { - this.taxRates = taxRates; - return this; - } - } - - @Getter - public static class Discount { - /** ID of the coupon to create a new discount for. */ - @SerializedName("coupon") - Object coupon; - - /** ID of an existing discount on the object (or one of its ancestors) to reuse. */ - @SerializedName("discount") - Object discount; - - /** - * Map of extra parameters for custom features not available in this client library. The content - * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each - * key/value pair is serialized as if the key is a root-level field (serialized) name in this - * param object. Effectively, this map is flattened to its parent instance. - */ - @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) - Map extraParams; - - private Discount(Object coupon, Object discount, Map extraParams) { - this.coupon = coupon; - this.discount = discount; - this.extraParams = extraParams; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Object coupon; - - private Object discount; - - private Map extraParams; - - /** Finalize and obtain parameter instance from this builder. */ - public InvoiceLineItemUpdateParams.Discount build() { - return new InvoiceLineItemUpdateParams.Discount( - this.coupon, this.discount, this.extraParams); - } - - /** ID of the coupon to create a new discount for. */ - public Builder setCoupon(String coupon) { - this.coupon = coupon; - return this; - } - - /** ID of the coupon to create a new discount for. */ - public Builder setCoupon(EmptyParam coupon) { - this.coupon = coupon; - return this; - } - - /** ID of an existing discount on the object (or one of its ancestors) to reuse. */ - public Builder setDiscount(String discount) { - this.discount = discount; - return this; - } - - /** ID of an existing discount on the object (or one of its ancestors) to reuse. */ - public Builder setDiscount(EmptyParam discount) { - this.discount = discount; - return this; - } - - /** - * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` - * call, and subsequent calls add additional key/value pairs to the original map. See {@link - * InvoiceLineItemUpdateParams.Discount#extraParams} for the field documentation. - */ - public Builder putExtraParam(String key, Object value) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.put(key, value); - return this; - } - - /** - * Add all map key/value pairs to `extraParams` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. - * See {@link InvoiceLineItemUpdateParams.Discount#extraParams} for the field documentation. - */ - public Builder putAllExtraParam(Map map) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.putAll(map); - return this; - } - } - } - - @Getter - public static class Period { - /** - * Required. The end of the period, which must be greater than or equal to the - * start. This value is inclusive. - */ - @SerializedName("end") - Long end; - - /** - * Map of extra parameters for custom features not available in this client library. The content - * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each - * key/value pair is serialized as if the key is a root-level field (serialized) name in this - * param object. Effectively, this map is flattened to its parent instance. - */ - @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) - Map extraParams; - - /** Required. The start of the period. This value is inclusive. */ - @SerializedName("start") - Long start; - - private Period(Long end, Map extraParams, Long start) { - this.end = end; - this.extraParams = extraParams; - this.start = start; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Long end; - - private Map extraParams; - - private Long start; - - /** Finalize and obtain parameter instance from this builder. */ - public InvoiceLineItemUpdateParams.Period build() { - return new InvoiceLineItemUpdateParams.Period(this.end, this.extraParams, this.start); - } - - /** - * Required. The end of the period, which must be greater than or equal to - * the start. This value is inclusive. - */ - public Builder setEnd(Long end) { - this.end = end; - return this; - } - - /** - * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` - * call, and subsequent calls add additional key/value pairs to the original map. See {@link - * InvoiceLineItemUpdateParams.Period#extraParams} for the field documentation. - */ - public Builder putExtraParam(String key, Object value) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.put(key, value); - return this; - } - - /** - * Add all map key/value pairs to `extraParams` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. - * See {@link InvoiceLineItemUpdateParams.Period#extraParams} for the field documentation. - */ - public Builder putAllExtraParam(Map map) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.putAll(map); - return this; - } - - /** Required. The start of the period. This value is inclusive. */ - public Builder setStart(Long start) { - this.start = start; - return this; - } - } - } - - @Getter - public static class PriceData { - /** - * Required. Three-letter ISO currency code, in lowercase. - * Must be a supported currency. - */ - @SerializedName("currency") - Object currency; - - /** - * Map of extra parameters for custom features not available in this client library. The content - * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each - * key/value pair is serialized as if the key is a root-level field (serialized) name in this - * param object. Effectively, this map is flattened to its parent instance. - */ - @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) - Map extraParams; - - /** - * The ID of the product that this price will belong to. One of {@code product} or {@code - * product_data} is required. - */ - @SerializedName("product") - Object product; - - /** - * Data used to generate a new product object inline. One of {@code product} or {@code - * product_data} is required. - */ - @SerializedName("product_data") - ProductData productData; - - /** - * Only required if a default - * tax behavior was not provided in the Stripe Tax settings. Specifies whether the price is - * considered inclusive of taxes or exclusive of taxes. One of {@code inclusive}, {@code - * exclusive}, or {@code unspecified}. Once specified as either {@code inclusive} or {@code - * exclusive}, it cannot be changed. - */ - @SerializedName("tax_behavior") - TaxBehavior taxBehavior; - - /** - * A non-negative integer in cents (or local equivalent) representing how much to charge. One of - * {@code unit_amount} or {@code unit_amount_decimal} is required. - */ - @SerializedName("unit_amount") - Long unitAmount; - - /** - * Same as {@code unit_amount}, but accepts a decimal value in cents (or local equivalent) with - * at most 12 decimal places. Only one of {@code unit_amount} and {@code unit_amount_decimal} - * can be set. - */ - @SerializedName("unit_amount_decimal") - Object unitAmountDecimal; - - private PriceData( - Object currency, - Map extraParams, - Object product, - ProductData productData, - TaxBehavior taxBehavior, - Long unitAmount, - Object unitAmountDecimal) { - this.currency = currency; - this.extraParams = extraParams; - this.product = product; - this.productData = productData; - this.taxBehavior = taxBehavior; - this.unitAmount = unitAmount; - this.unitAmountDecimal = unitAmountDecimal; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Object currency; - - private Map extraParams; - - private Object product; - - private ProductData productData; - - private TaxBehavior taxBehavior; - - private Long unitAmount; - - private Object unitAmountDecimal; - - /** Finalize and obtain parameter instance from this builder. */ - public InvoiceLineItemUpdateParams.PriceData build() { - return new InvoiceLineItemUpdateParams.PriceData( - this.currency, - this.extraParams, - this.product, - this.productData, - this.taxBehavior, - this.unitAmount, - this.unitAmountDecimal); - } - - /** - * Required. Three-letter ISO currency code, in - * lowercase. Must be a supported currency. - */ - public Builder setCurrency(String currency) { - this.currency = currency; - return this; - } - - /** - * Required. Three-letter ISO currency code, in - * lowercase. Must be a supported currency. - */ - public Builder setCurrency(EmptyParam currency) { - this.currency = currency; - return this; - } - - /** - * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` - * call, and subsequent calls add additional key/value pairs to the original map. See {@link - * InvoiceLineItemUpdateParams.PriceData#extraParams} for the field documentation. - */ - public Builder putExtraParam(String key, Object value) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.put(key, value); - return this; - } - - /** - * Add all map key/value pairs to `extraParams` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. - * See {@link InvoiceLineItemUpdateParams.PriceData#extraParams} for the field documentation. - */ - public Builder putAllExtraParam(Map map) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.putAll(map); - return this; - } - - /** - * The ID of the product that this price will belong to. One of {@code product} or {@code - * product_data} is required. - */ - public Builder setProduct(String product) { - this.product = product; - return this; - } - - /** - * The ID of the product that this price will belong to. One of {@code product} or {@code - * product_data} is required. - */ - public Builder setProduct(EmptyParam product) { - this.product = product; - return this; - } - - /** - * Data used to generate a new product object inline. One of {@code product} or {@code - * product_data} is required. - */ - public Builder setProductData(InvoiceLineItemUpdateParams.PriceData.ProductData productData) { - this.productData = productData; - return this; - } - - /** - * Only required if a default - * tax behavior was not provided in the Stripe Tax settings. Specifies whether the price - * is considered inclusive of taxes or exclusive of taxes. One of {@code inclusive}, {@code - * exclusive}, or {@code unspecified}. Once specified as either {@code inclusive} or {@code - * exclusive}, it cannot be changed. - */ - public Builder setTaxBehavior(InvoiceLineItemUpdateParams.PriceData.TaxBehavior taxBehavior) { - this.taxBehavior = taxBehavior; - return this; - } - - /** - * A non-negative integer in cents (or local equivalent) representing how much to charge. One - * of {@code unit_amount} or {@code unit_amount_decimal} is required. - */ - public Builder setUnitAmount(Long unitAmount) { - this.unitAmount = unitAmount; - return this; - } - - /** - * Same as {@code unit_amount}, but accepts a decimal value in cents (or local equivalent) - * with at most 12 decimal places. Only one of {@code unit_amount} and {@code - * unit_amount_decimal} can be set. - */ - public Builder setUnitAmountDecimal(BigDecimal unitAmountDecimal) { - this.unitAmountDecimal = unitAmountDecimal; - return this; - } - - /** - * Same as {@code unit_amount}, but accepts a decimal value in cents (or local equivalent) - * with at most 12 decimal places. Only one of {@code unit_amount} and {@code - * unit_amount_decimal} can be set. - */ - public Builder setUnitAmountDecimal(EmptyParam unitAmountDecimal) { - this.unitAmountDecimal = unitAmountDecimal; - return this; - } - } - - @Getter - public static class ProductData { - /** - * The product's description, meant to be displayable to the customer. Use this field to - * optionally store a long form explanation of the product being sold for your own rendering - * purposes. - */ - @SerializedName("description") - Object description; - - /** - * Map of extra parameters for custom features not available in this client library. The - * content in this map is not serialized under this field's {@code @SerializedName} value. - * Instead, each key/value pair is serialized as if the key is a root-level field (serialized) - * name in this param object. Effectively, this map is flattened to its parent instance. - */ - @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) - Map extraParams; - - /** - * A list of up to 8 URLs of images for this product, meant to be displayable to the customer. - */ - @SerializedName("images") - List images; - - /** - * Set of key-value pairs that you can - * attach to an object. This can be useful for storing additional information about the object - * in a structured format. Individual keys can be unset by posting an empty value to them. All - * keys can be unset by posting an empty value to {@code metadata}. - */ - @SerializedName("metadata") - Map metadata; - - /** Required. The product's name, meant to be displayable to the customer. */ - @SerializedName("name") - Object name; - - /** A tax code ID. */ - @SerializedName("tax_code") - Object taxCode; - - private ProductData( - Object description, - Map extraParams, - List images, - Map metadata, - Object name, - Object taxCode) { - this.description = description; - this.extraParams = extraParams; - this.images = images; - this.metadata = metadata; - this.name = name; - this.taxCode = taxCode; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Object description; - - private Map extraParams; - - private List images; - - private Map metadata; - - private Object name; - - private Object taxCode; - - /** Finalize and obtain parameter instance from this builder. */ - public InvoiceLineItemUpdateParams.PriceData.ProductData build() { - return new InvoiceLineItemUpdateParams.PriceData.ProductData( - this.description, - this.extraParams, - this.images, - this.metadata, - this.name, - this.taxCode); - } - - /** - * The product's description, meant to be displayable to the customer. Use this field to - * optionally store a long form explanation of the product being sold for your own rendering - * purposes. - */ - public Builder setDescription(String description) { - this.description = description; - return this; - } - - /** - * The product's description, meant to be displayable to the customer. Use this field to - * optionally store a long form explanation of the product being sold for your own rendering - * purposes. - */ - public Builder setDescription(EmptyParam description) { - this.description = description; - return this; - } - - /** - * Add a key/value pair to `extraParams` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original - * map. See {@link InvoiceLineItemUpdateParams.PriceData.ProductData#extraParams} for the - * field documentation. - */ - public Builder putExtraParam(String key, Object value) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.put(key, value); - return this; - } - - /** - * Add all map key/value pairs to `extraParams` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original - * map. See {@link InvoiceLineItemUpdateParams.PriceData.ProductData#extraParams} for the - * field documentation. - */ - public Builder putAllExtraParam(Map map) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.putAll(map); - return this; - } - - /** - * Add an element to `images` list. A list is initialized for the first `add/addAll` call, - * and subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams.PriceData.ProductData#images} for the field documentation. - */ - public Builder addImage(String element) { - if (this.images == null) { - this.images = new ArrayList<>(); - } - this.images.add(element); - return this; - } - - /** - * Add all elements to `images` list. A list is initialized for the first `add/addAll` call, - * and subsequent calls adds additional elements to the original list. See {@link - * InvoiceLineItemUpdateParams.PriceData.ProductData#images} for the field documentation. - */ - public Builder addAllImage(List elements) { - if (this.images == null) { - this.images = new ArrayList<>(); - } - this.images.addAll(elements); - return this; - } - - /** - * Add a key/value pair to `metadata` map. A map is initialized for the first `put/putAll` - * call, and subsequent calls add additional key/value pairs to the original map. See {@link - * InvoiceLineItemUpdateParams.PriceData.ProductData#metadata} for the field documentation. - */ - public Builder putMetadata(String key, String value) { - if (this.metadata == null) { - this.metadata = new HashMap<>(); - } - this.metadata.put(key, value); - return this; - } - - /** - * Add all map key/value pairs to `metadata` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original - * map. See {@link InvoiceLineItemUpdateParams.PriceData.ProductData#metadata} for the field - * documentation. - */ - public Builder putAllMetadata(Map map) { - if (this.metadata == null) { - this.metadata = new HashMap<>(); - } - this.metadata.putAll(map); - return this; - } - - /** - * Required. The product's name, meant to be displayable to the customer. - */ - public Builder setName(String name) { - this.name = name; - return this; - } - - /** - * Required. The product's name, meant to be displayable to the customer. - */ - public Builder setName(EmptyParam name) { - this.name = name; - return this; - } - - /** A tax code ID. */ - public Builder setTaxCode(String taxCode) { - this.taxCode = taxCode; - return this; - } - - /** A tax code ID. */ - public Builder setTaxCode(EmptyParam taxCode) { - this.taxCode = taxCode; - return this; - } - } - } - - public enum TaxBehavior implements ApiRequestParams.EnumParam { - @SerializedName("exclusive") - EXCLUSIVE("exclusive"), - - @SerializedName("inclusive") - INCLUSIVE("inclusive"), - - @SerializedName("unspecified") - UNSPECIFIED("unspecified"); - - @Getter(onMethod_ = {@Override}) - private final String value; - - TaxBehavior(String value) { - this.value = value; - } - } - } - - @Getter - public static class TaxAmount { - /** Required. The amount, in cents (or local equivalent), of the tax. */ - @SerializedName("amount") - Long amount; - - /** - * Map of extra parameters for custom features not available in this client library. The content - * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each - * key/value pair is serialized as if the key is a root-level field (serialized) name in this - * param object. Effectively, this map is flattened to its parent instance. - */ - @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) - Map extraParams; - - /** - * Required. Data to find or create a TaxRate object. - * - *

Stripe automatically creates or reuses a TaxRate object for each tax amount. If the {@code - * tax_rate_data} exactly matches a previous value, Stripe will reuse the TaxRate object. - * TaxRate objects created automatically by Stripe are immediately archived, do not appear in - * the line item’s {@code tax_rates}, and cannot be directly added to invoices, payments, or - * line items. - */ - @SerializedName("tax_rate_data") - TaxRateData taxRateData; - - /** - * Required. The amount on which tax is calculated, in cents (or local - * equivalent). - */ - @SerializedName("taxable_amount") - Long taxableAmount; - - private TaxAmount( - Long amount, Map extraParams, TaxRateData taxRateData, Long taxableAmount) { - this.amount = amount; - this.extraParams = extraParams; - this.taxRateData = taxRateData; - this.taxableAmount = taxableAmount; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Long amount; - - private Map extraParams; - - private TaxRateData taxRateData; - - private Long taxableAmount; - - /** Finalize and obtain parameter instance from this builder. */ - public InvoiceLineItemUpdateParams.TaxAmount build() { - return new InvoiceLineItemUpdateParams.TaxAmount( - this.amount, this.extraParams, this.taxRateData, this.taxableAmount); - } - - /** Required. The amount, in cents (or local equivalent), of the tax. */ - public Builder setAmount(Long amount) { - this.amount = amount; - return this; - } - - /** - * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` - * call, and subsequent calls add additional key/value pairs to the original map. See {@link - * InvoiceLineItemUpdateParams.TaxAmount#extraParams} for the field documentation. - */ - public Builder putExtraParam(String key, Object value) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.put(key, value); - return this; - } - - /** - * Add all map key/value pairs to `extraParams` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. - * See {@link InvoiceLineItemUpdateParams.TaxAmount#extraParams} for the field documentation. - */ - public Builder putAllExtraParam(Map map) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.putAll(map); - return this; - } - - /** - * Required. Data to find or create a TaxRate object. - * - *

Stripe automatically creates or reuses a TaxRate object for each tax amount. If the - * {@code tax_rate_data} exactly matches a previous value, Stripe will reuse the TaxRate - * object. TaxRate objects created automatically by Stripe are immediately archived, do not - * appear in the line item’s {@code tax_rates}, and cannot be directly added to invoices, - * payments, or line items. - */ - public Builder setTaxRateData(InvoiceLineItemUpdateParams.TaxAmount.TaxRateData taxRateData) { - this.taxRateData = taxRateData; - return this; - } - - /** - * Required. The amount on which tax is calculated, in cents (or local - * equivalent). - */ - public Builder setTaxableAmount(Long taxableAmount) { - this.taxableAmount = taxableAmount; - return this; - } - } - - @Getter - public static class TaxRateData { - /** - * Two-letter country code (ISO - * 3166-1 alpha-2). - */ - @SerializedName("country") - Object country; - - /** - * An arbitrary string attached to the tax rate for your internal use only. It will not be - * visible to your customers. - */ - @SerializedName("description") - Object description; - - /** - * Required. The display name of the tax rate, which will be shown to users. - */ - @SerializedName("display_name") - Object displayName; - - /** - * Map of extra parameters for custom features not available in this client library. The - * content in this map is not serialized under this field's {@code @SerializedName} value. - * Instead, each key/value pair is serialized as if the key is a root-level field (serialized) - * name in this param object. Effectively, this map is flattened to its parent instance. - */ - @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) - Map extraParams; - - /** Required. This specifies if the tax rate is inclusive or exclusive. */ - @SerializedName("inclusive") - Boolean inclusive; - - /** - * The jurisdiction for the tax rate. You can use this label field for tax reporting purposes. - * It also appears on your customer’s invoice. - */ - @SerializedName("jurisdiction") - Object jurisdiction; - - /** - * Required. The statutory tax rate percent. This field accepts decimal - * values between 0 and 100 inclusive with at most 4 decimal places. To accommodate - * fixed-amount taxes, set the percentage to zero. Stripe will not display zero percentages on - * the invoice unless the {@code amount} of the tax is also zero. - */ - @SerializedName("percentage") - BigDecimal percentage; - - /** - * ISO 3166-2 subdivision code, - * without country prefix. For example, "NY" for New York, United States. - */ - @SerializedName("state") - Object state; - - /** The high-level tax type, such as {@code vat} or {@code sales_tax}. */ - @SerializedName("tax_type") - TaxType taxType; - - private TaxRateData( - Object country, - Object description, - Object displayName, - Map extraParams, - Boolean inclusive, - Object jurisdiction, - BigDecimal percentage, - Object state, - TaxType taxType) { - this.country = country; - this.description = description; - this.displayName = displayName; - this.extraParams = extraParams; - this.inclusive = inclusive; - this.jurisdiction = jurisdiction; - this.percentage = percentage; - this.state = state; - this.taxType = taxType; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Object country; - - private Object description; - - private Object displayName; - - private Map extraParams; - - private Boolean inclusive; - - private Object jurisdiction; - - private BigDecimal percentage; - - private Object state; - - private TaxType taxType; - - /** Finalize and obtain parameter instance from this builder. */ - public InvoiceLineItemUpdateParams.TaxAmount.TaxRateData build() { - return new InvoiceLineItemUpdateParams.TaxAmount.TaxRateData( - this.country, - this.description, - this.displayName, - this.extraParams, - this.inclusive, - this.jurisdiction, - this.percentage, - this.state, - this.taxType); - } - - /** - * Two-letter country code (ISO - * 3166-1 alpha-2). - */ - public Builder setCountry(String country) { - this.country = country; - return this; - } - - /** - * Two-letter country code (ISO - * 3166-1 alpha-2). - */ - public Builder setCountry(EmptyParam country) { - this.country = country; - return this; - } - - /** - * An arbitrary string attached to the tax rate for your internal use only. It will not be - * visible to your customers. - */ - public Builder setDescription(String description) { - this.description = description; - return this; - } - - /** - * An arbitrary string attached to the tax rate for your internal use only. It will not be - * visible to your customers. - */ - public Builder setDescription(EmptyParam description) { - this.description = description; - return this; - } - - /** - * Required. The display name of the tax rate, which will be shown to - * users. - */ - public Builder setDisplayName(String displayName) { - this.displayName = displayName; - return this; - } - - /** - * Required. The display name of the tax rate, which will be shown to - * users. - */ - public Builder setDisplayName(EmptyParam displayName) { - this.displayName = displayName; - return this; - } - - /** - * Add a key/value pair to `extraParams` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original - * map. See {@link InvoiceLineItemUpdateParams.TaxAmount.TaxRateData#extraParams} for the - * field documentation. - */ - public Builder putExtraParam(String key, Object value) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.put(key, value); - return this; - } - - /** - * Add all map key/value pairs to `extraParams` map. A map is initialized for the first - * `put/putAll` call, and subsequent calls add additional key/value pairs to the original - * map. See {@link InvoiceLineItemUpdateParams.TaxAmount.TaxRateData#extraParams} for the - * field documentation. - */ - public Builder putAllExtraParam(Map map) { - if (this.extraParams == null) { - this.extraParams = new HashMap<>(); - } - this.extraParams.putAll(map); - return this; - } - - /** Required. This specifies if the tax rate is inclusive or exclusive. */ - public Builder setInclusive(Boolean inclusive) { - this.inclusive = inclusive; - return this; - } - - /** - * The jurisdiction for the tax rate. You can use this label field for tax reporting - * purposes. It also appears on your customer’s invoice. - */ - public Builder setJurisdiction(String jurisdiction) { - this.jurisdiction = jurisdiction; - return this; - } - - /** - * The jurisdiction for the tax rate. You can use this label field for tax reporting - * purposes. It also appears on your customer’s invoice. - */ - public Builder setJurisdiction(EmptyParam jurisdiction) { - this.jurisdiction = jurisdiction; - return this; - } - - /** - * Required. The statutory tax rate percent. This field accepts decimal - * values between 0 and 100 inclusive with at most 4 decimal places. To accommodate - * fixed-amount taxes, set the percentage to zero. Stripe will not display zero percentages - * on the invoice unless the {@code amount} of the tax is also zero. - */ - public Builder setPercentage(BigDecimal percentage) { - this.percentage = percentage; - return this; - } - - /** - * ISO 3166-2 subdivision code, - * without country prefix. For example, "NY" for New York, United States. - */ - public Builder setState(String state) { - this.state = state; - return this; - } - - /** - * ISO 3166-2 subdivision code, - * without country prefix. For example, "NY" for New York, United States. - */ - public Builder setState(EmptyParam state) { - this.state = state; - return this; - } - - /** The high-level tax type, such as {@code vat} or {@code sales_tax}. */ - public Builder setTaxType( - InvoiceLineItemUpdateParams.TaxAmount.TaxRateData.TaxType taxType) { - this.taxType = taxType; - return this; - } - } - - public enum TaxType implements ApiRequestParams.EnumParam { - @SerializedName("amusement_tax") - AMUSEMENT_TAX("amusement_tax"), - - @SerializedName("communications_tax") - COMMUNICATIONS_TAX("communications_tax"), - - @SerializedName("gst") - GST("gst"), - - @SerializedName("hst") - HST("hst"), - - @SerializedName("igst") - IGST("igst"), - - @SerializedName("jct") - JCT("jct"), - - @SerializedName("lease_tax") - LEASE_TAX("lease_tax"), - - @SerializedName("pst") - PST("pst"), - - @SerializedName("qst") - QST("qst"), - - @SerializedName("rst") - RST("rst"), - - @SerializedName("sales_tax") - SALES_TAX("sales_tax"), - - @SerializedName("service_tax") - SERVICE_TAX("service_tax"), - - @SerializedName("vat") - VAT("vat"); - - @Getter(onMethod_ = {@Override}) - private final String value; - - TaxType(String value) { - this.value = value; - } - } - } - } -} diff --git a/src/main/java/com/stripe/service/InvoiceLineItemService.java b/src/main/java/com/stripe/service/InvoiceLineItemService.java index 6e3b149c6f4..b1dc41dd745 100644 --- a/src/main/java/com/stripe/service/InvoiceLineItemService.java +++ b/src/main/java/com/stripe/service/InvoiceLineItemService.java @@ -13,7 +13,6 @@ import com.stripe.net.RequestOptions; import com.stripe.net.StripeResponseGetter; import com.stripe.param.InvoiceLineItemListParams; -import com.stripe.param.InvoiceLineItemUpdateParams; public final class InvoiceLineItemService extends ApiService { public InvoiceLineItemService(StripeResponseGetter responseGetter) { @@ -65,61 +64,4 @@ public StripeCollection list( options, ApiMode.V1); } - /** - * 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( - String invoice, String lineItemId, InvoiceLineItemUpdateParams params) - throws StripeException { - return update(invoice, lineItemId, 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(String invoice, String lineItemId, RequestOptions options) - throws StripeException { - return update(invoice, lineItemId, (InvoiceLineItemUpdateParams) null, options); - } - /** - * 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(String invoice, String lineItemId) throws StripeException { - return update(invoice, lineItemId, (InvoiceLineItemUpdateParams) null, (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( - String invoice, String lineItemId, InvoiceLineItemUpdateParams params, RequestOptions options) - throws StripeException { - String path = - String.format( - "/v1/invoices/%s/lines/%s", - ApiResource.urlEncodeId(invoice), ApiResource.urlEncodeId(lineItemId)); - return getResponseGetter() - .request( - BaseAddress.API, - ApiResource.RequestMethod.POST, - path, - ApiRequestParams.paramsToMap(params), - InvoiceLineItem.class, - options, - ApiMode.V1); - } } From e564b73e2b67086ab71951524f451c6e2975b37f Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Wed, 29 Nov 2023 15:06:38 -0800 Subject: [PATCH 3/9] wip --- build.gradle | 4 ++++ src/main/java/com/stripe/StripeClient.java | 14 +++++++---- src/main/java/com/stripe/net/HttpClient.java | 2 +- .../stripe/net/LiveStripeResponseGetter.java | 17 ++++++++++--- .../java/com/stripe/net/RequestTelemetry.java | 24 +++++++++++++++++-- .../java/com/stripe/net/StripeRequest.java | 21 ++++++++++++++-- .../net/StripeResponseGetterOptions.java | 3 +-- 7 files changed, 71 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 77ed44fe9b0..e70ea622ad6 100644 --- a/build.gradle +++ b/build.gradle @@ -50,6 +50,10 @@ tasks.withType(JavaCompile) { // com.stripe.param.AccountUpdateParams.Individual.Address] within this file.) // We should fix this by having autogen use the fully-qualified class to eliminate ambiguity. check("SameNameButDifferent", net.ltgt.gradle.errorprone.CheckSeverity.OFF) + + // InlineMe (https://errorprone.info/docs/inlineme) seems neat, but in order to add these annotations + // we would be imposing another dependency on `errorprone` to our users, not worth it. + check("InlineMeSuggester", net.ltgt.gradle.errorprone.CheckSeverity.OFF) } } diff --git a/src/main/java/com/stripe/StripeClient.java b/src/main/java/com/stripe/StripeClient.java index 41246fd7c98..6fa6c913b64 100644 --- a/src/main/java/com/stripe/StripeClient.java +++ b/src/main/java/com/stripe/StripeClient.java @@ -3,6 +3,7 @@ import com.stripe.net.*; import java.net.PasswordAuthentication; import java.net.Proxy; +import java.util.Arrays; import lombok.Getter; /** @@ -13,15 +14,20 @@ public class StripeClient { private final StripeResponseGetter responseGetter; + + private static StripeResponseGetter responseGetterFromOptions(StripeResponseGetterOptions options) { + return new LiveStripeResponseGetter( + Arrays.asList("stripe_client"), options, null); + } /** * Constructs a StripeClient with default settings, using the provided API key. Use the builder * instead if you require more complex configuration. */ public StripeClient(String apiKey) { - this.responseGetter = - new LiveStripeResponseGetter(builder().setApiKey(apiKey).buildOptions(), null); + this.responseGetter = responseGetterFromOptions(builder().setApiKey(apiKey).buildOptions()); } + /** * Constructs a StripeClient with a custom StripeResponseGetter. * @@ -287,7 +293,7 @@ public com.stripe.service.WebhookEndpointService webhookEndpoints() { // The end of the section generated from our OpenAPI spec static class ClientStripeResponseGetterOptions extends StripeResponseGetterOptions { - // When adding setting here keep them in sync with settings in RequestOptions and + // When adding settings here, keep them in sync with settings in RequestOptions and // in the RequestOptions.merge method @Getter(onMethod_ = {@Override}) private final String apiKey; @@ -517,7 +523,7 @@ public String getConnectBase() { /** Constructs a {@link StripeClient} with the specified configuration. */ public StripeClient build() { - return new StripeClient(new LiveStripeResponseGetter(buildOptions(), null)); + return new StripeClient(responseGetterFromOptions(buildOptions())); } StripeResponseGetterOptions buildOptions() { diff --git a/src/main/java/com/stripe/net/HttpClient.java b/src/main/java/com/stripe/net/HttpClient.java index 7e692cc36ef..6f38ae8c198 100644 --- a/src/main/java/com/stripe/net/HttpClient.java +++ b/src/main/java/com/stripe/net/HttpClient.java @@ -67,7 +67,7 @@ private > T sendWithTelemetry( stopwatch.stop(); - requestTelemetry.maybeEnqueueMetrics(response, stopwatch.getElapsed()); + requestTelemetry.maybeEnqueueMetrics(response, stopwatch.getElapsed(), request.usage()); return response; } diff --git a/src/main/java/com/stripe/net/LiveStripeResponseGetter.java b/src/main/java/com/stripe/net/LiveStripeResponseGetter.java index dcfb61fdeb2..6c893b8bb35 100644 --- a/src/main/java/com/stripe/net/LiveStripeResponseGetter.java +++ b/src/main/java/com/stripe/net/LiveStripeResponseGetter.java @@ -15,11 +15,14 @@ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Type; +import java.util.Collections; +import java.util.List; import java.util.Map; public class LiveStripeResponseGetter implements StripeResponseGetter { private final HttpClient httpClient; private final StripeResponseGetterOptions options; + private final List usage; /** * Initializes a new instance of the {@link LiveStripeResponseGetter} class with default @@ -35,12 +38,18 @@ public LiveStripeResponseGetter() { * @param httpClient the HTTP client to use */ public LiveStripeResponseGetter(HttpClient httpClient) { - this(null, httpClient); + this(null, null, httpClient); } public LiveStripeResponseGetter(StripeResponseGetterOptions options, HttpClient httpClient) { + this(null, options, httpClient); + } + + public LiveStripeResponseGetter( + List usage, StripeResponseGetterOptions options, HttpClient httpClient) { this.options = options != null ? options : GlobalStripeResponseGetterOptions.INSTANCE; this.httpClient = (httpClient != null) ? httpClient : buildDefaultHttpClient(); + this.usage = usage != null ? usage : Collections.emptyList(); } @Override @@ -56,7 +65,8 @@ public T request( throws StripeException { String fullUrl = fullUrl(baseAddress, options, path); StripeRequest request = - new StripeRequest(method, fullUrl, params, RequestOptions.merge(this.options, options)); + new StripeRequest( + method, fullUrl, params, RequestOptions.merge(this.options, options), this.usage); StripeResponse response = httpClient.requestWithRetries(request); int responseCode = response.code(); @@ -96,7 +106,8 @@ public InputStream requestStream( String fullUrl = fullUrl(baseAddress, options, path); StripeRequest request = - new StripeRequest(method, fullUrl, params, RequestOptions.merge(this.options, options)); + new StripeRequest( + method, fullUrl, params, RequestOptions.merge(this.options, options), this.usage); StripeResponseStream responseStream = httpClient.requestStreamWithRetries(request); int responseCode = responseStream.code(); diff --git a/src/main/java/com/stripe/net/RequestTelemetry.java b/src/main/java/com/stripe/net/RequestTelemetry.java index 34a128c77d7..bb990561af6 100644 --- a/src/main/java/com/stripe/net/RequestTelemetry.java +++ b/src/main/java/com/stripe/net/RequestTelemetry.java @@ -4,6 +4,8 @@ import com.google.gson.annotations.SerializedName; import com.stripe.Stripe; import java.time.Duration; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.concurrent.ConcurrentLinkedQueue; import lombok.Data; @@ -45,14 +47,25 @@ public Optional getHeaderValue(HttpHeaders headers) { return Optional.of(gson.toJson(payload)); } + // TODO (major) remove this overload + /** + * @deprecated use {@link #maybeEnqueueMetrics(AbstractStripeResponse, Duration, List)} instead. + */ + @Deprecated + public void maybeEnqueueMetrics(AbstractStripeResponse response, Duration duration) { + maybeEnqueueMetrics(response, duration, new ArrayList()); + } + /** * If telemetry is enabled and the queue is not full, then enqueue a new metrics item; otherwise, * do nothing. * * @param response the Stripe response * @param duration the request duration + * @param usage a list of tracked features used by the corresponding request */ - public void maybeEnqueueMetrics(AbstractStripeResponse response, Duration duration) { + public void maybeEnqueueMetrics( + AbstractStripeResponse response, Duration duration, List usage) { if (!Stripe.enableTelemetry) { return; } @@ -65,7 +78,11 @@ public void maybeEnqueueMetrics(AbstractStripeResponse response, Duration dur return; } - RequestMetrics metrics = new RequestMetrics(response.requestId(), duration.toMillis()); + if (usage.size() == 0) { + usage = null; + } + + RequestMetrics metrics = new RequestMetrics(response.requestId(), duration.toMillis(), usage); prevRequestMetrics.add(metrics); } @@ -82,5 +99,8 @@ private static class RequestMetrics { @SerializedName("request_duration_ms") private final long requestDurationMs; + + @SerializedName("usage") + private final List usage; } } diff --git a/src/main/java/com/stripe/net/StripeRequest.java b/src/main/java/com/stripe/net/StripeRequest.java index 53acfea729a..af20ca956f7 100644 --- a/src/main/java/com/stripe/net/StripeRequest.java +++ b/src/main/java/com/stripe/net/StripeRequest.java @@ -7,6 +7,7 @@ import com.stripe.util.StringUtils; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -51,6 +52,9 @@ public class StripeRequest { /** The special modifiers of the request. */ RequestOptions options; + /** List of tracked behaviors associated with this request. */ + List usage; + /** * Initializes a new instance of the {@link StripeRequest} class. * @@ -58,13 +62,15 @@ public class StripeRequest { * @param url the URL of the request * @param params the parameters of the request * @param options the special modifiers of the request + * @param usage list of tracked behaviors associated with this request * @throws StripeException if the request cannot be initialized for any reason */ public StripeRequest( ApiResource.RequestMethod method, String url, Map params, - RequestOptions options) + RequestOptions options, + List usage) throws StripeException { try { this.params = (params != null) ? Collections.unmodifiableMap(params) : null; @@ -73,6 +79,7 @@ public StripeRequest( this.url = buildURL(method, url, params); this.content = buildContent(method, params); this.headers = buildHeaders(method, this.options); + this.usage = usage; } catch (IOException e) { throw new ApiConnectionException( String.format( @@ -85,6 +92,15 @@ public StripeRequest( } } + public StripeRequest( + ApiResource.RequestMethod method, + String url, + Map params, + RequestOptions options) + throws StripeException { + this(method, url, params, options, new ArrayList()); + } + /** * Returns a new {@link StripeRequest} instance with an additional header. * @@ -99,7 +115,8 @@ public StripeRequest withAdditionalHeader(String name, String value) { this.content, this.headers.withAdditionalHeader(name, value), this.params, - this.options); + this.options, + this.usage); } private static URL buildURL( diff --git a/src/main/java/com/stripe/net/StripeResponseGetterOptions.java b/src/main/java/com/stripe/net/StripeResponseGetterOptions.java index 6bec8421701..8aa2fbccb4a 100644 --- a/src/main/java/com/stripe/net/StripeResponseGetterOptions.java +++ b/src/main/java/com/stripe/net/StripeResponseGetterOptions.java @@ -5,8 +5,7 @@ /** Controls how the request is sent by {@link StripeResponseGetter} */ public abstract class StripeResponseGetterOptions { - - // When adding setting here keep them in sync with settings in RequestOptions and + // When adding settings here keep them in sync with settings in RequestOptions and // in the RequestOptions.merge method public abstract String getApiKey(); From 35bdc63fa7ae6b28ddc9f3541af51651ce846828 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Wed, 29 Nov 2023 15:40:21 -0800 Subject: [PATCH 4/9] Don't put it on the contructor --- src/main/java/com/stripe/StripeClient.java | 28 +++++++++++++------ .../stripe/net/LiveStripeResponseGetter.java | 13 +++------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/stripe/StripeClient.java b/src/main/java/com/stripe/StripeClient.java index 6fa6c913b64..930a1e98e81 100644 --- a/src/main/java/com/stripe/StripeClient.java +++ b/src/main/java/com/stripe/StripeClient.java @@ -14,28 +14,40 @@ public class StripeClient { private final StripeResponseGetter responseGetter; - - private static StripeResponseGetter responseGetterFromOptions(StripeResponseGetterOptions options) { - return new LiveStripeResponseGetter( - Arrays.asList("stripe_client"), options, null); - } /** * Constructs a StripeClient with default settings, using the provided API key. Use the builder * instead if you require more complex configuration. */ public StripeClient(String apiKey) { - this.responseGetter = responseGetterFromOptions(builder().setApiKey(apiKey).buildOptions()); + this(new LiveStripeResponseGetter(builder().setApiKey(apiKey).buildOptions(), null)); } - /** * Constructs a StripeClient with a custom StripeResponseGetter. * *

Use this for testing, or advanced use cases where you need to make fundamental changes to * how the StripeClient makes requests. + * + *

responseGetter should not be re-used across StripeClient and + * ApiResource.setStripeResponseGetter */ public StripeClient(StripeResponseGetter responseGetter) { this.responseGetter = responseGetter; + + if (this.responseGetter instanceof LiveStripeResponseGetter) { + // Setting usage via mutation instead of making a copy is necessary if we want to support + // users to create their own subclasses of LiveStripeResponseGetter to use here. + // + // Unfortunately, mutation could technically cause some non-obvious behavior in the case + // of re-use; e.g. + // + // var lsrg = new LiveStripeResponseGetter(); + // ApiResource.setStripeResponseGetter(lsrg); + // new StripeClient(lsrg); + // + // would cause e.g. Customer.create(...) to erroneously report "stripe_client" in usage + ((LiveStripeResponseGetter) this.responseGetter).setUsage(Arrays.asList("stripe_client")); + } } protected StripeResponseGetter getResponseGetter() { @@ -523,7 +535,7 @@ public String getConnectBase() { /** Constructs a {@link StripeClient} with the specified configuration. */ public StripeClient build() { - return new StripeClient(responseGetterFromOptions(buildOptions())); + return new StripeClient(new LiveStripeResponseGetter(buildOptions(), null)); } StripeResponseGetterOptions buildOptions() { diff --git a/src/main/java/com/stripe/net/LiveStripeResponseGetter.java b/src/main/java/com/stripe/net/LiveStripeResponseGetter.java index 6c893b8bb35..b8831e724c8 100644 --- a/src/main/java/com/stripe/net/LiveStripeResponseGetter.java +++ b/src/main/java/com/stripe/net/LiveStripeResponseGetter.java @@ -15,14 +15,15 @@ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Type; -import java.util.Collections; import java.util.List; import java.util.Map; +import lombok.Setter; public class LiveStripeResponseGetter implements StripeResponseGetter { private final HttpClient httpClient; private final StripeResponseGetterOptions options; - private final List usage; + + @Setter private List usage; /** * Initializes a new instance of the {@link LiveStripeResponseGetter} class with default @@ -38,18 +39,12 @@ public LiveStripeResponseGetter() { * @param httpClient the HTTP client to use */ public LiveStripeResponseGetter(HttpClient httpClient) { - this(null, null, httpClient); + this(null, httpClient); } public LiveStripeResponseGetter(StripeResponseGetterOptions options, HttpClient httpClient) { - this(null, options, httpClient); - } - - public LiveStripeResponseGetter( - List usage, StripeResponseGetterOptions options, HttpClient httpClient) { this.options = options != null ? options : GlobalStripeResponseGetterOptions.INSTANCE; this.httpClient = (httpClient != null) ? httpClient : buildDefaultHttpClient(); - this.usage = usage != null ? usage : Collections.emptyList(); } @Override From 2cabdb3106a1a324f1b3ed9f3a412952851947fa Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Wed, 29 Nov 2023 16:31:02 -0800 Subject: [PATCH 5/9] Test for usage setting --- src/test/java/com/stripe/StripeClientTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/com/stripe/StripeClientTest.java b/src/test/java/com/stripe/StripeClientTest.java index ac01a96aa81..c9534fdc095 100644 --- a/src/test/java/com/stripe/StripeClientTest.java +++ b/src/test/java/com/stripe/StripeClientTest.java @@ -5,6 +5,7 @@ import com.stripe.model.terminal.Reader; import com.stripe.net.*; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -43,4 +44,14 @@ public void clientOptionsDefaults() { assertEquals(Stripe.UPLOAD_API_BASE, options.getFilesBase()); assertEquals(0, options.getMaxNetworkRetries()); } + + @Test + public void setsUsageOnResponseGetter() throws Exception { + StripeResponseGetter responseGetter = new LiveStripeResponseGetter(); + new StripeClient(responseGetter); + Object usage = responseGetter.getClass().getDeclaredField("usage").get(responseGetter); + assertTrue(usage instanceof List); + assertEquals(1, ((List) usage).size()); + assertEquals("stripe_client", ((List) usage).get(0)); + } } From e2ece8d7385fe0fbc4ee6c37b0af4d2d497111bd Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Thu, 30 Nov 2023 14:12:35 -0800 Subject: [PATCH 6/9] More tests --- .../stripe/net/LiveStripeResponseGetter.java | 2 + .../LiveStripeResponseGetterTest.java | 48 ++++++++++++++++++ .../stripe/functional/StripeClientTest.java | 49 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/test/java/com/stripe/functional/StripeClientTest.java diff --git a/src/main/java/com/stripe/net/LiveStripeResponseGetter.java b/src/main/java/com/stripe/net/LiveStripeResponseGetter.java index b8831e724c8..66326dff85a 100644 --- a/src/main/java/com/stripe/net/LiveStripeResponseGetter.java +++ b/src/main/java/com/stripe/net/LiveStripeResponseGetter.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Type; +import java.util.Arrays; import java.util.List; import java.util.Map; import lombok.Setter; @@ -45,6 +46,7 @@ public LiveStripeResponseGetter(HttpClient httpClient) { public LiveStripeResponseGetter(StripeResponseGetterOptions options, HttpClient httpClient) { this.options = options != null ? options : GlobalStripeResponseGetterOptions.INSTANCE; this.httpClient = (httpClient != null) ? httpClient : buildDefaultHttpClient(); + this.usage = Arrays.asList(); } @Override diff --git a/src/test/java/com/stripe/functional/LiveStripeResponseGetterTest.java b/src/test/java/com/stripe/functional/LiveStripeResponseGetterTest.java index b811e89ef7f..beddf7e3e56 100644 --- a/src/test/java/com/stripe/functional/LiveStripeResponseGetterTest.java +++ b/src/test/java/com/stripe/functional/LiveStripeResponseGetterTest.java @@ -4,10 +4,14 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import com.stripe.BaseStripeTest; +import com.stripe.Stripe; import com.stripe.exception.ApiException; import com.stripe.exception.StripeException; +import com.stripe.model.Customer; import com.stripe.model.Subscription; import com.stripe.net.ApiResource; import com.stripe.net.HttpClient; @@ -17,8 +21,12 @@ import com.stripe.net.StripeRequest; import com.stripe.net.StripeResponse; import com.stripe.net.StripeResponseGetter; +import com.stripe.param.CustomerCreateParams; +import com.stripe.param.CustomerUpdateParams; import java.util.Collections; import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -43,4 +51,44 @@ public void testInvalidJson() throws StripeException { assertNotNull(exception.getCause()); assertThat(exception.getCause(), CoreMatchers.instanceOf(JsonSyntaxException.class)); } + + private Boolean originalTelemetry; + + @BeforeEach + public void setUp() { + this.originalTelemetry = Stripe.enableTelemetry; + Stripe.enableTelemetry = true; + } + + @AfterEach + public void tearDown() { + Stripe.enableTelemetry = originalTelemetry; + } + + @Test + public void testGlobalClientTelemetryTest() throws StripeException { + StripeResponseGetter responseGetterSpy = + Mockito.spy(new LiveStripeResponseGetter(null, httpClientSpy)); + // We need to explicitly override the ApiResource.responseGetter = networkSpy that's set + // in BaseStripeTest. Unfortunately, BaseStripeTest shares the response getter spy across + // StripeClient and the Global Client, and so the global client will erroneously report stripe + // client usage. + ApiResource.setStripeResponseGetter(responseGetterSpy); + Customer cus = Customer.create(CustomerCreateParams.builder().build()); + Mockito.reset(httpClientSpy); + cus.update(CustomerUpdateParams.builder().setDescription("hello").build()); + Mockito.verify(httpClientSpy) + .request( + Mockito.argThat( + stripeRequest -> { + JsonObject metrics = + new Gson() + .fromJson( + stripeRequest.headers().firstValue("X-Stripe-Client-Telemetry").get(), + JsonObject.class) + .get("last_request_metrics") + .getAsJsonObject(); + return !metrics.has("usage") && metrics.has("request_duration_ms"); + })); + } } diff --git a/src/test/java/com/stripe/functional/StripeClientTest.java b/src/test/java/com/stripe/functional/StripeClientTest.java new file mode 100644 index 00000000000..517866b0720 --- /dev/null +++ b/src/test/java/com/stripe/functional/StripeClientTest.java @@ -0,0 +1,49 @@ +package com.stripe.functional; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.stripe.BaseStripeTest; +import com.stripe.Stripe; +import com.stripe.exception.StripeException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +public class StripeClientTest extends BaseStripeTest { + + private Boolean originalTelemetry; + + @BeforeEach + public void setUp() { + this.originalTelemetry = Stripe.enableTelemetry; + Stripe.enableTelemetry = true; + } + + @AfterEach + public void tearDown() { + Stripe.enableTelemetry = originalTelemetry; + } + + @Test + public void testReportsUsageTelemetry() throws StripeException { + mockClient.customers().create(); + Mockito.reset(httpClientSpy); + mockClient.customers().update("cus_xyz"); + Mockito.verify(httpClientSpy) + .request( + Mockito.argThat( + stripeRequest -> { + String usage = + new Gson() + .fromJson( + stripeRequest.headers().firstValue("X-Stripe-Client-Telemetry").get(), + JsonObject.class) + .get("last_request_metrics") + .getAsJsonObject() + .get("usage") + .getAsString(); + return usage.equals("stripe_client"); + })); + } +} From f448977f146814fc17d26d76cf8ec519e614c4f5 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 1 Dec 2023 13:23:21 -0800 Subject: [PATCH 7/9] Fix reflective access --- src/test/java/com/stripe/StripeClientTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/stripe/StripeClientTest.java b/src/test/java/com/stripe/StripeClientTest.java index c9534fdc095..6160de01328 100644 --- a/src/test/java/com/stripe/StripeClientTest.java +++ b/src/test/java/com/stripe/StripeClientTest.java @@ -5,6 +5,8 @@ import com.stripe.model.terminal.Reader; import com.stripe.net.*; + +import java.lang.reflect.Field; import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; @@ -49,7 +51,9 @@ public void clientOptionsDefaults() { public void setsUsageOnResponseGetter() throws Exception { StripeResponseGetter responseGetter = new LiveStripeResponseGetter(); new StripeClient(responseGetter); - Object usage = responseGetter.getClass().getDeclaredField("usage").get(responseGetter); + Field field = responseGetter.getClass().getDeclaredField("usage"); + field.setAccessible(true); + Object usage = field.get(responseGetter); assertTrue(usage instanceof List); assertEquals(1, ((List) usage).size()); assertEquals("stripe_client", ((List) usage).get(0)); From 6348f4b23378cabcb66752fdaadcb932437ffdf0 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 1 Dec 2023 13:44:03 -0800 Subject: [PATCH 8/9] Fix tests --- src/test/java/com/stripe/BaseStripeTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/stripe/BaseStripeTest.java b/src/test/java/com/stripe/BaseStripeTest.java index db5812341e6..25ce015df47 100644 --- a/src/test/java/com/stripe/BaseStripeTest.java +++ b/src/test/java/com/stripe/BaseStripeTest.java @@ -121,6 +121,9 @@ public void setUpStripeMockUsage() { httpClientSpy = Mockito.spy(new HttpURLConnectionClient()); networkSpy = Mockito.spy(new LiveStripeResponseGetter(null, httpClientSpy)); mockClient = new StripeClient(networkSpy); + // The StripeClient constructor calls .setUsage on networkSpy, let's reset that so + // in the test cases we can just verify the calls we care about. + Mockito.reset(networkSpy); ApiResource.setStripeResponseGetter(networkSpy); OAuth.setGlobalResponseGetter(networkSpy); } From 104c47a918f0ab964095366d3579d313c130b966 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 1 Dec 2023 13:48:57 -0800 Subject: [PATCH 9/9] Format --- src/test/java/com/stripe/StripeClientTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/stripe/StripeClientTest.java b/src/test/java/com/stripe/StripeClientTest.java index 6160de01328..c55dbf00ddd 100644 --- a/src/test/java/com/stripe/StripeClientTest.java +++ b/src/test/java/com/stripe/StripeClientTest.java @@ -5,7 +5,6 @@ import com.stripe.model.terminal.Reader; import com.stripe.net.*; - import java.lang.reflect.Field; import java.util.List; import java.util.Map;