Skip to content

Commit 7bb662c

Browse files
authored
Added risk header support (#46)
* Added HeaderData resource * Incorporated HeaderData into models * Updated version information * Updated the change log and compiled the new JAR
1 parent d4bd1d6 commit 7bb662c

19 files changed

+512
-127
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2017-01-19
2+
* Released v8.1.0, adding support for Risk Headers on API calls.
3+
14
2016-12-21
25
* Released v8.0.0, updating API support to 2016-12-07
36
* Added support for optional account_id in CreditCard.authorize()

lib/wepay.jar

2.75 KB
Binary file not shown.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>com.wepay</groupId>
1010
<artifactId>wepay-java-sdk</artifactId>
11-
<version>8.0.0</version>
11+
<version>8.1.0</version>
1212

1313
<name>wepay-java-sdk</name>
1414
<description>WePay Java SDK</description>

src/main/java/com/wepay/model/Account.java

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,35 @@ public class Account extends WePayResource {
2626
public Account(Long accountId) {
2727
this.accountId = accountId;
2828
}
29-
29+
3030
public static Account fetch(Long accountId, String accessToken) throws JSONException, IOException, WePayException {
31+
HeaderData headerData = new HeaderData();
32+
headerData.accessToken = accessToken;
33+
return Account.fetch(accountId, headerData);
34+
}
35+
36+
public static Account fetch(Long accountId, HeaderData headerData) throws JSONException, IOException, WePayException {
3137
JSONObject params = new JSONObject();
3238
params.put("account_id", accountId);
33-
String response = request("/account", params, accessToken);
39+
String response = request("/account", params, headerData);
3440
Account a = gson.fromJson(response, Account.class);
3541
AccountData ad = gson.fromJson(response, AccountData.class);
3642
a.accountData = ad;
3743
return a;
3844
}
39-
45+
4046
public static Account[] find(AccountFindData findData, String accessToken) throws JSONException, IOException, WePayException {
47+
HeaderData headerData = new HeaderData();
48+
headerData.accessToken = accessToken;
49+
return Account.find(findData, headerData);
50+
}
51+
52+
public static Account[] find(AccountFindData findData, HeaderData headerData) throws JSONException, IOException, WePayException {
4153
JSONObject params = new JSONObject();
4254
if (findData.name != null) params.put("name", findData.name);
4355
if (findData.referenceId != null) params.put("reference_id", findData.referenceId);
4456
if (findData.sortOrder != null) params.put("sort_order", findData.sortOrder);
45-
JSONArray results = new JSONArray(request("/account/find", params, accessToken));
57+
JSONArray results = new JSONArray(request("/account/find", params, headerData));
4658
Account[] found = new Account[results.length()];
4759
for (int i = 0; i < found.length; i++) {
4860
Account a = gson.fromJson(results.get(i).toString(), Account.class);
@@ -52,8 +64,14 @@ public static Account[] find(AccountFindData findData, String accessToken) throw
5264
}
5365
return found;
5466
}
55-
67+
5668
public static Account create(AccountData data, String accessToken) throws JSONException, IOException, WePayException {
69+
HeaderData headerData = new HeaderData();
70+
headerData.accessToken = accessToken;
71+
return Account.create(data, headerData);
72+
}
73+
74+
public static Account create(AccountData data, HeaderData headerData) throws JSONException, IOException, WePayException {
5775
JSONObject params = new JSONObject();
5876
params.put("name", data.name);
5977
params.put("description", data.description);
@@ -73,13 +91,19 @@ public static Account create(AccountData data, String accessToken) throws JSONEx
7391
String rbitsJson = gson.toJson(data.rbits);
7492
params.put("rbits", new JSONArray(rbitsJson));
7593
}
76-
String response = request("/account/create", params, accessToken);
94+
String response = request("/account/create", params, headerData);
7795
Account a = gson.fromJson(response, Account.class);
7896
a.accountData = data;
7997
return a;
8098
}
81-
99+
82100
public void modify(AccountData data, String accessToken) throws JSONException, IOException, WePayException {
101+
HeaderData headerData = new HeaderData();
102+
headerData.accessToken = accessToken;
103+
this.modify(data, headerData);
104+
}
105+
106+
public void modify(AccountData data, HeaderData headerData) throws JSONException, IOException, WePayException {
83107
JSONObject params = new JSONObject();
84108
params.put("account_id", this.accountId);
85109
if (data.name != null) params.put("name", data.name);
@@ -97,7 +121,7 @@ public void modify(AccountData data, String accessToken) throws JSONException, I
97121
params.put("rbits", new JSONArray(rbitsJson));
98122
}
99123

100-
String response = request("/account/modify", params, accessToken);
124+
String response = request("/account/modify", params, headerData);
101125
Account a = gson.fromJson(response, Account.class);
102126
AccountData ad = gson.fromJson(response, AccountData.class);
103127
ad.callbackUri = data.callbackUri;
@@ -109,15 +133,27 @@ public void modify(AccountData data, String accessToken) throws JSONException, I
109133
this.actionReasons = a.actionReasons;
110134
this.accountData = ad;
111135
}
112-
136+
113137
public void delete(String reason, String accessToken) throws JSONException, IOException, WePayException {
138+
HeaderData headerData = new HeaderData();
139+
headerData.accessToken = accessToken;
140+
this.delete(reason, headerData);
141+
}
142+
143+
public void delete(String reason, HeaderData headerData) throws JSONException, IOException, WePayException {
114144
JSONObject params = new JSONObject();
115145
params.put("account_id", this.accountId);
116146
if (reason != null) params.put("reason", reason);
117-
request("/account/delete", params, accessToken);
147+
request("/account/delete", params, headerData);
118148
}
119-
149+
120150
public String getUpdateUri(AccountUpdateUriData data, String accessToken) throws JSONException, IOException, WePayException {
151+
HeaderData headerData = new HeaderData();
152+
headerData.accessToken = accessToken;
153+
return this.getUpdateUri(data, headerData);
154+
}
155+
156+
public String getUpdateUri(AccountUpdateUriData data, HeaderData headerData) throws JSONException, IOException, WePayException {
121157
JSONObject params = new JSONObject();
122158
params.put("account_id", this.accountId);
123159
if (data.mode != null) {
@@ -132,15 +168,21 @@ public String getUpdateUri(AccountUpdateUriData data, String accessToken) throws
132168
params.put("prefill_info", KYCPrefillInfoData.buildPrefillInfo(data.prefillInfo));
133169
}
134170

135-
JSONObject object = new JSONObject(request("/account/get_update_uri", params, accessToken));
171+
JSONObject object = new JSONObject(request("/account/get_update_uri", params, headerData));
136172
return object.getString("uri");
137173
}
138174

