Skip to content

Commit

Permalink
Merge 934c838 into d243326
Browse files Browse the repository at this point in the history
  • Loading branch information
ramahalingam committed Sep 10, 2020
2 parents d243326 + 934c838 commit 6eb234a
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,22 @@ public HyperwalletTransferMethod createTransferMethod(String jsonCacheToken, Str
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>>() {
});
}

//--------------------------------------
// Upload documents for user endpoint
//--------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.hyperwallet.clientsdk.model;

import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hyperwallet.clientsdk.util.HyperwalletJsonConfiguration;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
import java.util.List;

@JsonFilter(HyperwalletJsonConfiguration.INCLUSION_FILTER)
@XmlRootElement
Expand All @@ -15,14 +17,18 @@ public class HyperwalletTransferMethod extends HyperwalletBaseMonitor {

public enum Type {BANK_ACCOUNT, WIRE_ACCOUNT, PREPAID_CARD, BANK_CARD, PAPER_CHECK, PAYPAL_ACCOUNT, VENMO_ACCOUNT}

public enum Status {ACTIVATED, INVALID, DE_ACTIVATED, PRE_ACTIVATED, SUSPENDED, LOST_OR_STOLEN, QUEUED, DECLINED, LOCKED, COMPLIANCE_HOLE, KYC_HOLD, VERIFIED}
public enum Status {ACTIVATED, INVALID, DE_ACTIVATED, PRE_ACTIVATED, SUSPENDED, LOST_OR_STOLEN, QUEUED, DECLINED, LOCKED, COMPLIANCE_HOLE,
KYC_HOLD, VERIFIED}

public enum CardType {PERSONALIZED, INSTANT_ISSUE, VIRTUAL}

public static enum VerificationStatus {EXPIRED, FAILED, UNDER_REVIEW, VERIFIED, REQUIRED, NOT_REQUIRED, READY_FOR_REVIEW, REQUESTED}

private String token;

private Type type;
private Status status;
private VerificationStatus verificationStatus;
private Date createdOn;
private String transferMethodCountry;
private String transferMethodCurrency;
Expand Down Expand Up @@ -53,6 +59,7 @@ public enum CardType {PERSONALIZED, INSTANT_ISSUE, VIRTUAL}
private String cardPackage;
private String cardNumber;
private HyperwalletPrepaidCard.Brand cardBrand;
@JsonFormat(pattern = "yyyy-MM", timezone = "UTC")
private Date dateOfExpiry;
private String cvv;

Expand Down Expand Up @@ -84,6 +91,7 @@ public enum CardType {PERSONALIZED, INSTANT_ISSUE, VIRTUAL}
private String stateProvince;
private String postalCode;
private String country;
private List<HyperwalletLink> links;

public String getToken() {
return token;
Expand Down Expand Up @@ -1365,4 +1373,46 @@ public HyperwalletTransferMethod clearCardBrand() {
this.cardBrand = null;
return this;
}

public VerificationStatus getVerificationStatus() {
return verificationStatus;
}

public void setVerificationStatus(VerificationStatus verificationStatus) {
addField("verificationStatus", verificationStatus);
this.verificationStatus = verificationStatus;
}

public HyperwalletTransferMethod verificationStatus(VerificationStatus verificationStatus) {
addField("verificationStatus", verificationStatus);
this.verificationStatus = verificationStatus;
return this;
}

public HyperwalletTransferMethod clearVerificationStatus() {
clearField("verificationStatus");
verificationStatus = null;
return this;
}

public List<HyperwalletLink> getLinks() {
return links;
}

public void setLinks(List<HyperwalletLink> links) {
addField("links", links);
this.links = links;
}

public HyperwalletTransferMethod links(List<HyperwalletLink> links) {
addField("links", links);
this.links = links;
return this;
}

public HyperwalletTransferMethod clearLinks() {
clearField("links");
this.links = null;
return this;
}
}
85 changes: 83 additions & 2 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
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.HyperwalletTransferMethod.Status;
import com.hyperwallet.clientsdk.model.HyperwalletTransferMethod.Type;
import com.hyperwallet.clientsdk.model.HyperwalletTransferMethod.VerificationStatus;
import com.hyperwallet.clientsdk.model.HyperwalletUser.Gender;
import com.hyperwallet.clientsdk.model.HyperwalletUser.ProfileType;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;
Expand All @@ -21,8 +28,7 @@
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.Header.header;
import static org.mockserver.model.JsonBody.json;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import static org.testng.Assert.*;

public class HyperwalletIT {

Expand Down Expand Up @@ -1347,6 +1353,81 @@ 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;
}

List<HyperwalletLink> hyperwalletLinks = new ArrayList<>();
HyperwalletLink hyperwalletLink = new HyperwalletLink();
hyperwalletLink.setHref(
"https://localhost-hyperwallet.aws.paylution.net:8181/rest/v4/users/usr-539f5e81-a52e-4bc5-aba7-f17de183c900/transfer-methods?limit"
+ "=100");
Map<String, String> mapParams = new HashMap<>();
mapParams.put("rel", "self");
hyperwalletLink.setParams(mapParams);
hyperwalletLinks.add(hyperwalletLink);

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

HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0);
HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0);
assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref())));
assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams());
}

//
// Program Accounts
//
Expand Down
53 changes: 53 additions & 0 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.hyperwallet.clientsdk.model.HyperwalletDocument.EDocumentCategory;
import com.hyperwallet.clientsdk.model.HyperwalletDocument.EIdentityVerificationType;
import com.hyperwallet.clientsdk.model.HyperwalletDocument.EKycDocumentVerificationStatus;
import com.hyperwallet.clientsdk.model.HyperwalletTransferMethod.Type;
import com.hyperwallet.clientsdk.model.HyperwalletUser.VerificationStatus;
import com.hyperwallet.clientsdk.util.HyperwalletApiClient;
import com.sun.jersey.multipart.FormDataMultiPart;
Expand Down Expand Up @@ -6286,6 +6287,58 @@ private HyperwalletTransferMethod createPrePopulatedTransferMethod() {
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)));

}

//--------------------------------------
// Business Stakeholders
//--------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.hyperwallet.clientsdk.model;

import com.hyperwallet.clientsdk.model.HyperwalletTransferMethod.VerificationStatus;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* @author fkrauthan
*/
public class HyperwalletTransferMethodTest extends BaseModelTest<HyperwalletTransferMethod> {
protected HyperwalletTransferMethod createBaseModel() {
HyperwalletTransferMethod transferMethod = new HyperwalletTransferMethod();
List<HyperwalletLink> hyperwalletLinkList = new ArrayList<>();
HyperwalletLink hyperwalletLink = new HyperwalletLink();
hyperwalletLinkList.add(hyperwalletLink);
transferMethod
.token("test-token")

Expand Down Expand Up @@ -81,7 +88,9 @@ protected HyperwalletTransferMethod createBaseModel() {
.city("test-city")
.stateProvince("test-state-province")
.postalCode("test-postal-code")
.country("test-country");
.country("test-country")
.verificationStatus(VerificationStatus.NOT_REQUIRED)
.links(hyperwalletLinkList);

return transferMethod;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
curl -X "GET" "https://api.sandbox.hyperwallet.com/rest/v4/users/usr-321ad2c1-df3f-4a7a-bce4-3e88416b54ad/transfer-methods" \
-u testuser@12345678:myAccPassw0rd \
-H "Accept: application/json"
Loading

0 comments on commit 6eb234a

Please sign in to comment.