|
| 1 | +// File generated from our OpenAPI spec |
| 2 | +package com.stripe.model.productcatalog; |
| 3 | + |
| 4 | +import com.google.gson.annotations.SerializedName; |
| 5 | +import com.stripe.exception.StripeException; |
| 6 | +import com.stripe.model.ExpandableField; |
| 7 | +import com.stripe.model.HasId; |
| 8 | +import com.stripe.model.Price; |
| 9 | +import com.stripe.model.StripeObject; |
| 10 | +import com.stripe.net.ApiRequest; |
| 11 | +import com.stripe.net.ApiRequestParams; |
| 12 | +import com.stripe.net.ApiResource; |
| 13 | +import com.stripe.net.BaseAddress; |
| 14 | +import com.stripe.net.RequestOptions; |
| 15 | +import com.stripe.net.StripeResponseGetter; |
| 16 | +import com.stripe.param.productcatalog.TrialOfferCreateParams; |
| 17 | +import java.util.Map; |
| 18 | +import lombok.EqualsAndHashCode; |
| 19 | +import lombok.Getter; |
| 20 | +import lombok.Setter; |
| 21 | + |
| 22 | +/** |
| 23 | + * Resource for the TrialOffer API, used to describe a subscription item's trial period settings. |
| 24 | + * Renders a TrialOffer object that describes the price, duration, end_behavior of a trial offer. |
| 25 | + */ |
| 26 | +@Getter |
| 27 | +@Setter |
| 28 | +@EqualsAndHashCode(callSuper = false) |
| 29 | +public class TrialOffer extends ApiResource implements HasId { |
| 30 | + @SerializedName("duration") |
| 31 | + Duration duration; |
| 32 | + |
| 33 | + @SerializedName("end_behavior") |
| 34 | + EndBehavior endBehavior; |
| 35 | + |
| 36 | + /** Unique identifier for the object. */ |
| 37 | + @Getter(onMethod_ = {@Override}) |
| 38 | + @SerializedName("id") |
| 39 | + String id; |
| 40 | + |
| 41 | + /** |
| 42 | + * Has the value {@code true} if the object exists in live mode or the value {@code false} if the |
| 43 | + * object exists in test mode. |
| 44 | + */ |
| 45 | + @SerializedName("livemode") |
| 46 | + Boolean livemode; |
| 47 | + |
| 48 | + /** |
| 49 | + * String representing the object's type. Objects of the same type share the same value. |
| 50 | + * |
| 51 | + * <p>Equal to {@code product_catalog.trial_offer}. |
| 52 | + */ |
| 53 | + @SerializedName("object") |
| 54 | + String object; |
| 55 | + |
| 56 | + /** The price during the trial offer. */ |
| 57 | + @SerializedName("price") |
| 58 | + @Getter(lombok.AccessLevel.NONE) |
| 59 | + @Setter(lombok.AccessLevel.NONE) |
| 60 | + ExpandableField<Price> price; |
| 61 | + |
| 62 | + /** Get ID of expandable {@code price} object. */ |
| 63 | + public String getPrice() { |
| 64 | + return (this.price != null) ? this.price.getId() : null; |
| 65 | + } |
| 66 | + |
| 67 | + public void setPrice(String id) { |
| 68 | + this.price = ApiResource.setExpandableFieldId(id, this.price); |
| 69 | + } |
| 70 | + |
| 71 | + /** Get expanded {@code price}. */ |
| 72 | + public Price getPriceObject() { |
| 73 | + return (this.price != null) ? this.price.getExpanded() : null; |
| 74 | + } |
| 75 | + |
| 76 | + public void setPriceObject(Price expandableObject) { |
| 77 | + this.price = new ExpandableField<Price>(expandableObject.getId(), expandableObject); |
| 78 | + } |
| 79 | + |
| 80 | + /** Creates a trial offer. */ |
| 81 | + public static TrialOffer create(Map<String, Object> params) throws StripeException { |
| 82 | + return create(params, (RequestOptions) null); |
| 83 | + } |
| 84 | + |
| 85 | + /** Creates a trial offer. */ |
| 86 | + public static TrialOffer create(Map<String, Object> params, RequestOptions options) |
| 87 | + throws StripeException { |
| 88 | + String path = "/v1/product_catalog/trial_offers"; |
| 89 | + ApiRequest request = |
| 90 | + new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.POST, path, params, options); |
| 91 | + return getGlobalResponseGetter().request(request, TrialOffer.class); |
| 92 | + } |
| 93 | + |
| 94 | + /** Creates a trial offer. */ |
| 95 | + public static TrialOffer create(TrialOfferCreateParams params) throws StripeException { |
| 96 | + return create(params, (RequestOptions) null); |
| 97 | + } |
| 98 | + |
| 99 | + /** Creates a trial offer. */ |
| 100 | + public static TrialOffer create(TrialOfferCreateParams params, RequestOptions options) |
| 101 | + throws StripeException { |
| 102 | + String path = "/v1/product_catalog/trial_offers"; |
| 103 | + ApiResource.checkNullTypedParams(path, params); |
| 104 | + ApiRequest request = |
| 105 | + new ApiRequest( |
| 106 | + BaseAddress.API, |
| 107 | + ApiResource.RequestMethod.POST, |
| 108 | + path, |
| 109 | + ApiRequestParams.paramsToMap(params), |
| 110 | + options); |
| 111 | + return getGlobalResponseGetter().request(request, TrialOffer.class); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * For more details about Duration, please refer to the <a href="https://docs.stripe.com/api">API |
| 116 | + * Reference.</a> |
| 117 | + */ |
| 118 | + @Getter |
| 119 | + @Setter |
| 120 | + @EqualsAndHashCode(callSuper = false) |
| 121 | + public static class Duration extends StripeObject { |
| 122 | + @SerializedName("relative") |
| 123 | + Relative relative; |
| 124 | + |
| 125 | + /** |
| 126 | + * The type of trial offer duration. |
| 127 | + * |
| 128 | + * <p>One of {@code relative}, or {@code timestamp}. |
| 129 | + */ |
| 130 | + @SerializedName("type") |
| 131 | + String type; |
| 132 | + |
| 133 | + /** |
| 134 | + * For more details about Relative, please refer to the <a |
| 135 | + * href="https://docs.stripe.com/api">API Reference.</a> |
| 136 | + */ |
| 137 | + @Getter |
| 138 | + @Setter |
| 139 | + @EqualsAndHashCode(callSuper = false) |
| 140 | + public static class Relative extends StripeObject { |
| 141 | + /** The number of iterations of the price's interval for this trial offer. */ |
| 142 | + @SerializedName("iterations") |
| 143 | + Long iterations; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * For more details about EndBehavior, please refer to the <a |
| 149 | + * href="https://docs.stripe.com/api">API Reference.</a> |
| 150 | + */ |
| 151 | + @Getter |
| 152 | + @Setter |
| 153 | + @EqualsAndHashCode(callSuper = false) |
| 154 | + public static class EndBehavior extends StripeObject { |
| 155 | + @SerializedName("transition") |
| 156 | + Transition transition; |
| 157 | + |
| 158 | + /** |
| 159 | + * The type of behavior when the trial offer ends. |
| 160 | + * |
| 161 | + * <p>Equal to {@code transition}. |
| 162 | + */ |
| 163 | + @SerializedName("type") |
| 164 | + String type; |
| 165 | + |
| 166 | + /** |
| 167 | + * For more details about Transition, please refer to the <a |
| 168 | + * href="https://docs.stripe.com/api">API Reference.</a> |
| 169 | + */ |
| 170 | + @Getter |
| 171 | + @Setter |
| 172 | + @EqualsAndHashCode(callSuper = false) |
| 173 | + public static class Transition extends StripeObject { |
| 174 | + /** The new price to use at the end of the trial offer period. */ |
| 175 | + @SerializedName("price") |
| 176 | + String price; |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + @Override |
| 181 | + public void setResponseGetter(StripeResponseGetter responseGetter) { |
| 182 | + super.setResponseGetter(responseGetter); |
| 183 | + trySetResponseGetter(duration, responseGetter); |
| 184 | + trySetResponseGetter(endBehavior, responseGetter); |
| 185 | + trySetResponseGetter(price, responseGetter); |
| 186 | + } |
| 187 | +} |
0 commit comments