Skip to content

Commit 2598dc1

Browse files
Add non-autogen typed params Event/File/EphemeralKeys (#730)
* file create params with handling of file object * create file with typed params * list file with typed params update import order on files refactor file test * add ephemeral key create params * add event list params * null check for typed parameters
1 parent a917ac3 commit 2598dc1

12 files changed

+1160
-1
lines changed

src/main/java/com/stripe/model/EphemeralKey.java

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.stripe.exception.StripeException;
66
import com.stripe.net.ApiResource;
77
import com.stripe.net.RequestOptions;
8+
import com.stripe.param.EphemeralKeyCreateParams;
89

910
import java.util.List;
1011
import java.util.Map;
@@ -49,6 +50,20 @@ public class EphemeralKey extends ApiResource implements HasId {
4950

5051
transient String rawJson;
5152

53+
/**
54+
* Creates an ephemeral API key for a given resource.
55+
*
56+
* @param params request parameters
57+
* @param options request options. {@code stripeVersion} is required when creating ephemeral
58+
* keys. it must have non-null {@link RequestOptions#getStripeVersionOverride()}.
59+
* @return the new ephemeral key
60+
*/
61+
public static EphemeralKey create(EphemeralKeyCreateParams params, RequestOptions options)
62+
throws StripeException {
63+
checkNullTypedParams(classUrl(EphemeralKey.class), params);
64+
return create(params.toMap(), options);
65+
}
66+
5267
/**
5368
* Creates an ephemeral API key for a given resource.
5469
*

src/main/java/com/stripe/model/Event.java

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.stripe.exception.StripeException;
66
import com.stripe.net.ApiResource;
77
import com.stripe.net.RequestOptions;
8+
import com.stripe.param.EventListParams;
89

910
import java.util.Map;
1011

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

108+
/**
109+
* List events, going back up to 30 days. Each event data is rendered according to Stripe API
110+
* version at its creation time, specified in
111+
* <a href="https://stripe.com/docs/api/events/object">event object</a> {@code api_version}
112+
* attribute (not according to your current Stripe API version or {@code Stripe-Version} header).
113+
*/
114+
public static EventCollection list(EventListParams params) throws StripeException {
115+
return list(params, null);
116+
}
117+
107118
/**
108119
* List events, going back up to 30 days. Each event data is rendered according to Stripe API
109120
* version at its creation time, specified in
@@ -115,6 +126,17 @@ public static EventCollection list(Map<String, Object> params, RequestOptions op
115126
return requestCollection(classUrl(Event.class), params, EventCollection.class, options);
116127
}
117128

129+
/**
130+
* List events, going back up to 30 days. Each event data is rendered according to Stripe API
131+
* version at its creation time, specified in
132+
* <a href="https://stripe.com/docs/api/events/object">event object</a> {@code api_version}
133+
* attribute (not according to your current Stripe API version or {@code Stripe-Version} header).
134+
*/
135+
public static EventCollection list(EventListParams params, RequestOptions options)
136+
throws StripeException {
137+
return requestCollection(classUrl(Event.class), params, EventCollection.class, options);
138+
}
139+
118140
/**
119141
* Retrieves the details of an event. Supply the unique identifier of the event, which you might
120142
* have received in a webhook.

src/main/java/com/stripe/model/File.java

+39
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.stripe.exception.StripeException;
77
import com.stripe.net.ApiResource;
88
import com.stripe.net.RequestOptions;
9+
import com.stripe.param.FileCreateParams;
10+
import com.stripe.param.FileListParams;
911

1012
import java.util.Map;
1113

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

79+
/**
80+
* To upload a file to Stripe, you’ll need to send a request of type {@code multipart/form-data}.
81+
* The request should contain the file you would like to upload, as well as the parameters for
82+
* creating a file.
83+
*/
84+
public static File create(FileCreateParams params) throws StripeException {
85+
return create(params, (RequestOptions) null);
86+
}
87+
88+
/**
89+
* To upload a file to Stripe, you’ll need to send a request of type {@code multipart/form-data}.
90+
* The request should contain the file you would like to upload, as well as the parameters for
91+
* creating a file.
92+
*/
93+
public static File create(FileCreateParams params, RequestOptions options)
94+
throws StripeException {
95+
checkNullTypedParams(classUrl(File.class, Stripe.getUploadBase()), params);
96+
return create(params.toMap(), options);
97+
}
98+
7799
/**
78100
* To upload a file to Stripe, you’ll need to send a request of type {@code multipart/form-data}.
79101
* The request should contain the file you would like to upload, as well as the parameters for
@@ -102,6 +124,23 @@ public static FileCollection list(Map<String, Object> params, RequestOptions opt
102124
return requestCollection(classUrl(File.class), params, FileCollection.class, options);
103125
}
104126

127+
/**
128+
* Returns a list of the files that your account has access to. The files are returned sorted by
129+
* creation date, with the most recently created files appearing first.
130+
*/
131+
public static FileCollection list(FileListParams params) throws StripeException {
132+
return list(params, (RequestOptions) null);
133+
}
134+
135+
/**
136+
* Returns a list of the files that your account has access to. The files are returned sorted by
137+
* creation date, with the most recently created files appearing first.
138+
*/
139+
public static FileCollection list(FileListParams params, RequestOptions options)
140+
throws StripeException {
141+
return requestCollection(classUrl(File.class), params, FileCollection.class, options);
142+
}
143+
105144
/**
106145
* Retrieves the details of an existing file object. Supply the unique file ID from a file, and
107146
* Stripe will return the corresponding file object.

src/main/java/com/stripe/net/ApiResource.java

+15
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public static <T> T multipartRequest(ApiResource.RequestMethod method,
166166
public static <T> T request(ApiResource.RequestMethod method,
167167
String url, ApiRequestParams params, Class<T> clazz,
168168
RequestOptions options) throws StripeException {
169+
checkNullTypedParams(url, params);
169170
return request(method, url, params.toMap(), clazz, options);
170171
}
171172

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

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

209+
/**
210+
* Invalidate null typed parameters.
211+
* @param url request url associated with the given parameters.
212+
* @param params typed parameters to check for null value.
213+
*/
214+
public static void checkNullTypedParams(String url, ApiRequestParams params) {
215+
if (params == null) {
216+
throw new IllegalArgumentException(String.format("Found null params for %s. "
217+
+ "Please pass empty params using param builder via `builder().build()` instead.", url
218+
));
219+
}
220+
}
221+
207222
/**
208223
* When setting a String ID for an ExpandableField, we need to be careful about keeping the String
209224
* ID and the expanded object in sync. If they specify a new String ID that is different from the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.stripe.param;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import com.stripe.net.ApiRequestParams;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class EphemeralKeyCreateParams extends ApiRequestParams {
9+
/** The ID of the Customer you'd like to modify using the resulting ephemeral key. */
10+
@SerializedName("customer")
11+
String customer;
12+
13+
/** Specifies which fields in the response should be expanded. */
14+
@SerializedName("expand")
15+
List<String> expand;
16+
17+
/** The ID of the Issuing Card you'd like to access using the resulting ephemeral key. */
18+
@SerializedName("issuing_card")
19+
String issuingCard;
20+
21+
private EphemeralKeyCreateParams(String customer, List<String> expand, String issuingCard) {
22+
this.customer = customer;
23+
this.expand = expand;
24+
this.issuingCard = issuingCard;
25+
}
26+
27+
public static Builder builder() {
28+
return new com.stripe.param.EphemeralKeyCreateParams.Builder();
29+
}
30+
31+
public static class Builder {
32+
private String customer;
33+
34+
private List<String> expand;
35+
36+
private String issuingCard;
37+
38+
/** Finalize and obtain parameter instance from this builder. */
39+
public EphemeralKeyCreateParams build() {
40+
return new EphemeralKeyCreateParams(this.customer, this.expand, this.issuingCard);
41+
}
42+
43+
/** The ID of the Customer you'd like to modify using the resulting ephemeral key. */
44+
public Builder setCustomer(String customer) {
45+
this.customer = customer;
46+
return this;
47+
}
48+
49+
/**
50+
* Add an element to `expand` list. A list is initialized for the first `add/addAll` call, and
51+
* subsequent calls adds additional elements to the original list. See {@link
52+
* EphemeralKeyCreateParams#expand} for the field documentation.
53+
*/
54+
public Builder addExpand(String element) {
55+
if (this.expand == null) {
56+
this.expand = new ArrayList<>();
57+
}
58+
this.expand.add(element);
59+
return this;
60+
}
61+
62+
/**
63+
* Add all elements to `expand` list. A list is initialized for the first `add/addAll` call, and
64+
* subsequent calls adds additional elements to the original list. See {@link
65+
* EphemeralKeyCreateParams#expand} for the field documentation.
66+
*/
67+
public Builder addAllExpand(List<String> elements) {
68+
if (this.expand == null) {
69+
this.expand = new ArrayList<>();
70+
}
71+
this.expand.addAll(elements);
72+
return this;
73+
}
74+
75+
/** The ID of the Issuing Card you'd like to access using the resulting ephemeral key. */
76+
public Builder setIssuingCard(String issuingCard) {
77+
this.issuingCard = issuingCard;
78+
return this;
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)