-
Notifications
You must be signed in to change notification settings - Fork 356
/
Stripe.java
200 lines (170 loc) · 5.89 KB
/
Stripe.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package com.stripe;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.util.HashMap;
import java.util.Map;
public abstract class Stripe {
public static final int DEFAULT_CONNECT_TIMEOUT = 30 * 1000;
public static final int DEFAULT_READ_TIMEOUT = 80 * 1000;
public static final String API_VERSION = ApiVersion.CURRENT;
public static final String CONNECT_API_BASE = "https://connect.stripe.com";
public static final String LIVE_API_BASE = "https://api.stripe.com";
public static final String UPLOAD_API_BASE = "https://files.stripe.com";
public static final String VERSION = "25.11.0";
public static volatile String apiKey;
public static volatile String clientId;
public static volatile boolean enableTelemetry = true;
public static volatile String partnerId;
// Note that URLConnection reserves the value of 0 to mean "infinite
// timeout", so we use -1 here to represent an unset value which should
// fall back to a default.
private static volatile int connectTimeout = -1;
private static volatile int readTimeout = -1;
private static volatile int maxNetworkRetries = 0;
private static volatile String apiBase = LIVE_API_BASE;
private static volatile String connectBase = CONNECT_API_BASE;
private static volatile String uploadBase = UPLOAD_API_BASE;
private static volatile Proxy connectionProxy = null;
private static volatile PasswordAuthentication proxyCredential = null;
private static volatile Map<String, String> appInfo = null;
/**
* (FOR TESTING ONLY) If you'd like your API requests to hit your own (mocked) server, you can set
* this up here by overriding the base api URL.
*/
public static void overrideApiBase(final String overriddenApiBase) {
apiBase = overriddenApiBase;
}
public static String getApiBase() {
return apiBase;
}
/**
* (FOR TESTING ONLY) If you'd like your OAuth requests to hit your own (mocked) server, you can
* set this up here by overriding the base Connect URL.
*/
public static void overrideConnectBase(final String overriddenConnectBase) {
connectBase = overriddenConnectBase;
}
public static String getConnectBase() {
return connectBase;
}
/**
* (FOR TESTING ONLY) If you'd like your upload requests to hit your own (mocked) server, you can
* set this up here by overriding the base api URL.
*/
public static void overrideUploadBase(final String overriddenUploadBase) {
uploadBase = overriddenUploadBase;
}
public static String getUploadBase() {
return uploadBase;
}
/**
* Set proxy to tunnel all Stripe connections.
*
* @param proxy proxy host and port setting
*/
public static void setConnectionProxy(final Proxy proxy) {
connectionProxy = proxy;
}
public static Proxy getConnectionProxy() {
return connectionProxy;
}
/**
* Returns the connection timeout.
*
* @return timeout value in milliseconds
*/
public static int getConnectTimeout() {
if (connectTimeout == -1) {
return DEFAULT_CONNECT_TIMEOUT;
}
return connectTimeout;
}
/**
* Sets the timeout value that will be used for making new connections to the Stripe API (in
* milliseconds).
*
* @param timeout timeout value in milliseconds
*/
public static void setConnectTimeout(final int timeout) {
connectTimeout = timeout;
}
/**
* Returns the read timeout.
*
* @return timeout value in milliseconds
*/
public static int getReadTimeout() {
if (readTimeout == -1) {
return DEFAULT_READ_TIMEOUT;
}
return readTimeout;
}
/**
* Sets the timeout value that will be used when reading data from an established connection to
* the Stripe API (in milliseconds).
*
* <p>Note that this value should be set conservatively because some API requests can take time
* and a short timeout increases the likelihood of causing a problem in the backend.
*
* @param timeout timeout value in milliseconds
*/
public static void setReadTimeout(final int timeout) {
readTimeout = timeout;
}
/**
* Returns the maximum number of times requests will be retried.
*
* @return the maximum number of times requests will be retried
*/
public static int getMaxNetworkRetries() {
return maxNetworkRetries;
}
/**
* Sets the maximum number of times requests will be retried.
*
* @param numRetries the maximum number of times requests will be retried
*/
public static void setMaxNetworkRetries(final int numRetries) {
maxNetworkRetries = numRetries;
}
/**
* Provide credential for proxy authorization if required.
*
* @param auth proxy required userName and password
*/
public static void setProxyCredential(final PasswordAuthentication auth) {
proxyCredential = auth;
}
public static PasswordAuthentication getProxyCredential() {
return proxyCredential;
}
public static void setAppInfo(String name) {
setAppInfo(name, null, null, null);
}
public static void setAppInfo(String name, String version) {
setAppInfo(name, version, null, null);
}
public static void setAppInfo(String name, String version, String url) {
setAppInfo(name, version, url, null);
}
/**
* Sets information about your application. The information is passed along to Stripe.
*
* @param name Name of your application (e.g. "MyAwesomeApp")
* @param version Version of your application (e.g. "1.2.34")
* @param url Website for your application (e.g. "https://myawesomeapp.info")
* @param partnerId Your Stripe Partner ID (e.g. "pp_partner_1234")
*/
public static void setAppInfo(String name, String version, String url, String partnerId) {
if (appInfo == null) {
appInfo = new HashMap<String, String>();
}
appInfo.put("name", name);
appInfo.put("version", version);
appInfo.put("url", url);
appInfo.put("partner_id", partnerId);
}
public static Map<String, String> getAppInfo() {
return appInfo;
}
}