Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.TimeZone;

Expand Down Expand Up @@ -927,6 +928,62 @@ public HyperwalletList<HyperwalletWebhookNotification> listWebhookEvents(Hyperwa
return apiClient.get(url, new TypeReference<HyperwalletList<HyperwalletWebhookNotification>>() {});
}

//--------------------------------------
// Transfer Methods
//--------------------------------------

/**
* Create a Transfer Method
*
* @param jsonCacheToken String JSON cache token
* @param transferMethod TransferMethod object to create
* @return HyperwalletTransferMethod Transfer Method object created
*/
public HyperwalletTransferMethod createTransferMethod(String jsonCacheToken, HyperwalletTransferMethod transferMethod) {

if (transferMethod == null || StringUtils.isEmpty(transferMethod.getUserToken())) {
throw new HyperwalletException("User token is required");
}
if (StringUtils.isEmpty(jsonCacheToken)) {
throw new HyperwalletException("JSON token is required");
}
transferMethod = copy(transferMethod);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to check if transfer method type is set or we rely on service validators?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the documentation i was following you are correct.
https://confluence.site1.hyperwallet.local/pages/viewpage.action?pageId=22299508

the other SDKs seem to handle it at the service level.


transferMethod.setToken(null);
transferMethod.setStatus(null);
transferMethod.setCreatedOn(null);

HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Json-Cache-Token", jsonCacheToken);

return apiClient.post(url + "/users/" + transferMethod.getUserToken() + "/transfer-methods", transferMethod, HyperwalletTransferMethod.class, headers);
}


/**
* Create a Transfer Method
*
* @param jsonCacheToken String JSON cache token
* @param userToken String user token
* @return HyperwalletTransferMethod Transfer Method object created
*/
public HyperwalletTransferMethod createTransferMethod(String jsonCacheToken, String userToken) {

if (StringUtils.isEmpty(userToken)) {
throw new HyperwalletException("User token is required");
}
if (StringUtils.isEmpty(jsonCacheToken)) {
throw new HyperwalletException("JSON token is required");
}

HyperwalletTransferMethod transferMethod = new HyperwalletTransferMethod();
transferMethod.setUserToken(userToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we cannot create TransferMethod without Type? i.e. PREPAID_CARD, BANK_ACCOUNT, WIRE_ACCOUNT or PAPER_CHECK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if that is the case we should either not provide this method, or have a default value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this method for me should be removed since even if we set a default but in this context we cannot know for sure what are the users available transfer methods or the concept of default transfer method to a specific user given only the user token, please also confirm with @fkrauthan-hyperwallet thanks.


HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Json-Cache-Token", jsonCacheToken);

return apiClient.post(url + "/users/" + transferMethod.getUserToken() + "/transfer-methods", transferMethod, HyperwalletTransferMethod.class, headers);
}
//--------------------------------------
// Internal utils
//--------------------------------------
Expand Down Expand Up @@ -998,4 +1055,9 @@ private HyperwalletStatusTransition copy(HyperwalletStatusTransition statusTrans
return statusTransition;
}

private HyperwalletTransferMethod copy(HyperwalletTransferMethod transferMethod) {
transferMethod = HyperwalletJsonUtil.fromJson(HyperwalletJsonUtil.toJson(transferMethod), HyperwalletTransferMethod.class);
return transferMethod;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import cc.protea.util.http.Response;
import com.fasterxml.jackson.core.type.TypeReference;
import com.hyperwallet.clientsdk.HyperwalletException;
import com.hyperwallet.clientsdk.model.*;
import com.hyperwallet.clientsdk.model.HyperwalletErrorList;

import javax.xml.bind.DatatypeConverter;
import java.io.IOException;
import java.util.HashMap;

public class HyperwalletApiClient {

Expand Down Expand Up @@ -68,6 +69,25 @@ public <T> T post(final String url, final Object bodyObject, final Class<T> type
}
}

public <T> T post(final String url, final Object bodyObject, final Class<T> type, HashMap<String,String> header) {
Response response = null;
try {
String body = convert(bodyObject);
Request request = getService(url, false).setBody(body);

if (header != null) {
for (String key : header.keySet()) {
request = request.addHeader(key, header.get(key));
}
}

response = request.postResource();
return processResponse(response, type);
} catch (IOException e) {
throw new HyperwalletException(e);
}
}

protected <T> T processResponse(final Response response, final Class<T> type) {
checkErrorResponse(response);
if (response.getResponseCode() == 204) {
Expand Down
Loading