Skip to content

Commit

Permalink
Added risk header support (#46)
Browse files Browse the repository at this point in the history
* Added HeaderData resource
* Incorporated HeaderData into models
* Updated version information
* Updated the change log and compiled the new JAR
  • Loading branch information
camerona93 authored Jan 23, 2017
1 parent d4bd1d6 commit 7bb662c
Show file tree
Hide file tree
Showing 19 changed files with 512 additions and 127 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2017-01-19
* Released v8.1.0, adding support for Risk Headers on API calls.

2016-12-21
* Released v8.0.0, updating API support to 2016-12-07
* Added support for optional account_id in CreditCard.authorize()
Expand Down
Binary file modified lib/wepay.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>com.wepay</groupId>
<artifactId>wepay-java-sdk</artifactId>
<version>8.0.0</version>
<version>8.1.0</version>

<name>wepay-java-sdk</name>
<description>WePay Java SDK</description>
Expand Down
68 changes: 55 additions & 13 deletions src/main/java/com/wepay/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,35 @@ public class Account extends WePayResource {
public Account(Long accountId) {
this.accountId = accountId;
}

public static Account fetch(Long accountId, String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
return Account.fetch(accountId, headerData);
}

public static Account fetch(Long accountId, HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject params = new JSONObject();
params.put("account_id", accountId);
String response = request("/account", params, accessToken);
String response = request("/account", params, headerData);
Account a = gson.fromJson(response, Account.class);
AccountData ad = gson.fromJson(response, AccountData.class);
a.accountData = ad;
return a;
}

public static Account[] find(AccountFindData findData, String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
return Account.find(findData, headerData);
}

public static Account[] find(AccountFindData findData, HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject params = new JSONObject();
if (findData.name != null) params.put("name", findData.name);
if (findData.referenceId != null) params.put("reference_id", findData.referenceId);
if (findData.sortOrder != null) params.put("sort_order", findData.sortOrder);
JSONArray results = new JSONArray(request("/account/find", params, accessToken));
JSONArray results = new JSONArray(request("/account/find", params, headerData));
Account[] found = new Account[results.length()];
for (int i = 0; i < found.length; i++) {
Account a = gson.fromJson(results.get(i).toString(), Account.class);
Expand All @@ -52,8 +64,14 @@ public static Account[] find(AccountFindData findData, String accessToken) throw
}
return found;
}

public static Account create(AccountData data, String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
return Account.create(data, headerData);
}

public static Account create(AccountData data, HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject params = new JSONObject();
params.put("name", data.name);
params.put("description", data.description);
Expand All @@ -73,13 +91,19 @@ public static Account create(AccountData data, String accessToken) throws JSONEx
String rbitsJson = gson.toJson(data.rbits);
params.put("rbits", new JSONArray(rbitsJson));
}
String response = request("/account/create", params, accessToken);
String response = request("/account/create", params, headerData);
Account a = gson.fromJson(response, Account.class);
a.accountData = data;
return a;
}

public void modify(AccountData data, String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
this.modify(data, headerData);
}

public void modify(AccountData data, HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject params = new JSONObject();
params.put("account_id", this.accountId);
if (data.name != null) params.put("name", data.name);
Expand All @@ -97,7 +121,7 @@ public void modify(AccountData data, String accessToken) throws JSONException, I
params.put("rbits", new JSONArray(rbitsJson));
}

String response = request("/account/modify", params, accessToken);
String response = request("/account/modify", params, headerData);
Account a = gson.fromJson(response, Account.class);
AccountData ad = gson.fromJson(response, AccountData.class);
ad.callbackUri = data.callbackUri;
Expand All @@ -109,15 +133,27 @@ public void modify(AccountData data, String accessToken) throws JSONException, I
this.actionReasons = a.actionReasons;
this.accountData = ad;
}

public void delete(String reason, String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
this.delete(reason, headerData);
}

