Skip to content
Closed
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
45 changes: 44 additions & 1 deletion src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

/**
Expand Down Expand Up @@ -160,6 +161,21 @@ public HyperwalletList<HyperwalletUser> listUsers(HyperwalletPaginationOptions o
});
}

/**
* List Users
*
* @param options List filter option
* @return HyperwalletList of HyperwalletUser
*/
public HyperwalletList<HyperwalletUser> listUsers(HyperwalletUserListOptions options) {
String url = paginate(this.url + "/users", options);
if (options != null) {
url = addParameters(url, options.getParameters());
}
return apiClient.get(url, new TypeReference<HyperwalletList<HyperwalletUser>>() {
});
}

/**
* Get Authentication Token
*
Expand Down Expand Up @@ -1001,6 +1017,26 @@ public HyperwalletPayPalAccount getPayPalAccount(String userToken, String payPal
return apiClient.get(url + "/users/" + userToken + "/paypal-accounts/" + payPalAccountToken, HyperwalletPayPalAccount.class);
}

/**
* Updates the PayPal Account's email address
*
* @param account PayPal Account to update.
*
* @return HyperwalletPayPalAccount updated PayPal Account
*/
public HyperwalletPayPalAccount updatePayPalAccount(HyperwalletPayPalAccount account) {
if (account == null) {
throw new HyperwalletException("PayPal Account is required");
}
if (StringUtils.isEmpty(account.getUserToken())) {
throw new HyperwalletException("User token is required");
}
if (StringUtils.isEmpty(account.getToken())) {
throw new HyperwalletException("PayPal Account token is required");
}
return apiClient.put(url + "/users/" + account.getUserToken() + "/paypal-accounts/" + account.getToken(), account, HyperwalletPayPalAccount.class);
}

/**
* List PayPal Accounts
*
Expand Down Expand Up @@ -1851,6 +1887,14 @@ private String addParameter(String url, String key, Object value) {
return url + (url.indexOf("?") == -1 ? "?" : "&") + key + "=" + value;
}

private String addParameters(String url, Map<String, String> params)
{
for (Map.Entry<String, String> param : params.entrySet()) {
url = addParameter(url, param.getKey(), param.getValue());
}
return url;
}

private String convert(Date in) {
if (in == null) {
return null;
Expand Down Expand Up @@ -1923,5 +1967,4 @@ private HyperwalletPayPalAccount copy(HyperwalletPayPalAccount payPalAccount) {
payPalAccount = HyperwalletJsonUtil.fromJson(HyperwalletJsonUtil.toJson(payPalAccount), HyperwalletPayPalAccount.class);
return payPalAccount;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hyperwallet.clientsdk.model;

import java.util.Date;
import java.util.Map;

public class HyperwalletPaginationOptions {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.hyperwallet.clientsdk.model;

import java.util.HashMap;
import java.util.Map;

public class HyperwalletUserListOptions extends HyperwalletPaginationOptions
{
/**
* Return the user with this particular client-defined identifier.
*/
private String clientUserId;

/**
* Returns users with this email address.
*/
private String email;

/**
* Returns users belonging to program specified by the provided token.
*/
private String programToken;

/**
* Returns users with this account status.
*/
private HyperwalletUser.Status status;

/**
* The user's verification status. A user may be required to verify their identity after a certain
* threshold of payments is reached.
*/
private HyperwalletUser.VerificationStatus verificationStatus;

public String getClientUserId() {
return clientUserId;
}

public HyperwalletUserListOptions setClientUserId(String clientUserId) {
this.clientUserId = clientUserId;
return this;
}

public String getEmail() {
return email;
}

public HyperwalletUserListOptions setEmail(String email) {
this.email = email;
return this;
}

public String getProgramToken() {
return programToken;
}

public HyperwalletUserListOptions setProgramToken(String programToken) {
this.programToken = programToken;
return this;
}

public HyperwalletUser.Status getStatus() {
return status;
}

public HyperwalletUserListOptions setStatus(HyperwalletUser.Status status) {
this.status = status;
return this;
}

public HyperwalletUser.VerificationStatus getVerificationStatus() {
return verificationStatus;
}

public HyperwalletUserListOptions setVerificationStatus(HyperwalletUser.VerificationStatus verificationStatus) {
this.verificationStatus = verificationStatus;
return this;
}