139175
public AccountReserveData getReserveDetails(String currency, String accessToken) throws JSONException, IOException, WePayException {
176+
HeaderData headerData = new HeaderData();
177+
headerData.accessToken = accessToken;
178+
return this.getReserveDetails(currency, headerData);
179+
}
180+
181+
public AccountReserveData getReserveDetails(String currency, HeaderData headerData) throws JSONException, IOException, WePayException {
140182
JSONObject params = new JSONObject();
141183
params.put("account_id", this.accountId);
142184
if (currency != null) params.put("currency", currency);
143-
String response = request("/account/get_reserve_details", params, accessToken);
185+
String response = request("/account/get_reserve_details", params, headerData);
144186
AccountReserveData ar = gson.fromJson(response, AccountReserveData.class);
145187
return ar;
146188
}

src/main/java/com/wepay/model/App.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,37 @@ public class App extends WePayResource {
1717
protected AppData appData;
1818

1919
public static App fetch(String accessToken) throws JSONException, IOException, WePayException {
20+
HeaderData headerData = new HeaderData();
21+
headerData.accessToken = accessToken;
22+
return App.fetch(headerData);
23+
}
24+
25+
public static App fetch(HeaderData headerData) throws JSONException, IOException, WePayException {
2026
JSONObject params = new JSONObject();
2127
params.put("client_id", WePay.clientId);
2228
params.put("client_secret", WePay.clientSecret);
23-
String response = request("/app", params, accessToken);
29+
String response = request("/app", params, headerData);
2430
App a = gson.fromJson(response, App.class);
2531
AppData ad = gson.fromJson(response, AppData.class);
2632
ThemeObjectData atod = gson.fromJson(response, ThemeObjectData.class);
2733
ad.themeObject = atod;
2834
a.appData = ad;
2935
return a;
3036
}
31-
37+
3238
public void modify(AppData data, String accessToken) throws JSONException, IOException, WePayException {
39+
HeaderData headerData = new HeaderData();
40+
headerData.accessToken = accessToken;
41+
this.modify(data, headerData);
42+
}
43+
44+
public void modify(AppData data, HeaderData headerData) throws JSONException, IOException, WePayException {
3345
JSONObject params = new JSONObject();
3446
params.put("client_id", WePay.clientId);
3547
params.put("client_secret", WePay.clientSecret);
3648
if (data.gaqDomains != null) params.put("gaq_domains", data.gaqDomains);
3749
if (data.themeObject != null) params.put("theme_object", ThemeObjectData.buildThemeObject(data.themeObject));
38-
JSONObject object = new JSONObject(request("/app/modify", params, accessToken));
50+
JSONObject object = new JSONObject(request("/app/modify", params, headerData));
3951
this.clientId = WePay.clientId;
4052
this.status = object.getString("status");
4153
if (this.appData == null) this.appData = data;

src/main/java/com/wepay/model/Batch.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ public class Batch extends WePayResource {
1515
protected String call;
1616
protected String referenceId;
1717
protected Map response;
18-
18+
1919
public static Batch[] create(BatchData[] calls, String accessToken) throws JSONException, IOException, WePayException {
20+
HeaderData headerData = new HeaderData();
21+
headerData.accessToken = accessToken;
22+
return Batch.create(calls, headerData);
23+
}
24+
25+
public static Batch[] create(BatchData[] calls, HeaderData headerData) throws JSONException, IOException, WePayException {
2026
JSONObject batch = new JSONObject();
2127
batch.put("client_id", WePay.clientId);
2228
batch.put("client_secret", WePay.clientSecret);
@@ -33,7 +39,7 @@ public static Batch[] create(BatchData[] calls, String accessToken) throws JSONE
3339
callsArray.put(call);
3440
}
3541
batch.put("calls", callsArray);
36-
JSONObject object = new JSONObject(request("/batch/create", batch, accessToken));
42+
JSONObject object = new JSONObject(request("/batch/create", batch, headerData));
3743
JSONArray responses = object.getJSONArray("calls");
3844
Batch[] response = new Batch[responses.length()];
3945
for (int i = 0; i < response.length; i++) {

0 commit comments

Comments
 (0)