public void delete(String reason, HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject params = new JSONObject();
params.put("account_id", this.accountId);
if (reason != null) params.put("reason", reason);
request("/account/delete", params, accessToken);
request("/account/delete", params, headerData);
}

public String getUpdateUri(AccountUpdateUriData data, String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
return this.getUpdateUri(data, headerData);
}

public String getUpdateUri(AccountUpdateUriData data, HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject params = new JSONObject();
params.put("account_id", this.accountId);
if (data.mode != null) {
Expand All @@ -132,15 +168,21 @@ public String getUpdateUri(AccountUpdateUriData data, String accessToken) throws
params.put("prefill_info", KYCPrefillInfoData.buildPrefillInfo(data.prefillInfo));
}

JSONObject object = new JSONObject(request("/account/get_update_uri", params, accessToken));
JSONObject object = new JSONObject(request("/account/get_update_uri", params, headerData));
return object.getString("uri");
}

public AccountReserveData getReserveDetails(String currency, String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
return this.getReserveDetails(currency, headerData);
}

public AccountReserveData getReserveDetails(String currency, HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject params = new JSONObject();
params.put("account_id", this.accountId);
if (currency != null) params.put("currency", currency);
String response = request("/account/get_reserve_details", params, accessToken);
String response = request("/account/get_reserve_details", params, headerData);
AccountReserveData ar = gson.fromJson(response, AccountReserveData.class);
return ar;
}
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/com/wepay/model/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,37 @@ public class App extends WePayResource {
protected AppData appData;

public static App fetch(String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
return App.fetch(headerData);
}

public static App fetch(HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject params = new JSONObject();
params.put("client_id", WePay.clientId);
params.put("client_secret", WePay.clientSecret);
String response = request("/app", params, accessToken);
String response = request("/app", params, headerData);
App a = gson.fromJson(response, App.class);
AppData ad = gson.fromJson(response, AppData.class);
ThemeObjectData atod = gson.fromJson(response, ThemeObjectData.class);
ad.themeObject = atod;
a.appData = ad;
return a;
}

public void modify(AppData data, String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
this.modify(data, headerData);
}

public void modify(AppData data, HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject params = new JSONObject();
params.put("client_id", WePay.clientId);
params.put("client_secret", WePay.clientSecret);
if (data.gaqDomains != null) params.put("gaq_domains", data.gaqDomains);
if (data.themeObject != null) params.put("theme_object", ThemeObjectData.buildThemeObject(data.themeObject));
JSONObject object = new JSONObject(request("/app/modify", params, accessToken));
JSONObject object = new JSONObject(request("/app/modify", params, headerData));
this.clientId = WePay.clientId;
this.status = object.getString("status");
if (this.appData == null) this.appData = data;
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/wepay/model/Batch.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ public class Batch extends WePayResource {
protected String call;
protected String referenceId;
protected Map response;

public static Batch[] create(BatchData[] calls, String accessToken) throws JSONException, IOException, WePayException {
HeaderData headerData = new HeaderData();
headerData.accessToken = accessToken;
return Batch.create(calls, headerData);
}

public static Batch[] create(BatchData[] calls, HeaderData headerData) throws JSONException, IOException, WePayException {
JSONObject batch = new JSONObject();
batch.put("client_id", WePay.clientId);
batch.put("client_secret", WePay.clientSecret);
Expand All @@ -33,7 +39,7 @@ public static Batch[] create(BatchData[] calls, String accessToken) throws JSONE
callsArray.put(call);
}
batch.put("calls", callsArray);
JSONObject object = new JSONObject(request("/batch/create", batch, accessToken));
JSONObject object = new JSONObject(request("/batch/create", batch, headerData));
JSONArray responses = object.getJSONArray("calls");
Batch[] response = new Batch[responses.length()];
for (int i = 0; i < response.length; i++) {
Expand Down
Loading

0 comments on commit 7bb662c

Please sign in to comment.