Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.
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
20 changes: 19 additions & 1 deletion src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2175,8 +2175,26 @@ public HyperwalletTransferMethod createTransferMethod(String jsonCacheToken, Str
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);
return apiClient.post(url + "/users/" + transferMethod.getUserToken() + "/transfer-methods", transferMethod, HyperwalletTransferMethod.class,
headers);
}

/**
* List Transfer Methods
*
* @param userToken String user token
* @param options List filter option
* @return HyperwalletList of HyperwalletTransferMethod
*/
public HyperwalletList<HyperwalletTransferMethod> listTransferMethods(String userToken, HyperwalletPaginationOptions options) {
String url = paginate(this.url + "/users/" + userToken + "/transfer-methods", options);
if (StringUtils.isEmpty(userToken)) {
throw new HyperwalletException("User token is required");
}
return apiClient.get(url, new TypeReference<HyperwalletList<HyperwalletTransferMethod>>() {
});
}

//--------------------------------------
// Internal utils
//--------------------------------------
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.hyperwallet.clientsdk;

import com.hyperwallet.clientsdk.model.*;
import com.hyperwallet.clientsdk.model.HyperwalletPrepaidCard.Brand;
import com.hyperwallet.clientsdk.model.HyperwalletTransferMethod.CardType;
import com.hyperwallet.clientsdk.model.HyperwalletUser.*;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpRequest;
Expand Down Expand Up @@ -1170,6 +1172,63 @@ public void testGetPaymentStatusTransition() throws Exception {
assertThat(returnValue.getToStatus(), is(equalTo(COMPLETED)));
}

@Test
public void testListTransferMethods() throws Exception {
String functionality = "listTransferMethods";
initMockServer(functionality);

HyperwalletList<HyperwalletTransferMethod> returnValue;
try {
String userToken = "usr-321ad2c1-df3f-4a7a-bce4-3e88416b54ad";
returnValue = client.listTransferMethods(userToken, null);
} catch (Exception e) {
mockServer.verify(parseRequest(functionality));
throw e;
}

HyperwalletTransferMethod brandTransferMethod = returnValue.getData().get(0);
assertThat(brandTransferMethod.getToken(), is(equalTo("trm-a43b1064-da94-457f-ae56-e4f85bd36aec")));
assertThat(brandTransferMethod.getType(), is(equalTo(HyperwalletTransferMethod.Type.BANK_ACCOUNT)));
assertThat(brandTransferMethod.getStatus(), is(equalTo(HyperwalletTransferMethod.Status.ACTIVATED)));
assertThat(brandTransferMethod.getCreatedOn(), is(equalTo(dateFormat.parse("2020-09-09T18:43:10 UTC"))));
assertThat(brandTransferMethod.getTransferMethodCountry(), is(equalTo("US")));
assertThat(brandTransferMethod.getTransferMethodCurrency(), is(equalTo("USD")));
assertThat(brandTransferMethod.getBranchId(), is(equalTo("021000021")));
assertThat(brandTransferMethod.getBankAccountId(), is(equalTo("1599657189")));
assertThat(brandTransferMethod.getBankAccountPurpose(), is(equalTo("SAVINGS")));
assertThat(brandTransferMethod.getUserToken(), is(equalTo("usr-539f5e81-a52e-4bc5-aba7-f17de183c900")));
assertThat(brandTransferMethod.getProfileType(), is(equalTo(ProfileType.INDIVIDUAL)));
assertThat(brandTransferMethod.getFirstName(), is(equalTo("FirstName")));
assertThat(brandTransferMethod.getLastName(), is(equalTo("LastName")));
assertThat(brandTransferMethod.getDateOfBirth(), is(equalTo(dateFormat.parse("2000-09-09T18:43:10 UTC"))));
assertThat(brandTransferMethod.getGender(), is(equalTo(Gender.MALE)));
assertThat(brandTransferMethod.getPhoneNumber(), is(equalTo("605-555-1323")));
assertThat(brandTransferMethod.getMobileNumber(), is(equalTo("605-555-1323")));
assertThat(brandTransferMethod.getGovernmentId(), is(equalTo("444444444")));
assertThat(brandTransferMethod.getAddressLine1(), is(equalTo("1234 IndividualAddress St")));
assertThat(brandTransferMethod.getAddressLine2(), is(equalTo("1234 AddressLineTwo St")));
assertThat(brandTransferMethod.getCity(), is(equalTo("TestCity")));
assertThat(brandTransferMethod.getStateProvince(), is(equalTo("CA")));
assertThat(brandTransferMethod.getCountry(), is(equalTo("US")));
assertThat(brandTransferMethod.getPostalCode(), is(equalTo("12345")));

HyperwalletTransferMethod cardTransferMethod = returnValue.getData().get(1);

assertThat(cardTransferMethod.getToken(), is(equalTo("trm-c8e4c164-7d5b-4b5b-8b6a-9c4d68c2a9fe")));
assertThat(cardTransferMethod.getType(), is(equalTo(HyperwalletTransferMethod.Type.PREPAID_CARD)));
assertThat(cardTransferMethod.getStatus(), is(equalTo(HyperwalletTransferMethod.Status.PRE_ACTIVATED)));
assertThat(cardTransferMethod.getCreatedOn(), is(equalTo(dateFormat.parse("2020-09-09T18:43:34 UTC"))));
assertThat(cardTransferMethod.getTransferMethodCountry(), is(equalTo("US")));
assertThat(cardTransferMethod.getTransferMethodCurrency(), is(equalTo("USD")));
assertThat(cardTransferMethod.getCardType(), is(equalTo(CardType.PERSONALIZED)));
assertThat(cardTransferMethod.getCardPackage(), is(equalTo("L1")));
assertThat(cardTransferMethod.getCardNumber(), is(equalTo("************4194")));
assertThat(cardTransferMethod.getCardBrand(), is(equalTo(Brand.VISA)));
assertThat(cardTransferMethod.getDateOfExpiry(), is(equalTo(dateFormat.parse("2024-09-01T00:00:00 UTC"))));
assertThat(cardTransferMethod.getUserToken(), is(equalTo("usr-539f5e81-a52e-4bc5-aba7-f17de183c900")));

}

