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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Changelog
=========
2.4.5
-------------------
- Added field 'accountId' to PayPal.
- PayPal account creation allowed using field 'accountId' which accepts Email, Phone Number, PayPal PayerID.
- Venmo account creation allowed using field 'accountId' which accepts Email, Phone Number, Venmo Handle, Venmo External ID.

2.4.4
-------------------
- Added attribute 'isDefaultTransferMethod' to identify default accounts.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1527,8 +1527,8 @@ public HyperwalletPayPalAccount createPayPalAccount(HyperwalletPayPalAccount pay
if (StringUtils.isEmpty(payPalAccount.getTransferMethodCurrency())) {
throw new HyperwalletException("Transfer Method Currency is required");
}
if (StringUtils.isEmpty(payPalAccount.getEmail())) {
throw new HyperwalletException("Email is required");
if (StringUtils.isEmpty(payPalAccount.getEmail()) && StringUtils.isEmpty(payPalAccount.getAccountId())) {
throw new HyperwalletException("Email or AccountId is required");
}
if (!StringUtils.isEmpty(payPalAccount.getToken())) {
throw new HyperwalletException("PayPal Account token may not be present");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum Type {PAYPAL_ACCOUNT}
private Boolean isDefaultTransferMethod;
private String email;
private String userToken;
private String accountId;
private List<HyperwalletLink> links;

public String getToken() {
Expand Down Expand Up @@ -197,6 +198,27 @@ public HyperwalletPayPalAccount clearEmail() {
return this;
}

public String getAccountId() {
return accountId;
}

public void setAccountId(String accountId) {
addField("accountId", accountId);
this.accountId = accountId;
}

public HyperwalletPayPalAccount accountId(String accountId) {
addField("accountId", accountId);
this.accountId = accountId;
return this;
}

public HyperwalletPayPalAccount clearAccountId() {
clearField("accountId");
this.accountId = null;
return this;
}

public String getUserToken() {
return userToken;
}
Expand Down
87 changes: 87 additions & 0 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3410,6 +3410,93 @@ public void testGetPayPalAccountDefaultTransfer() throws Exception {
}
}

@Test
Copy link
Collaborator

Choose a reason for hiding this comment

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

The testGetPayPalAccountDefaultTransfer() method is missing code.

public void testCreatePayPalAccountWithAccountId() throws Exception {
String functionality = "createPayPalAccountWithAccountId";
initMockServer(functionality);

HyperwalletPayPalAccount payPalAccount = new HyperwalletPayPalAccount()
.userToken("usr-e7b61829-a73a-45dc-930e-afa8a56b924c")
.transferMethodCountry("US")
.transferMethodCurrency("USD")
.type(HyperwalletPayPalAccount.Type.PAYPAL_ACCOUNT)
.accountId("K8QRQHMYWETL9");

HyperwalletPayPalAccount returnValue;
try {
returnValue = client.createPayPalAccount(payPalAccount);
} catch (Exception e) {
mockServer.verify(parseRequest(functionality));
throw e;
}
List<HyperwalletLink> hyperwalletLinks = new ArrayList<>();
HyperwalletLink hyperwalletLink = new HyperwalletLink();
hyperwalletLink.setHref(
"https://api.sandbox.hyperwallet.com/rest/v4/users/usr-e7b61829-a73a-45dc-930e-afa8a56b924c/paypal-accounts/trm-54b0db9c-5565-47f7"
+ "-aee6-685e713595f4");
Map<String, String> mapParams = new HashMap<>();
mapParams.put("rel", "self");
hyperwalletLink.setParams(mapParams);
hyperwalletLinks.add(hyperwalletLink);

assertThat(returnValue.getToken(), is(equalTo("trm-54b0db9c-5565-47f7-aee6-afa8a56b924c")));
assertThat(returnValue.getStatus(), is(equalTo(HyperwalletPayPalAccount.Status.ACTIVATED)));
assertThat(returnValue.getType(), is(equalTo(HyperwalletPayPalAccount.Type.PAYPAL_ACCOUNT)));
assertThat(returnValue.getCreatedOn(), is(equalTo(dateFormat.parse("2022-11-11T00:00:00 UTC"))));
assertThat(returnValue.getTransferMethodCountry(), is(equalTo("US")));
assertThat(returnValue.getTransferMethodCurrency(), is(equalTo("USD")));
assertThat(returnValue.getAccountId(), is(equalTo("K8QRQHMYWETL9")));
if (returnValue.getLinks() != null) {
HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0);
HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0);
assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref())));
assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams());
}
}