public Map<String, String> getParameters() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I did like @dfreudenberger but I will ask you to stick with the current design. We are planning to do changes on all our server SDKs to support the changes in our REST v4 and I will keep it in mind to implement for all resources.

return new HashMap<String, String>() {{
put("clientUserId", clientUserId);
put("email", email);
put("programToken", programToken);
put("status", status == null ? null : status.name());
put("verificationStatus", verificationStatus == null ? null : verificationStatus.name());
}};
}
}
98 changes: 98 additions & 0 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -345,6 +346,25 @@ public void testListUsers_withSomeParameters() throws Exception {
Mockito.verify(mockApiClient).get(Mockito.eq("https://api.sandbox.hyperwallet.com/rest/v3/users?createdBefore=2016-06-29T17:58:26Z&sortBy=test-sort-by&offset=5"), Mockito.any(TypeReference.class));
}

@Test
public void testListUsers_withCustomParameters() throws Exception {
HyperwalletList<HyperwalletUser> response = new HyperwalletList<HyperwalletUser>();

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

HyperwalletUserListOptions options = new HyperwalletUserListOptions();
options.setLimit(100);
options.setEmail("test-email");

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

HyperwalletList<HyperwalletUser> resp = client.listUsers(options);
assertThat(resp, is(equalTo(response)));

Mockito.verify(mockApiClient).get(Mockito.eq("https://api.sandbox.hyperwallet.com/rest/v3/users?limit=100&email=test-email"), Mockito.any(TypeReference.class));
}

@Test
public void testGetUserStatusTransition_noUserToken() {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
Expand Down Expand Up @@ -3130,6 +3150,84 @@ public void testGetPayPalAccount_successful() throws Exception {
Mockito.verify(mockApiClient).get("https://api.sandbox.hyperwallet.com/rest/v3/users/test-user-token/paypal-accounts/test-paypal-account-token", payPalAccount.getClass());
}

@Test
public void testUpdatePayPalAccount_noPayPalAccount() {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.updatePayPalAccount(null);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("PayPal Account is required")));
assertThat(e.getMessage(), is(equalTo("PayPal Account is required")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
assertThat(e.getRelatedResources(), is(nullValue()));
}
}

@Test
public void testUpdatePayPalAccount_noUserToken() {
HyperwalletPayPalAccount account = new HyperwalletPayPalAccount();

Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.updatePayPalAccount(account);
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 testUpdatePayPalAccount_noPayPalAccountToken() {
HyperwalletPayPalAccount account = new HyperwalletPayPalAccount();
account.setUserToken("test-user-token");

Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.updatePayPalAccount(account);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("PayPal Account token is required")));
assertThat(e.getMessage(), is(equalTo("PayPal Account token is required")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
assertThat(e.getRelatedResources(), is(nullValue()));
}
}

@Test
public void testUpdatePayPalAccount_successful() throws Exception {
HyperwalletPayPalAccount account = new HyperwalletPayPalAccount();
account.setToken("test-paypal-account-token");
account.setUserToken("test-user-token");
account.setEmail("test-email");

HyperwalletPayPalAccount accountResponse = new HyperwalletPayPalAccount();

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

Mockito.when(mockApiClient.put(Mockito.anyString(), Mockito.anyObject(), Mockito.any(Class.class))).thenReturn(accountResponse);

HyperwalletPayPalAccount resp = client.updatePayPalAccount(account);
assertThat(resp, is(equalTo(accountResponse)));

ArgumentCaptor<HyperwalletPayPalAccount> argument = ArgumentCaptor.forClass(HyperwalletPayPalAccount.class);
Mockito.verify(mockApiClient).put(Mockito.eq("https://api.sandbox.hyperwallet.com/rest/v3/users/test-user-token/paypal-accounts/test-paypal-account-token"), argument.capture(), Mockito.eq(account.getClass()));

HyperwalletPayPalAccount apiClientBankAccount = argument.getValue();
assertThat(apiClientBankAccount, is(notNullValue()));
assertThat(apiClientBankAccount.getEmail(), is(equalTo("test-email")));
}

@Test
public void testListPayPalAccount_noUserToken() {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
Expand Down