-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathConfiguration.java
More file actions
174 lines (137 loc) · 4.44 KB
/
Configuration.java
File metadata and controls
174 lines (137 loc) · 4.44 KB
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
package com.braintreegateway;
import com.braintreegateway.exceptions.ConfigurationException;
import com.braintreegateway.util.ClientLibraryProperties;
import com.braintreegateway.util.HttpClient;
import com.braintreegateway.util.JavaHttpClient;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Configuration {
private Environment environment;
private int timeout;
private int connectTimeout;
private Proxy proxy;
private String accessToken;
private String clientId;
private String clientSecret;
private String merchantId;
private String privateKey;
private String publicKey;
private HttpClient httpClient;
private static Logger logger;
static {
logger = Logger.getLogger("Braintree");
logger.setLevel(Level.INFO);
}
public static final String VERSION = new ClientLibraryProperties().version();
public static final String GRAPHQL_API_VERSION = "2018-05-21";
public static String apiVersion() {
return "6";
}
public Configuration(Environment environment, String merchantId, String publicKey, String privateKey) {
this.environment = environment;
if (merchantId == null || merchantId.isEmpty()) {
throw new ConfigurationException("merchantId needs to be set");
} else {
this.merchantId = merchantId;
}
if (publicKey == null || publicKey.isEmpty()) {
throw new ConfigurationException("publicKey needs to be set");
} else {
this.publicKey = publicKey;
}
if (privateKey == null || privateKey.isEmpty()) {
throw new ConfigurationException("privateKey needs to be set");
} else {
this.privateKey = privateKey;
}
}
public Configuration(String environment, String merchantId, String publicKey, String privateKey) {
this(Environment.parseEnvironment(environment), merchantId, publicKey, privateKey);
}
public Configuration(String clientId, String clientSecret) {
CredentialsParser parser = new CredentialsParser(clientId, clientSecret);
this.environment = parser.environment;
this.clientId = parser.clientId;
this.clientSecret = parser.clientSecret;
}
public Configuration(String accessToken) {
CredentialsParser parser = new CredentialsParser(accessToken);
this.environment = parser.environment;
this.merchantId = parser.merchantId;
this.accessToken = parser.accessToken;
}
public Environment getEnvironment() {
return environment;
}
public String getPrivateKey() {
return privateKey;
}
public String getPublicKey() {
return publicKey;
}
public String getClientId() {
return clientId;
}
public String getClientSecret() {
return clientSecret;
}
public Boolean isClientCredentials() {
return clientId != null;
}
public String getAccessToken() {
return accessToken;
}
public Boolean isAccessToken() {
return accessToken != null;
}
public String getMerchantPath() {
return "/merchants/" + merchantId;
}
public String getBaseURL() {
return environment.baseURL;
}
public String getGraphQLURL() {
return environment.graphQLURL;
}
public Boolean usesProxy() {
return proxy != null;
}
public void setProxy(String url, Integer port) {
this.proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(url, port));
}
public void setProxy(Proxy proxy) {
this.proxy = proxy;
}
public Proxy getProxy() {
return proxy;
}
public Logger getLogger() {
return logger;
}
public void setLogger(Logger log) {
logger = log;
}
public int getTimeout() {
return (timeout == 0) ? 60000 : timeout;
}
public void setTimeout(Integer timeout) {
this.timeout = timeout;
}
public int getConnectTimeout() {
return connectTimeout;
}
public void setConnectTimeout(Integer timeout) {
this.connectTimeout = timeout;
}
public HttpClient getHttpClient() {
if (httpClient == null) {
this.httpClient = new JavaHttpClient(this);
}
return httpClient;
}
public void setHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
}
}