Skip to content

Add non-autogen typed params Event/File/EphemeralKeys #730

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
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions src/main/java/com/stripe/model/EphemeralKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.stripe.exception.StripeException;
import com.stripe.net.ApiResource;
import com.stripe.net.RequestOptions;
import com.stripe.param.EphemeralKeyCreateParams;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -49,6 +50,20 @@ public class EphemeralKey extends ApiResource implements HasId {

transient String rawJson;

/**
* Creates an ephemeral API key for a given resource.
*
* @param params request parameters
* @param options request options. {@code stripeVersion} is required when creating ephemeral
* keys. it must have non-null {@link RequestOptions#getStripeVersionOverride()}.
* @return the new ephemeral key
*/
public static EphemeralKey create(EphemeralKeyCreateParams params, RequestOptions options)
throws StripeException {
checkNullTypedParams(classUrl(EphemeralKey.class), params);
return create(params.toMap(), options);
}

/**
* Creates an ephemeral API key for a given resource.
*
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/stripe/model/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.stripe.exception.StripeException;
import com.stripe.net.ApiResource;
import com.stripe.net.RequestOptions;
import com.stripe.param.EventListParams;

import java.util.Map;

Expand Down Expand Up @@ -104,6 +105,16 @@ public static EventCollection list(Map<String, Object> params) throws StripeExce
return list(params, null);
}

/**
* List events, going back up to 30 days. Each event data is rendered according to Stripe API
* version at its creation time, specified in
* <a href="https://stripe.com/docs/api/events/object">event object</a> {@code api_version}
* attribute (not according to your current Stripe API version or {@code Stripe-Version} header).
*/
public static EventCollection list(EventListParams params) throws StripeException {
return list(params, null);
}

/**
* List events, going back up to 30 days. Each event data is rendered according to Stripe API
* version at its creation time, specified in
Expand All @@ -115,6 +126,17 @@ public static EventCollection list(Map<String, Object> params, RequestOptions op
return requestCollection(classUrl(Event.class), params, EventCollection.class, options);
}

/**
* List events, going back up to 30 days. Each event data is rendered according to Stripe API
* version at its creation time, specified in
* <a href="https://stripe.com/docs/api/events/object">event object</a> {@code api_version}
* attribute (not according to your current Stripe API version or {@code Stripe-Version} header).
*/
public static EventCollection list(EventListParams params, RequestOptions options)
throws StripeException {
return requestCollection(classUrl(Event.class), params, EventCollection.class, options);
}

/**
* Retrieves the details of an event. Supply the unique identifier of the event, which you might
* have received in a webhook.
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/stripe/model/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.stripe.exception.StripeException;
import com.stripe.net.ApiResource;
import com.stripe.net.RequestOptions;
import com.stripe.param.FileCreateParams;
import com.stripe.param.FileListParams;

import java.util.Map;

Expand Down Expand Up @@ -74,6 +76,26 @@ public static File create(Map<String, Object> params) throws StripeException {
return create(params, (RequestOptions) null);
}

/**
* To upload a file to Stripe, you’ll need to send a request of type {@code multipart/form-data}.
* The request should contain the file you would like to upload, as well as the parameters for
* creating a file.
*/
public static File create(FileCreateParams params) throws StripeException {
return create(params, (RequestOptions) null);
}

/**
* To upload a file to Stripe, you’ll need to send a request of type {@code multipart/form-data}.
* The request should contain the file you would like to upload, as well as the parameters for
* creating a file.
*/
public static File create(FileCreateParams params, RequestOptions options)
throws StripeException {
checkNullTypedParams(classUrl(File.class, Stripe.getUploadBase()), params);
return create(params.toMap(), options);
}

/**
* To upload a file to Stripe, you’ll need to send a request of type {@code multipart/form-data}.
* The request should contain the file you would like to upload, as well as the parameters for
Expand Down Expand Up @@ -102,6 +124,23 @@ public static FileCollection list(Map<String, Object> params, RequestOptions opt
return requestCollection(classUrl(File.class), params, FileCollection.class, options);
}

/**
* Returns a list of the files that your account has access to. The files are returned sorted by
* creation date, with the most recently created files appearing first.
*/
public static FileCollection list(FileListParams params) throws StripeException {
return list(params, (RequestOptions) null);
}

/**
* Returns a list of the files that your account has access to. The files are returned sorted by
* creation date, with the most recently created files appearing first.
*/
public static FileCollection list(FileListParams params, RequestOptions options)
throws StripeException {
return requestCollection(classUrl(File.class), params, FileCollection.class, options);
}

/**
* Retrieves the details of an existing file object. Supply the unique file ID from a file, and
* Stripe will return the corresponding file object.
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/stripe/net/ApiResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public static <T> T multipartRequest(ApiResource.RequestMethod method,
public static <T> T request(ApiResource.RequestMethod method,
String url, ApiRequestParams params, Class<T> clazz,
RequestOptions options) throws StripeException {
checkNullTypedParams(url, params);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom error message here instead of failing in the next line toMap

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice!

return request(method, url, params.toMap(), clazz, options);
}

Expand All @@ -179,6 +180,7 @@ public static <T> T request(ApiResource.RequestMethod method,
public static <T extends StripeCollectionInterface<?>> T requestCollection(
String url, ApiRequestParams params, Class<T> clazz, RequestOptions options)
throws StripeException {
checkNullTypedParams(url, params);
return requestCollection(url, params.toMap(), clazz, options);
}

Expand All @@ -204,6 +206,19 @@ public static <T extends StripeCollectionInterface<?>> T requestCollection(
return collection;
}

/**
* Invalidate null typed parameters.
* @param url request url associated with the given parameters.
* @param params typed parameters to check for null value.
*/
public static void checkNullTypedParams(String url, ApiRequestParams params) {
if (params == null) {
throw new IllegalArgumentException(String.format("Found null params for %s. "
+ "Please pass empty params using param builder via `builder().build()` instead.", url
));
}
}

/**
* When setting a String ID for an ExpandableField, we need to be careful about keeping the String
* ID and the expanded object in sync. If they specify a new String ID that is different from the
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/com/stripe/param/EphemeralKeyCreateParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.stripe.param;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no change to this file from the generator. But I removed the comment that is generated.

 // Generated by com.stripe.generator.entity.SdkBuilder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


import com.google.gson.annotations.SerializedName;
import com.stripe.net.ApiRequestParams;
import java.util.ArrayList;
import java.util.List;

public class EphemeralKeyCreateParams extends ApiRequestParams {
/** The ID of the Customer you'd like to modify using the resulting ephemeral key. */
@SerializedName("customer")
String customer;

/** Specifies which fields in the response should be expanded. */
@SerializedName("expand")
List<String> expand;

/** The ID of the Issuing Card you'd like to access using the resulting ephemeral key. */
@SerializedName("issuing_card")
String issuingCard;

private EphemeralKeyCreateParams(String customer, List<String> expand, String issuingCard) {
this.customer = customer;
this.expand = expand;
this.issuingCard = issuingCard;
}

public static Builder builder() {
return new com.stripe.param.EphemeralKeyCreateParams.Builder();
}

public static class Builder {
private String customer;

private List<String> expand;

private String issuingCard;

/** Finalize and obtain parameter instance from this builder. */
public EphemeralKeyCreateParams build() {
return new EphemeralKeyCreateParams(this.customer, this.expand, this.issuingCard);
}

/** The ID of the Customer you'd like to modify using the resulting ephemeral key. */
public Builder setCustomer(String customer) {
this.customer = customer;
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
* EphemeralKeyCreateParams#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
* EphemeralKeyCreateParams#expand} for the field documentation.
*/
public Builder addAllExpand(List<String> elements) {
if (this.expand == null) {
this.expand = new ArrayList<>();
}
this.expand.addAll(elements);
return this;
}

/** The ID of the Issuing Card you'd like to access using the resulting ephemeral key. */
public Builder setIssuingCard(String issuingCard) {
this.issuingCard = issuingCard;
return this;
}
}
}
Loading