@Test
public void testCreateVenmoAccountWithEmail() throws Exception {
String functionality = "createVenmoAccountWithEmail";
initMockServer(functionality);

HyperwalletVenmoAccount venmoAccount = new HyperwalletVenmoAccount()
.userToken("usr-c4292f1a-866f-4310-a289-b916853939ef")
.transferMethodCountry("US")
.transferMethodCurrency("USD")
.type(HyperwalletVenmoAccount.Type.VENMO_ACCOUNT)
.accountId("user@domain.com");

HyperwalletVenmoAccount returnValue;
try {
returnValue = client.createVenmoAccount(venmoAccount);
} catch (Exception e) {
mockServer.verify(parseRequest(functionality));
throw e;
}
List<HyperwalletLink> hyperwalletLinks = new ArrayList<>();
HyperwalletLink hyperwalletLink = new HyperwalletLink();
hyperwalletLink.setHref(
"https://api.sandbox.hyperwallet.com/rest/v4/users/usr-c4292f1a-866f-4310-a289-b916853939ef/venmo-accounts/trm-ac5727ac-8fe7-42fb"
+ "-b69d-977ebdd7b49c");
Map<String, String> mapParams = new HashMap<>();
mapParams.put("rel", "self");
hyperwalletLink.setParams(mapParams);
hyperwalletLinks.add(hyperwalletLink);
assertThat(returnValue.getToken(), is(equalTo("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b49c")));
assertThat(returnValue.getStatus(), is(equalTo(HyperwalletVenmoAccount.Status.ACTIVATED)));
assertThat(returnValue.getType(), is(equalTo(HyperwalletVenmoAccount.Type.VENMO_ACCOUNT)));
assertThat(returnValue.getCreatedOn(), is(equalTo(dateFormat.parse("2022-11-11T22:50:14 UTC"))));
assertThat(returnValue.getTransferMethodCountry(), is(equalTo("US")));
assertThat(returnValue.getTransferMethodCurrency(), is(equalTo("USD")));
assertThat(returnValue.getAccountId(), is(equalTo("user@domain.com")));
if (returnValue.getLinks() != null) {
HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0);
HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0);
assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref())));
assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams());
}
}

private void initMockServerWithErrorResponse(String functionality) throws IOException {
mockServer.reset();
mockServer
Expand Down
42 changes: 40 additions & 2 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3656,8 +3656,8 @@ public void testCreatePayPalAccount_noEmail() {
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("Email is required")));
assertThat(e.getMessage(), is(equalTo("Email is required")));
assertThat(e.getErrorMessage(), is(equalTo("Email or AccountId is required")));
assertThat(e.getMessage(), is(equalTo("Email or AccountId is required")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
assertThat(e.getRelatedResources(), is(nullValue()));
}
Expand Down Expand Up @@ -8866,4 +8866,42 @@ public void testListTransferRefunds_noTransferToken() {
}
}

