Skip to content

Add discounts to SessionCreateParams #1130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions src/main/java/com/stripe/param/checkout/SessionCreateParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public class SessionCreateParams extends ApiRequestParams {
@SerializedName("customer_email")
String customerEmail;

/**
* The coupon or promotion code to apply to this session. Currently, only up to one may be
* specified.
*/
@SerializedName("discounts")
List<Discount> discounts;

/** Specifies which fields in the response should be expanded. */
@SerializedName("expand")
List<String> expand;
Expand Down Expand Up @@ -165,6 +172,7 @@ private SessionCreateParams(
String clientReferenceId,
String customer,
String customerEmail,
List<Discount> discounts,
List<String> expand,
Map<String, Object> extraParams,
List<LineItem> lineItems,
Expand All @@ -184,6 +192,7 @@ private SessionCreateParams(
this.clientReferenceId = clientReferenceId;
this.customer = customer;
this.customerEmail = customerEmail;
this.discounts = discounts;
this.expand = expand;
this.extraParams = extraParams;
this.lineItems = lineItems;
Expand Down Expand Up @@ -216,6 +225,8 @@ public static class Builder {

private String customerEmail;

private List<Discount> discounts;

private List<String> expand;

private Map<String, Object> extraParams;
Expand Down Expand Up @@ -251,6 +262,7 @@ public SessionCreateParams build() {
this.clientReferenceId,
this.customer,
this.customerEmail,
this.discounts,
this.expand,
this.extraParams,
this.lineItems,
Expand Down Expand Up @@ -319,6 +331,32 @@ public Builder setCustomerEmail(String customerEmail) {
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
* SessionCreateParams#discounts} for the field documentation.
*/
public Builder addDiscount(Discount element) {
if (this.discounts == null) {
this.discounts = new ArrayList<>();
}
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
* SessionCreateParams#discounts} for the field documentation.
*/
public Builder addAllDiscount(List<Discount> elements) {
if (this.discounts == null) {
this.discounts = new ArrayList<>();
}
this.discounts.addAll(elements);
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
Expand Down Expand Up @@ -527,6 +565,87 @@ public Builder setSuccessUrl(String successUrl) {
}
}

@Getter
public static class Discount {
/** The ID of the coupon to apply to this session. */
@SerializedName("coupon")
String coupon;

/**
* 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<String, Object> extraParams;

/** The ID of a promotion code to apply to this session. */
@SerializedName("promotion_code")
String promotionCode;

private Discount(String coupon, Map<String, Object> extraParams, String promotionCode) {
this.coupon = coupon;
this.extraParams = extraParams;
this.promotionCode = promotionCode;
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private String coupon;

private Map<String, Object> extraParams;

private String promotionCode;

/** Finalize and obtain parameter instance from this builder. */
public Discount build() {
return new Discount(this.coupon, this.extraParams, this.promotionCode);
}

/** The ID of the coupon to apply to this session. */
public Builder setCoupon(String coupon) {
this.coupon = coupon;
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
* SessionCreateParams.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 SessionCreateParams.Discount#extraParams} for the field documentation.
*/
public Builder putAllExtraParam(Map<String, Object> map) {
if (this.extraParams == null) {
this.extraParams = new HashMap<>();
}
this.extraParams.putAll(map);
return this;
}

/** The ID of a promotion code to apply to this session. */
public Builder setPromotionCode(String promotionCode) {
this.promotionCode = promotionCode;
return this;
}
}
}

@Getter
public static class LineItem {
/**
Expand Down