diff --git a/CHANGELOG.md b/CHANGELOG.md index 11e0213cd..2ba19fc3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java b/src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java index ae9cf26ed..01ee08011 100644 --- a/src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java +++ b/src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java @@ -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"); diff --git a/src/main/java/com/hyperwallet/clientsdk/model/HyperwalletPayPalAccount.java b/src/main/java/com/hyperwallet/clientsdk/model/HyperwalletPayPalAccount.java index 52bf5cfd3..9801229a5 100644 --- a/src/main/java/com/hyperwallet/clientsdk/model/HyperwalletPayPalAccount.java +++ b/src/main/java/com/hyperwallet/clientsdk/model/HyperwalletPayPalAccount.java @@ -27,6 +27,7 @@ public enum Type {PAYPAL_ACCOUNT} private Boolean isDefaultTransferMethod; private String email; private String userToken; + private String accountId; private List links; public String getToken() { @@ -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; } diff --git a/src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java b/src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java index 3355f8985..d0e7a3a4c 100644 --- a/src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java +++ b/src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java @@ -3410,6 +3410,93 @@ public void testGetPayPalAccountDefaultTransfer() throws Exception { } } + @Test + 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 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 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 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 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 diff --git a/src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java b/src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java index e3551de33..5e4b8ec5e 100644 --- a/src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java +++ b/src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java @@ -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())); } @@ -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 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)); + } + + } diff --git a/src/test/java/com/hyperwallet/clientsdk/model/HyperwalletPayPalAccountTest.java b/src/test/java/com/hyperwallet/clientsdk/model/HyperwalletPayPalAccountTest.java index a7101bd46..dab91bac6 100644 --- a/src/test/java/com/hyperwallet/clientsdk/model/HyperwalletPayPalAccountTest.java +++ b/src/test/java/com/hyperwallet/clientsdk/model/HyperwalletPayPalAccountTest.java @@ -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; diff --git a/src/test/resources/integration/createPayPalAccountWithAccountId-request.txt b/src/test/resources/integration/createPayPalAccountWithAccountId-request.txt new file mode 100644 index 000000000..2cec54ff5 --- /dev/null +++ b/src/test/resources/integration/createPayPalAccountWithAccountId-request.txt @@ -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" +}" diff --git a/src/test/resources/integration/createPayPalAccountWithAccountId-response.json b/src/test/resources/integration/createPayPalAccountWithAccountId-response.json new file mode 100644 index 000000000..c06370c8e --- /dev/null +++ b/src/test/resources/integration/createPayPalAccountWithAccountId-response.json @@ -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" + } + ] +} diff --git a/src/test/resources/integration/createVenmoAccountWithEmail-request.txt b/src/test/resources/integration/createVenmoAccountWithEmail-request.txt new file mode 100644 index 000000000..5ae0a8d62 --- /dev/null +++ b/src/test/resources/integration/createVenmoAccountWithEmail-request.txt @@ -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" +}" diff --git a/src/test/resources/integration/createVenmoAccountWithEmail-response.json b/src/test/resources/integration/createVenmoAccountWithEmail-response.json new file mode 100644 index 000000000..aa4ac8b13 --- /dev/null +++ b/src/test/resources/integration/createVenmoAccountWithEmail-response.json @@ -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" + } + ] +}