@Test
public void createPayPalAccountWithAccountId() throws Exception {
HyperwalletPayPalAccount payPalAccount = new HyperwalletPayPalAccount();
payPalAccount.setUserToken("test-user-token");
payPalAccount.setTransferMethodCountry("test-transfer-method-country");
payPalAccount.setTransferMethodCurrency("test-transfer-method-currency");
payPalAccount.setAccountId("test-accountId");
payPalAccount.setStatus(HyperwalletPayPalAccount.Status.ACTIVATED);
payPalAccount.setCreatedOn(new Date());

HyperwalletPayPalAccount payPalAccountResponse = new HyperwalletPayPalAccount();

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

Mockito.when(mockApiClient.post(ArgumentMatchers.anyString(), ArgumentMatchers.anyObject(), ArgumentMatchers.any(Class.class)))
.thenReturn(payPalAccountResponse);

HyperwalletPayPalAccount resp = client.createPayPalAccount(payPalAccount);
assertThat(resp, is(equalTo(payPalAccountResponse)));

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

HyperwalletPayPalAccount apiPayPalAccount = argument.getValue();
assertThat(apiPayPalAccount, is(notNullValue()));
assertThat(apiPayPalAccount.getUserToken(), is(equalTo("test-user-token")));
assertThat(apiPayPalAccount.getTransferMethodCountry(), is(equalTo("test-transfer-method-country")));
assertThat(apiPayPalAccount.getTransferMethodCurrency(), is(equalTo("test-transfer-method-currency")));
assertThat(apiPayPalAccount.getAccountId(), is(equalTo("test-accountId")));
assertThat(apiPayPalAccount.getStatus(), is(nullValue()));
assertThat(apiPayPalAccount.getCreatedOn(), is(nullValue()));
assertThat(apiPayPalAccount.getType(), is(HyperwalletPayPalAccount.Type.PAYPAL_ACCOUNT));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected HyperwalletPayPalAccount createBaseModel() {
.transferMethodCurrency("test-transfer-method-currency")
.isDefaultTransferMethod(Boolean.FALSE)
.email("test-user-email")
.accountId("test-user-accountId")
.links(hyperwalletLinkList)
.userToken("test-user-token");
return payPalAccount;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
curl -X "POST" "https://api.sandbox.hyperwallet.com/rest/v4/users/usr-e7b61829-a73a-45dc-930e-afa8a56b924c/paypal-accounts" \
-u testuser@12345678:myAccPassw0rd \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "{
"type": "PAYPAL_ACCOUNT",
"transferMethodCountry": "US",
"transferMethodCurrency": "USD",
"accountId": "K8QRQHMYWETL9",
"userToken": "usr-e7b61829-a73a-45dc-930e-afa8a56b924c"
}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"token": "trm-54b0db9c-5565-47f7-aee6-afa8a56b924c",
"type": "PAYPAL_ACCOUNT",
"status": "ACTIVATED",
"createdOn": "2022-11-11T00:00:00",
"transferMethodCountry": "US",
"transferMethodCurrency": "USD",
"accountId": "K8QRQHMYWETL9",
"links": [
{
"params": {
"rel": "self"
},
"href": "https://api.sandbox.hyperwallet.com/rest/v4/users/usr-e7b61829-a73a-45dc-930e-afa8a56b924c/paypal-accounts/trm-54b0db9c-5565-47f7-aee6-685e713595f4"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
curl -X "POST" "https://api.sandbox.hyperwallet.com/rest/v4/users/usr-c4292f1a-866f-4310-a289-b916853939ef/venmo-accounts" \
-u testuser@12345678:myAccPassw0rd \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "{
"type": "VENMO_ACCOUNT",
"transferMethodCountry": "US",
"transferMethodCurrency": "USD",
"accountId": "user@domain.com"
}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"token": "trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b49c",
"type": "VENMO_ACCOUNT",
"status": "ACTIVATED",
"createdOn": "2022-11-11T22:50:14",
"transferMethodCountry": "US",
"transferMethodCurrency": "USD",
"accountId": "user@domain.com",
"links": [
{
"params": {
"rel": "self"
},
"href": "https://api.sandbox.hyperwallet.com/rest/v4/users/usr-c4292f1a-866f-4310-a289-b916853939ef/venmo-accounts/trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b49c"
}
]
}