//
// Response with error
//
Expand Down
58 changes: 54 additions & 4 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.hyperwallet.clientsdk.model.*;
import com.hyperwallet.clientsdk.model.HyperwalletStatusTransition.Status;
import com.hyperwallet.clientsdk.model.HyperwalletTransferMethod.Type;
import com.hyperwallet.clientsdk.model.HyperwalletUser.VerificationStatus;
import com.hyperwallet.clientsdk.util.HyperwalletApiClient;
import org.mockito.ArgumentCaptor;
Expand All @@ -15,10 +16,7 @@
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.TimeZone;
import java.util.*;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
Expand Down Expand Up @@ -7171,4 +7169,56 @@ private HyperwalletTransferMethod createPrePopulatedTransferMethod() {
.country("test-country");
return transferMethod;
}

@Test
public void testListTransferMethods_noUserToken() {

Hyperwallet client = new Hyperwallet("test-username", "test-password");

try {
client.listTransferMethods(null, null);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("User token is required")));
assertThat(e.getMessage(), is(equalTo("User token is required")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
assertThat(e.getRelatedResources(), is(nullValue()));
}
}

@Test
public void testListTransferMethods() throws Exception {

String userToken = "user-token";
HyperwalletList<HyperwalletTransferMethod> response = new HyperwalletList<HyperwalletTransferMethod>();

List<HyperwalletTransferMethod> hyperwalletTransferMethodsList = new ArrayList<>();
HyperwalletTransferMethod bankTransferMethod = new HyperwalletTransferMethod();
bankTransferMethod.setToken("bank-token");
bankTransferMethod.setType(Type.BANK_ACCOUNT);
HyperwalletTransferMethod cardTransferMethod = new HyperwalletTransferMethod();
cardTransferMethod.setToken("card-token");
cardTransferMethod.setType(Type.PREPAID_CARD);
hyperwalletTransferMethodsList.add(bankTransferMethod);
hyperwalletTransferMethodsList.add(cardTransferMethod);

response.setData(hyperwalletTransferMethodsList);

Hyperwallet client = new Hyperwallet("test-username", "test-password");
HyperwalletApiClient mockApiClient = createAndInjectHyperwalletApiClientMock(client);

Mockito.when(mockApiClient.get(Mockito.anyString(), Mockito.any(TypeReference.class))).thenReturn(response);

HyperwalletList<HyperwalletTransferMethod> resp = client.listTransferMethods(userToken, null);
assertThat(resp, is(equalTo(response)));
HyperwalletTransferMethod response1 = response.getData().get(0);
HyperwalletTransferMethod response2 = response.getData().get(1);
assertThat(response1.getToken(), is(equalTo("bank-token")));
assertThat(response1.getType(), is(equalTo(Type.BANK_ACCOUNT)));
assertThat(response2.getToken(), is(equalTo("card-token")));
assertThat(response2.getType(), is(equalTo(Type.PREPAID_CARD)));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
curl -X "GET" "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-321ad2c1-df3f-4a7a-bce4-3e88416b54ad/transfer-methods" \
-u testuser@12345678:myAccPassw0rd \
-H "Accept: application/json"
73 changes: 73 additions & 0 deletions src/test/resources/integration/listTransferMethods-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"count": 2,
"offset": 0,
"limit": 10,
"data": [
{
"token": "trm-a43b1064-da94-457f-ae56-e4f85bd36aec",
"type": "BANK_ACCOUNT",
"status": "ACTIVATED",
"verificationStatus": "NOT_REQUIRED",
"createdOn": "2020-09-09T18:43:10",
"transferMethodCountry": "US",
"transferMethodCurrency": "USD",
"branchId": "021000021",
"bankAccountId": "1599657189",
"bankAccountPurpose": "SAVINGS",
"userToken": "usr-539f5e81-a52e-4bc5-aba7-f17de183c900",
"profileType": "INDIVIDUAL",
"firstName": "FirstName",
"lastName": "LastName",
"dateOfBirth": "2000-09-09T18:43:10",
"gender": "MALE",
"phoneNumber": "605-555-1323",
"mobileNumber": "605-555-1323",
"governmentId": "444444444",
"addressLine1": "1234 IndividualAddress St",
"addressLine2": "1234 AddressLineTwo St",
"city": "TestCity",
"stateProvince": "CA",
"country": "US",
"postalCode": "12345",
"links": [
{
"params": {
"rel": "self"
},
"href": "https://localhost-hyperwallet.aws.paylution.net:8181/rest/v3/users/usr-539f5e81-a52e-4bc5-aba7-f17de183c900/transfer-methods/trm-a43b1064-da94-457f-ae56-e4f85bd36aec"
}
]
},
{
"token": "trm-c8e4c164-7d5b-4b5b-8b6a-9c4d68c2a9fe",
"type": "PREPAID_CARD",
"status": "PRE_ACTIVATED",
"verificationStatus": "NOT_REQUIRED",
"createdOn": "2020-09-09T18:43:34",
"transferMethodCountry": "US",
"transferMethodCurrency": "USD",
"cardType": "PERSONALIZED",
"cardPackage": "L1",
"cardNumber": "************4194",
"cardBrand": "VISA",
"dateOfExpiry": "2024-09-01T00:00:00",
"userToken": "usr-539f5e81-a52e-4bc5-aba7-f17de183c900",
"links": [
{
"params": {
"rel": "self"
},
"href": "https://localhost-hyperwallet.aws.paylution.net:8181/rest/v3/users/usr-539f5e81-a52e-4bc5-aba7-f17de183c900/transfer-methods/trm-c8e4c164-7d5b-4b5b-8b6a-9c4d68c2a9fe"
}
]
}
],
"links": [
{
"params": {
"rel": "self"
},
"href": "https://localhost-hyperwallet.aws.paylution.net:8181/rest/v3/users/usr-539f5e81-a52e-4bc5-aba7-f17de183c900/transfer-methods?limit=100"
}
]
}