From 6add58ba9de3846ec0983fbca9b5b608c441cdd5 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Tue, 30 Apr 2019 13:30:47 +0300 Subject: [PATCH 01/17] HW-51228. PayPal Account Deactivation --- .../com/hyperwallet/android/Hyperwallet.java | 33 +++++ .../android/HyperwalletTestSuite.java | 2 + ...yperwalletDeactivatePayPalAccountTest.java | 113 ++++++++++++++++++ .../deactivated_paypal_account_response.json | 16 +++ 4 files changed, 164 insertions(+) create mode 100644 core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletDeactivatePayPalAccountTest.java create mode 100644 core/src/test/resources/deactivated_paypal_account_response.json diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index d0eecf36..19a0feb5 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -371,6 +371,39 @@ public void deactivateBankCard(@NonNull final String transferMethodToken, @Nulla performRestTransaction(builder, listener); } + /** + * Deactivates the {@link PayPalAccount} linked to the transfer method token specified. The + * {@code PayPalAccount} being deactivated must belong to the User that is associated with the + * authentication token returned from + * {@link HyperwalletAuthenticationTokenProvider#retrieveAuthenticationToken(HyperwalletAuthenticationTokenListener)}. + * + *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from + * processing the request.

+ * + *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + * if the current one is expired or about to expire.

+ * + * @param transferMethodToken the Hyperwallet specific unique identifier for the {@code PayPalAccount} + * being deactivated; must not be null + * @param notes a note regarding the status change + * @param listener the callback handler of responses from the Hyperwallet platform; must not be null + */ + public void deactivatePayPalAccount(@NonNull final String transferMethodToken, @Nullable final String notes, + @NonNull final HyperwalletListener listener) { + PathFormatter pathFormatter = new PathFormatter("users/{0}/paypal-accounts/{1}/status-transitions", + transferMethodToken); + + final HyperwalletStatusTransition deactivatedStatusTransition = new HyperwalletStatusTransition( + HyperwalletStatusTransition.StatusDefinition.DE_ACTIVATED); + deactivatedStatusTransition.setNotes(notes); + RestTransaction.Builder builder = new RestTransaction.Builder<>(PUT, pathFormatter, + new TypeReference() { + }, listener).jsonModel(deactivatedStatusTransition); + + performRestTransaction(builder, listener); + } + + /** * Returns the {@link HyperwalletTransferMethod} (Bank Account, Bank Card, PayPay Account, Prepaid Card, * Paper Checks) for the User associated with the authentication token returned from diff --git a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java index 27b1182e..f06b8ee4 100644 --- a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java +++ b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java @@ -5,6 +5,7 @@ import com.hyperwallet.android.transfermethod.HyperwalletCreateBankCardTest; import com.hyperwallet.android.transfermethod.HyperwalletDeactivateBankAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletDeactivateBankCardTest; +import com.hyperwallet.android.transfermethod.HyperwalletDeactivatePayPalAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletGetBankAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletGetBankCardTest; import com.hyperwallet.android.transfermethod.HyperwalletListBankAccountsTest; @@ -29,6 +30,7 @@ HyperwalletUpdateBankCardTest.class, HyperwalletDeactivateBankAccountTest.class, HyperwalletDeactivateBankCardTest.class, + HyperwalletDeactivatePayPalAccountTest.class, HyperwalletListTransferMethodsTest.class, HyperwalletListBankCardsTest.class, HyperwalletRetrieveTransferMethodConfigurationKeysTest.class, diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletDeactivatePayPalAccountTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletDeactivatePayPalAccountTest.java new file mode 100644 index 00000000..112853b6 --- /dev/null +++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletDeactivatePayPalAccountTest.java @@ -0,0 +1,113 @@ +package com.hyperwallet.android.transfermethod; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import com.hyperwallet.android.Hyperwallet; +import com.hyperwallet.android.exception.HyperwalletException; +import com.hyperwallet.android.listener.HyperwalletListener; +import com.hyperwallet.android.model.HyperwalletError; +import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.HyperwalletStatusTransition; +import com.hyperwallet.android.rule.HyperwalletExternalResourceManager; +import com.hyperwallet.android.rule.HyperwalletMockWebServer; +import com.hyperwallet.android.rule.HyperwalletSdkMock; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.robolectric.RobolectricTestRunner; + +import java.net.HttpURLConnection; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +@RunWith(RobolectricTestRunner.class) +public class HyperwalletDeactivatePayPalAccountTest { + + @Rule + public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer(); + @Rule + public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer); + @Rule + public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager(); + @Rule + public MockitoRule mMockitoRule = MockitoJUnit.rule(); + @Mock + private HyperwalletListener mListener; + @Captor + private ArgumentCaptor mStatusTransitionCaptor; + @Captor + private ArgumentCaptor mExceptionArgumentCaptor; + + private final CountDownLatch mAwait = new CountDownLatch(1); + + @Test + public void testDeactivatePayPalAccount_successfulStatusTransition() throws Exception { + + String responseBody = mExternalResourceManager.getResourceContent( + "deactivated_paypal_account_response.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_CREATED).withBody(responseBody).mock(); + + Hyperwallet.getDefault().deactivatePayPalAccount("trm-da21954a-3910-4d70-b83d-0c2d96104394", null, + mListener); + mAwait.await(50, TimeUnit.MILLISECONDS); + + verify(mListener).onSuccess(mStatusTransitionCaptor.capture()); + verify(mListener, never()).onFailure(any(HyperwalletException.class)); + HyperwalletStatusTransition statusTransitionResponse = mStatusTransitionCaptor.getValue(); + assertNotNull(statusTransitionResponse); + assertThat(statusTransitionResponse.getFromStatus(), + is(HyperwalletStatusTransition.StatusDefinition.ACTIVATED)); + assertThat(statusTransitionResponse.getToStatus(), + is(HyperwalletStatusTransition.StatusDefinition.DE_ACTIVATED)); + assertThat(statusTransitionResponse.getTransition(), + is(HyperwalletStatusTransition.StatusDefinition.DE_ACTIVATED)); + assertThat(statusTransitionResponse.getToken(), is("sts-70ddc78a-0c14-4a72-8390-75d49ff376f2")); + assertNotNull(statusTransitionResponse.getCreatedOn()); + assertThat(mServer.getRequest().getPath(), endsWith( + "users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-da21954a-3910-4d70-b83d" + + "-0c2d96104394/status-transitions")); + } + + @Test + public void testDeactivatePayPalAccount_unsuccessfulStatusTransition() throws Exception { + + String responseBody = mExternalResourceManager.getResourceContentError("invalid_status_transition.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock(); + + Hyperwallet.getDefault().deactivatePayPalAccount("trm-fake-token", null, mListener); + mAwait.await(100, TimeUnit.MILLISECONDS); + + verify(mListener).onFailure(mExceptionArgumentCaptor.capture()); + verify(mListener, never()).onSuccess(any(HyperwalletStatusTransition.class)); + HyperwalletException hyperwalletException = mExceptionArgumentCaptor.getValue(); + assertNotNull(hyperwalletException); + final HyperwalletErrors hyperwalletErrors = hyperwalletException.getHyperwalletErrors(); + assertNotNull(hyperwalletErrors); + final List statusTransitionErrorList = hyperwalletErrors.getErrors(); + assertNotNull(statusTransitionErrorList); + assertThat(statusTransitionErrorList, hasSize(1)); + HyperwalletError statusTransitionError = statusTransitionErrorList.get(0); + assertNotNull(statusTransitionError); + assertThat(statusTransitionError.getCode(), is("INVALID_FIELD_VALUE")); + assertThat(statusTransitionError.getFieldName(), is("transition")); + assertThat(statusTransitionError.getMessage(), is("transition is invalid")); + assertThat(mServer.getRequest().getPath(), + endsWith( + "users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-fake-token/status" + + "-transitions")); + } +} diff --git a/core/src/test/resources/deactivated_paypal_account_response.json b/core/src/test/resources/deactivated_paypal_account_response.json new file mode 100644 index 00000000..277fd08d --- /dev/null +++ b/core/src/test/resources/deactivated_paypal_account_response.json @@ -0,0 +1,16 @@ +{ + "token": "sts-70ddc78a-0c14-4a72-8390-75d49ff376f2", + "createdOn": "2017-10-30T18:50:20", + "transition": "DE_ACTIVATED", + "fromStatus": "ACTIVATED", + "toStatus": "DE_ACTIVATED", + "notes": "Closing this account.", + "links": [ + { + "params": { + "rel": "self" + }, + "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-f695ef43-9614-4e17-9269-902c234616c3/paypal-accounts/trm-da21954a-3910-4d70-b83d-0c2d96104394/status-transitions/sts-70ddc78a-0c14-4a72-8390-75d49ff376f2" + } + ] +} \ No newline at end of file From 9c48a4bff48650791c1e02a517d7013f564706d3 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Thu, 2 May 2019 09:58:57 +0300 Subject: [PATCH 02/17] HW-51228. Changed PUT tp POST --- .../com/hyperwallet/android/Hyperwallet.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index 19a0feb5..f55c9cb8 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -121,7 +121,7 @@ public static Hyperwallet getDefault() { *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankAccount the {@code HyperwalletBankAccount} to be created; must not be null @@ -161,7 +161,7 @@ public void createBankAccount(@NonNull final HyperwalletBankAccount bankAccount, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankAccountPagination the ordering and filtering criteria @@ -186,7 +186,7 @@ public void listBankAccounts(@Nullable final HyperwalletBankAccountPagination ba *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankCard the {@code HyperwalletBankCard} to be created; must not be null @@ -209,7 +209,7 @@ public void createBankCard(@NonNull final HyperwalletBankCard bankCard, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param transferMethodToken the Hyperwallet specific unique identifier for the {@code HyperwalletBankAccount} @@ -233,7 +233,7 @@ public void getBankAccount(@NonNull String transferMethodToken, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param transferMethodToken the Hyperwallet specific unique identifier for the {@code HyperwalletBankCard} @@ -260,7 +260,7 @@ public void getBankCard(@NonNull final String transferMethodToken, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankAccount the {@code HyperwalletBankAccount} to be created; must not be null @@ -289,7 +289,7 @@ public void updateBankAccount(@NonNull final HyperwalletBankAccount bankAccount, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankCard the {@code HyperwalletBankCard} to be created; must not be null @@ -316,7 +316,7 @@ public void updateBankCard(@NonNull final HyperwalletBankCard bankCard, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param transferMethodToken the Hyperwallet specific unique identifier for the {@code HyperwalletBankAccount} @@ -348,7 +348,7 @@ public void deactivateBankAccount(@NonNull final String transferMethodToken, @Nu *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param transferMethodToken the Hyperwallet specific unique identifier for the {@code HyperwalletBankCard} being @@ -380,7 +380,7 @@ public void deactivateBankCard(@NonNull final String transferMethodToken, @Nulla *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param transferMethodToken the Hyperwallet specific unique identifier for the {@code PayPalAccount} @@ -396,7 +396,7 @@ public void deactivatePayPalAccount(@NonNull final String transferMethodToken, @ final HyperwalletStatusTransition deactivatedStatusTransition = new HyperwalletStatusTransition( HyperwalletStatusTransition.StatusDefinition.DE_ACTIVATED); deactivatedStatusTransition.setNotes(notes); - RestTransaction.Builder builder = new RestTransaction.Builder<>(PUT, pathFormatter, + RestTransaction.Builder builder = new RestTransaction.Builder<>(POST, pathFormatter, new TypeReference() { }, listener).jsonModel(deactivatedStatusTransition); @@ -427,7 +427,7 @@ public void deactivatePayPalAccount(@NonNull final String transferMethodToken, @ *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param transferMethodPagination the ordering and filtering criteria @@ -467,7 +467,7 @@ public void listTransferMethods(@Nullable final HyperwalletTransferMethodPaginat *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankCardPagination the ordering and filtering criteria @@ -506,7 +506,7 @@ public void listBankCards(@Nullable final HyperwalletBankCardPagination bankCard *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankCardPagination the ordering and filtering criteria @@ -531,7 +531,7 @@ public void listPayPalAccounts(@Nullable final PayPalAccountPagination bankCardP *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param transferMethodConfigurationKeysQuery containing the transfer method configuration key query, @@ -558,7 +558,7 @@ public void retrieveTransferMethodConfigurationKeys( *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param transferMethodConfigurationFieldQuery containing a transfer method configuration key tuple of From b421d5a334f5302eac86a81a316c737cf43452d1 Mon Sep 17 00:00:00 2001 From: Anna <48258136+azakrevska-epam@users.noreply.github.com> Date: Fri, 3 May 2019 23:49:14 +0300 Subject: [PATCH 03/17] HW-51226. PayPalAccount update (#1) * HW-51226. Add support to PayPal account update --- .../com/hyperwallet/android/Hyperwallet.java | 28 ++++ .../android/model/PayPalAccount.java | 2 +- .../android/HyperwalletTestSuite.java | 2 + .../HyperwalletUpdatePayPalAccountTest.java | 147 ++++++++++++++++++ .../paypal_account_update_error_response.json | 9 ++ .../paypal_account_update_response.json | 17 ++ 6 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletUpdatePayPalAccountTest.java create mode 100644 core/src/test/resources/errors/paypal_account_update_error_response.json create mode 100644 core/src/test/resources/paypal_account_update_response.json diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index f55c9cb8..c2754f9e 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -307,6 +307,34 @@ public void updateBankCard(@NonNull final HyperwalletBankCard bankCard, performRestTransaction(builder, listener); } + /** + * Updates the {@link PayPalAccount} for the User associated with the authentication token returned from + * {@link HyperwalletAuthenticationTokenProvider#retrieveAuthenticationToken(HyperwalletAuthenticationTokenListener)}. + * + *

To identify the {@code PayPalAccount} that is going to be updated, the transfer method token must be + * set as part of the {@code PayPalAccount} object passed in.

+ * + *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from + * processing the request.

+ * + *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + * if the current one is expired or about to expire.

+ * + * @param payPalAccount the {@code PayPalAccount} to be created; must not be null + * @param listener the callback handler of responses from the Hyperwallet platform; must not be null + */ + public void updatePayPalAccount(@NonNull final PayPalAccount payPalAccount, + @NonNull final HyperwalletListener listener) { + PathFormatter pathFormatter = new PathFormatter("users/{0}/paypal-accounts/{1}", + payPalAccount.getField(HyperwalletTransferMethod.TransferMethodFields.TOKEN)); + + RestTransaction.Builder builder = new RestTransaction.Builder<>(PUT, pathFormatter, + new TypeReference() { + }, listener).jsonModel(payPalAccount); + + performRestTransaction(builder, listener); + } + /** * Deactivates the {@link HyperwalletBankAccount} linked to the transfer method token specified. The * {@code HyperwalletBankAccount} being deactivated must belong to the User that is associated with the diff --git a/core/src/main/java/com/hyperwallet/android/model/PayPalAccount.java b/core/src/main/java/com/hyperwallet/android/model/PayPalAccount.java index c658316c..59c84d5a 100644 --- a/core/src/main/java/com/hyperwallet/android/model/PayPalAccount.java +++ b/core/src/main/java/com/hyperwallet/android/model/PayPalAccount.java @@ -42,7 +42,7 @@ public class PayPalAccount extends HyperwalletTransferMethod { /** - * Constructor to build bank card, based on json object + * Constructor to build PayPal Account, based on json object */ public PayPalAccount(@NonNull JSONObject jsonObject) throws JSONException { super(jsonObject); diff --git a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java index f06b8ee4..caf22692 100644 --- a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java +++ b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java @@ -14,6 +14,7 @@ import com.hyperwallet.android.transfermethod.HyperwalletRetrieveTransferMethodConfigurationKeysTest; import com.hyperwallet.android.transfermethod.HyperwalletUpdateBankAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletUpdateBankCardTest; +import com.hyperwallet.android.transfermethod.HyperwalletUpdatePayPalAccountTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -28,6 +29,7 @@ HyperwalletGetBankCardTest.class, HyperwalletUpdateBankAccountTest.class, HyperwalletUpdateBankCardTest.class, + HyperwalletUpdatePayPalAccountTest.class, HyperwalletDeactivateBankAccountTest.class, HyperwalletDeactivateBankCardTest.class, HyperwalletDeactivatePayPalAccountTest.class, diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletUpdatePayPalAccountTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletUpdatePayPalAccountTest.java new file mode 100644 index 00000000..004331e2 --- /dev/null +++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletUpdatePayPalAccountTest.java @@ -0,0 +1,147 @@ +package com.hyperwallet.android.transfermethod; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.CREATED_ON; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.EMAIL; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.STATUS; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TOKEN; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_CURRENCY; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TYPE; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT; + +import com.hyperwallet.android.Hyperwallet; +import com.hyperwallet.android.exception.HyperwalletException; +import com.hyperwallet.android.exception.HyperwalletRestException; +import com.hyperwallet.android.listener.HyperwalletListener; +import com.hyperwallet.android.model.HyperwalletError; +import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.PayPalAccount; +import com.hyperwallet.android.rule.HyperwalletExternalResourceManager; +import com.hyperwallet.android.rule.HyperwalletMockWebServer; +import com.hyperwallet.android.rule.HyperwalletSdkMock; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.robolectric.RobolectricTestRunner; + +import java.net.HttpURLConnection; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import okhttp3.mockwebserver.RecordedRequest; + +@RunWith(RobolectricTestRunner.class) +public class HyperwalletUpdatePayPalAccountTest { + @Rule + public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer(); + @Rule + public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer); + @Rule + public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager(); + @Rule + public MockitoRule mMockito = MockitoJUnit.rule(); + + @Mock + private HyperwalletListener mListener; + + @Captor + private ArgumentCaptor mPayPalAccountCaptor; + @Captor + private ArgumentCaptor mExceptionCaptor; + + private final CountDownLatch mAwait = new CountDownLatch(1); + + @Test + public void testUpdatePayPalAccount_withSuccess() throws InterruptedException { + String responseBody = mExternalResourceManager.getResourceContent("paypal_account_update_response.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_OK).withBody(responseBody).mock(); + + final PayPalAccount payPalAccount = new PayPalAccount + .Builder() + .email("jsmith2@paypal.com") + .token("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b") + .build(); + + assertThat(payPalAccount.getField(EMAIL), is("jsmith2@paypal.com")); + assertThat(payPalAccount.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b")); + + Hyperwallet.getDefault().updatePayPalAccount(payPalAccount, mListener); + mAwait.await(50, TimeUnit.MILLISECONDS); + + RecordedRequest recordedRequest = mServer.getRequest(); + verify(mListener).onSuccess(mPayPalAccountCaptor.capture()); + verify(mListener, never()).onFailure(any(HyperwalletException.class)); + + PayPalAccount payPalAccountResponse = mPayPalAccountCaptor.getValue(); + assertThat(payPalAccountResponse, is(notNullValue())); + + assertThat(recordedRequest.getPath(), + is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-ac5727ac-8fe7-42fb" + + "-b69d-977ebdd7b48b")); + + assertThat(payPalAccountResponse.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b")); + assertThat(payPalAccountResponse.getField(STATUS), is("ACTIVATED")); + assertThat(payPalAccountResponse.getField(TYPE), is(PAYPAL_ACCOUNT)); + assertThat(payPalAccountResponse.getField(EMAIL), is("jsmith2@paypal.com")); + assertThat(payPalAccountResponse.getField(TRANSFER_METHOD_CURRENCY), is("USD")); + assertThat(payPalAccountResponse.getField(TRANSFER_METHOD_COUNTRY), is("US")); + assertThat(payPalAccountResponse.getField(CREATED_ON), is("2019-01-09T22:50:14")); + } + + @Test + public void testUpdatePayPalAccount_withValidationError() throws InterruptedException { + + String responseBody = mExternalResourceManager.getResourceContentError( + "paypal_account_update_error_response.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock(); + + final PayPalAccount payPalAccount = new PayPalAccount + .Builder() + .email("00G0G1ema.com") + .token("trm-56b976c5-26b2-42fa-87cf-14b3366673c6") + .build(); + + assertThat(payPalAccount.getField(EMAIL), is("00G0G1ema.com")); + assertThat(payPalAccount.getField(TOKEN), + is("trm-56b976c5-26b2-42fa-87cf-14b3366673c6")); + + Hyperwallet.getDefault().updatePayPalAccount(payPalAccount, mListener); + mAwait.await(50, TimeUnit.MILLISECONDS); + + RecordedRequest recordedRequest = mServer.getRequest(); + verify(mListener, never()).onSuccess(any(PayPalAccount.class)); + verify(mListener).onFailure(mExceptionCaptor.capture()); + + HyperwalletException hyperwalletException = mExceptionCaptor.getValue(); + assertThat(hyperwalletException, is(notNullValue())); + assertThat(((HyperwalletRestException) hyperwalletException).getHttpCode(), + is(HttpURLConnection.HTTP_BAD_REQUEST)); + + assertThat(recordedRequest.getPath(), + is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-56b976c5-26b2-42fa-87cf" + + "-14b3366673c6")); + + HyperwalletErrors hyperwalletErrors = hyperwalletException.getHyperwalletErrors(); + assertThat(hyperwalletErrors, is(notNullValue())); + assertThat(hyperwalletErrors.getErrors(), hasSize(1)); + + HyperwalletError hyperwalletError1 = hyperwalletErrors.getErrors().get(0); + assertThat(hyperwalletError1.getCode(), is("CONSTRAINT_VIOLATIONS")); + assertThat(hyperwalletError1.getFieldName(), is("email")); + assertThat(hyperwalletError1.getMessage(), is("Invalid Email")); + } +} diff --git a/core/src/test/resources/errors/paypal_account_update_error_response.json b/core/src/test/resources/errors/paypal_account_update_error_response.json new file mode 100644 index 00000000..408baab1 --- /dev/null +++ b/core/src/test/resources/errors/paypal_account_update_error_response.json @@ -0,0 +1,9 @@ +{ + "errors": [ + { + "message": "Invalid Email", + "fieldName": "email", + "code": "CONSTRAINT_VIOLATIONS" + } + ] +} \ No newline at end of file diff --git a/core/src/test/resources/paypal_account_update_response.json b/core/src/test/resources/paypal_account_update_response.json new file mode 100644 index 00000000..a157c0a0 --- /dev/null +++ b/core/src/test/resources/paypal_account_update_response.json @@ -0,0 +1,17 @@ +{ + "token": "trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b", + "type": "PAYPAL_ACCOUNT", + "status": "ACTIVATED", + "createdOn": "2019-01-09T22:50:14", + "transferMethodCountry": "US", + "transferMethodCurrency": "USD", + "email": "jsmith2@paypal.com", + "links": [ + { + "params": { + "rel": "self" + }, + "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-c4292f1a-866f-4310-a289-b916853939de/paypal-accounts/trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b" + } + ] +} \ No newline at end of file From 58d20c8194c871389a45df1924628b7140fed353 Mon Sep 17 00:00:00 2001 From: Anna <48258136+azakrevska-epam@users.noreply.github.com> Date: Sat, 4 May 2019 00:07:43 +0300 Subject: [PATCH 04/17] HW-51227. PayPal Account Creation (#2) * HW-51227. Add support to create PayPal accounts --- .../com/hyperwallet/android/Hyperwallet.java | 24 +++ .../android/HyperwalletTestSuite.java | 2 + .../HyperwalletCreatePayPalAccountTest.java | 140 ++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletCreatePayPalAccountTest.java diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index c2754f9e..d6fca2fc 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -203,6 +203,30 @@ public void createBankCard(@NonNull final HyperwalletBankCard bankCard, performRestTransaction(builder, listener); } + /** + * Creates a {@link PayPalAccount} for the User associated with the authentication token returned from + * {@link HyperwalletAuthenticationTokenProvider#retrieveAuthenticationToken(HyperwalletAuthenticationTokenListener)}. + * + *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from + * * processing the request.

+ * + *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + * if the current one is expired or about to expire.

+ * + * @param payPalAccount the {@code PayPalAccount} to be created; must not be null + * @param listener the callback handler of responses from the Hyperwallet platform; must not be null + */ + public void createPayPalAccount(@NonNull final PayPalAccount payPalAccount, + @NonNull final HyperwalletListener listener) { + PathFormatter pathFormatter = new PathFormatter("users/{0}/paypal-accounts"); + + RestTransaction.Builder builder = new RestTransaction.Builder<>(POST, pathFormatter, + new TypeReference() { + }, listener).jsonModel(payPalAccount); + + performRestTransaction(builder, listener); + } + /** * Returns the {@link HyperwalletBankAccount} linked to the transfer method token specified, or null if none exists. * diff --git a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java index caf22692..605d89f0 100644 --- a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java +++ b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java @@ -3,6 +3,7 @@ import com.hyperwallet.android.model.meta.HyperwalletRetrieveTransferMethodConfigurationFieldsTest; import com.hyperwallet.android.transfermethod.HyperwalletCreateBankAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletCreateBankCardTest; +import com.hyperwallet.android.transfermethod.HyperwalletCreatePayPalAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletDeactivateBankAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletDeactivateBankCardTest; import com.hyperwallet.android.transfermethod.HyperwalletDeactivatePayPalAccountTest; @@ -25,6 +26,7 @@ HyperwalletCreateBankAccountTest.class, HyperwalletListBankAccountsTest.class, HyperwalletCreateBankCardTest.class, + HyperwalletCreatePayPalAccountTest.class, HyperwalletGetBankAccountTest.class, HyperwalletGetBankCardTest.class, HyperwalletUpdateBankAccountTest.class, diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletCreatePayPalAccountTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletCreatePayPalAccountTest.java new file mode 100644 index 00000000..eec9cb27 --- /dev/null +++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletCreatePayPalAccountTest.java @@ -0,0 +1,140 @@ +package com.hyperwallet.android.transfermethod; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import static com.hyperwallet.android.model.HyperwalletStatusTransition.StatusDefinition.ACTIVATED; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.CREATED_ON; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.EMAIL; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.STATUS; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TOKEN; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_CURRENCY; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TYPE; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT; + +import com.hyperwallet.android.Hyperwallet; +import com.hyperwallet.android.exception.HyperwalletException; +import com.hyperwallet.android.listener.HyperwalletListener; +import com.hyperwallet.android.model.HyperwalletError; +import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.PayPalAccount; +import com.hyperwallet.android.rule.HyperwalletExternalResourceManager; +import com.hyperwallet.android.rule.HyperwalletMockWebServer; +import com.hyperwallet.android.rule.HyperwalletSdkMock; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.robolectric.RobolectricTestRunner; + +import java.net.HttpURLConnection; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import okhttp3.mockwebserver.RecordedRequest; + +@RunWith(RobolectricTestRunner.class) +public class HyperwalletCreatePayPalAccountTest { + @Rule + public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer(); + @Rule + public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer); + @Rule + public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager(); + @Rule + public MockitoRule mMockito = MockitoJUnit.rule(); + + @Mock + private HyperwalletListener mListener; + + @Captor + private ArgumentCaptor mPayPalAccountCaptor; + @Captor + private ArgumentCaptor mExceptionCaptor; + + private final CountDownLatch mAwait = new CountDownLatch(1); + + @Test + public void testCreatePayPalAccount_withSuccess() throws InterruptedException { + + String responseBody = mExternalResourceManager.getResourceContent("paypal_account_response.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_CREATED).withBody(responseBody).mock(); + + final PayPalAccount.Builder builder = new PayPalAccount + .Builder("US", "USD", "jsmith@paypal.com") + .token("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"); + + final PayPalAccount payPalAccount = builder.build(); + + assertThat(payPalAccount.getField(TRANSFER_METHOD_COUNTRY), is("US")); + assertThat(payPalAccount.getField(TRANSFER_METHOD_CURRENCY), is("USD")); + assertThat(payPalAccount.getField(EMAIL), is("jsmith@paypal.com")); + assertThat(payPalAccount.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b")); + + + Hyperwallet.getDefault().createPayPalAccount(payPalAccount, mListener); + mAwait.await(50, TimeUnit.MILLISECONDS); + + RecordedRequest recordedRequest = mServer.getRequest(); + verify(mListener).onSuccess(mPayPalAccountCaptor.capture()); + verify(mListener, never()).onFailure(any(HyperwalletException.class)); + + PayPalAccount paypalAccountResponse = mPayPalAccountCaptor.getValue(); + assertThat(paypalAccountResponse, is(notNullValue())); + + //paypal account info + assertThat(recordedRequest.getPath(), + is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts")); + + assertThat(paypalAccountResponse.getField(STATUS), is(ACTIVATED)); + assertThat(paypalAccountResponse.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b")); + assertThat(paypalAccountResponse.getField(TRANSFER_METHOD_COUNTRY), is("US")); + assertThat(paypalAccountResponse.getField(TRANSFER_METHOD_CURRENCY), is("USD")); + assertThat(paypalAccountResponse.getField(TYPE), is(PAYPAL_ACCOUNT)); + assertThat(paypalAccountResponse.getField(CREATED_ON), is(notNullValue())); + assertThat(paypalAccountResponse.getField(EMAIL), is("jsmith@paypal.com")); + } + + @Test + public void testCreatePayPalAccount_withValidationError() throws InterruptedException { + String responseBody = mExternalResourceManager.getResourceContentError("transfer_method_error_response.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock(); + + final PayPalAccount payPalAccount = new PayPalAccount + .Builder("", "USD", "jsmith@paypal.com") + .token("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b") + .build(); + + Hyperwallet.getDefault().createPayPalAccount(payPalAccount, mListener); + mAwait.await(50, TimeUnit.MILLISECONDS); + + RecordedRequest recordedRequest = mServer.getRequest(); + verify(mListener, never()).onSuccess(any(PayPalAccount.class)); + verify(mListener).onFailure(mExceptionCaptor.capture()); + + HyperwalletException hyperwalletException = mExceptionCaptor.getValue(); + assertThat(hyperwalletException, is(notNullValue())); + + assertThat(recordedRequest.getPath(), + is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts")); + + HyperwalletErrors hyperwalletErrors = hyperwalletException.getHyperwalletErrors(); + assertThat(hyperwalletErrors.getErrors(), hasSize(1)); + + HyperwalletError hyperwalletError = hyperwalletErrors.getErrors().get(0); + assertThat(hyperwalletError.getCode(), is("CONSTRAINT_VIOLATIONS")); + assertThat(hyperwalletError.getFieldName(), is("transferMethodCountry")); + assertThat(hyperwalletError.getMessage(), is("You must provide a value for this field")); + } +} From 5a0ba23e9492ef0cd2e0684f225d932074994aa5 Mon Sep 17 00:00:00 2001 From: vshcherbyna-epam <48257687+vshcherbyna-epam@users.noreply.github.com> Date: Sat, 4 May 2019 00:18:51 +0300 Subject: [PATCH 05/17] HW-51321: Get paypal account (#3) * HW-51321: Add support to retrieve PayPal accounts --- .../com/hyperwallet/android/Hyperwallet.java | 26 ++- .../HyperwalletGetPayPalTest.java | 150 ++++++++++++++++++ 2 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetPayPalTest.java diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index d6fca2fc..0f48f5df 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -240,7 +240,7 @@ public void createPayPalAccount(@NonNull final PayPalAccount payPalAccount, * being requested; must not be null * @param listener the callback handler of responses from the Hyperwallet platform; must not be null */ - public void getBankAccount(@NonNull String transferMethodToken, + public void getBankAccount(@NonNull final String transferMethodToken, @NonNull final HyperwalletListener listener) { PathFormatter pathFormatter = new PathFormatter("users/{0}/bank-accounts/{1}", transferMethodToken); @@ -575,6 +575,30 @@ public void listPayPalAccounts(@Nullable final PayPalAccountPagination bankCardP performRestTransaction(builder, listener); } + /** + * Returns the {@link PayPalAccount} linked to the transfer method token specified, or null if none exists. + * + *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from + * processing the request.

+ * + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + * if the current one is expired or about to expire.

+ * + * @param transferMethodToken the Hyperwallet specific unique identifier for the {@code PayPalAccount} + * being requested; must not be null + * @param listener the callback handler of responses from the Hyperwallet platform; must not be null + */ + public void getPayPalAccount(@NonNull final String transferMethodToken, + @NonNull final HyperwalletListener listener) { + PathFormatter pathFormatter = new PathFormatter("users/{0}/paypal-accounts/{1}", transferMethodToken); + + RestTransaction.Builder builder = new RestTransaction.Builder<>(GET, pathFormatter, + new TypeReference() { + }, listener); + + performRestTransaction(builder, listener); + } + /** * Returns the transfer method configuration key set, processing times, and fees for the User that is associated * with the authentication token returned from diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetPayPalTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetPayPalTest.java new file mode 100644 index 00000000..9722bae4 --- /dev/null +++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetPayPalTest.java @@ -0,0 +1,150 @@ +package com.hyperwallet.android.transfermethod; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import static com.hyperwallet.android.model.HyperwalletStatusTransition.StatusDefinition.ACTIVATED; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.CREATED_ON; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.EMAIL; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.STATUS; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TOKEN; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_CURRENCY; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TYPE; +import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT; + +import com.hyperwallet.android.Hyperwallet; +import com.hyperwallet.android.exception.HyperwalletException; +import com.hyperwallet.android.listener.HyperwalletListener; +import com.hyperwallet.android.model.HyperwalletError; +import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.PayPalAccount; +import com.hyperwallet.android.rule.HyperwalletExternalResourceManager; +import com.hyperwallet.android.rule.HyperwalletMockWebServer; +import com.hyperwallet.android.rule.HyperwalletSdkMock; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.robolectric.RobolectricTestRunner; + +import java.net.HttpURLConnection; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import okhttp3.mockwebserver.RecordedRequest; + +@RunWith(RobolectricTestRunner.class) +public class HyperwalletGetPayPalTest { + @Rule + public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer(); + @Rule + public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer); + @Rule + public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager(); + @Rule + public MockitoRule mMockito = MockitoJUnit.rule(); + + @Mock + private HyperwalletListener mListener; + @Captor + private ArgumentCaptor mPayPalAccountArgumentCaptor; + @Captor + private ArgumentCaptor mExceptionCaptor; + + private final CountDownLatch mAwait = new CountDownLatch(1); + private static final long COUNTDOWN_TIMEOUT_MILLIS = 100L; + + @Test + public void testGetGetPayPalAccount_returnsAccount() throws InterruptedException { + + String responseBody = mExternalResourceManager.getResourceContent("paypal_account_response.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_OK).withBody(responseBody).mock(); + + Hyperwallet.getDefault().getPayPalAccount("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b", mListener); + mAwait.await(COUNTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); + + RecordedRequest recordedRequest = mServer.getRequest(); + assertThat(recordedRequest.getPath(), + is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-ac5727ac-8fe7-42fb" + + "-b69d-977ebdd7b48b")); + + verify(mListener).onSuccess(mPayPalAccountArgumentCaptor.capture()); + verify(mListener, never()).onFailure(any(HyperwalletException.class)); + + PayPalAccount payPalAccountResponse = mPayPalAccountArgumentCaptor.getValue(); + assertThat(payPalAccountResponse, is(notNullValue())); + assertThat(payPalAccountResponse.getField(TYPE), is(PAYPAL_ACCOUNT)); + assertThat(payPalAccountResponse.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b")); + assertThat(payPalAccountResponse.getField(STATUS), is(ACTIVATED)); + + assertThat(payPalAccountResponse.getField(CREATED_ON), is("2019-01-09T22:50:14")); + assertThat(payPalAccountResponse.getField(TRANSFER_METHOD_COUNTRY), is("US")); + assertThat(payPalAccountResponse.getField(TRANSFER_METHOD_CURRENCY), is("USD")); + assertThat(payPalAccountResponse.getField(EMAIL), is("jsmith@paypal.com")); + + } + + @Test + public void testGetGetPayPalAccount_returnsNoAccount() throws InterruptedException { + + String responseBody = ""; + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_NO_CONTENT).withBody(responseBody).mock(); + + Hyperwallet.getDefault().getPayPalAccount("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b", mListener); + mAwait.await(COUNTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); + + RecordedRequest recordedRequest = mServer.getRequest(); + assertThat(recordedRequest.getPath(), + is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-ac5727ac-8fe7-42fb" + + "-b69d-977ebdd7b48b")); + + verify(mListener).onSuccess(mPayPalAccountArgumentCaptor.capture()); + verify(mListener, never()).onFailure(any(HyperwalletException.class)); + + PayPalAccount payPalAccount = mPayPalAccountArgumentCaptor.getValue(); + assertThat(payPalAccount, is(nullValue())); + } + + @Test + public void testGetGetPayPalAccount_returnsError() throws InterruptedException { + + String responseBody = mExternalResourceManager.getResourceContentError("system_error_response.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock(); + + Hyperwallet.getDefault().getPayPalAccount("trm-854c4ec1-9161-49d6-92e2-b8d15aa4bf56", mListener); + mAwait.await(COUNTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); + + RecordedRequest recordedRequest = mServer.getRequest(); + assertThat(recordedRequest.getPath(), + is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-854c4ec1-9161-49d6-92e2" + + "-b8d15aa4bf56")); + + verify(mListener, never()).onSuccess(any(PayPalAccount.class)); + verify(mListener).onFailure(mExceptionCaptor.capture()); + + HyperwalletException exception = mExceptionCaptor.getValue(); + assertThat(exception, is(notNullValue())); + HyperwalletErrors errors = exception.getHyperwalletErrors(); + assertThat(errors, is(notNullValue())); + assertThat(errors.getErrors(), hasSize(1)); + + HyperwalletError error = errors.getErrors().get(0); + assertThat(error.getCode(), is("SYSTEM_ERROR")); + assertThat(error.getMessage(), + is("A system error has occurred. Please try again. If you continue to receive this error, please " + + "contact customer support for assistance (Ref ID: 99b4ad5c-4aac-4cc2-aa9b-4b4f4844ac9b).")); + + } +} From 4d4ae4cb98d047e245a402ce0dd0e3447d189d58 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Tue, 30 Apr 2019 12:45:42 -0700 Subject: [PATCH 06/17] Adding required properties to pom file --- core/build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/build.gradle b/core/build.gradle index d842635a..6e2e9722 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -115,6 +115,9 @@ publishing { artifact(aarArtifact) pom { + name = 'Hyperwallet Android Core SDK' + description = 'Hyperwallet Core SDK for Android to integrate with Hyperwallet Platform' + url = 'https://github.com/hyperwallet/hyperwallet-android-sdk' pom.withXml { def dependenciesNode = asNode().appendNode('dependencies') configurations.implementation.allDependencies.each { From cd10fa846ac0d7f75fa403770d557bb784ecee8d Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Tue, 30 Apr 2019 15:23:32 -0700 Subject: [PATCH 07/17] Version update and exempt maven local publish task from signing --- build.gradle | 2 +- core/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index ea4665c4..6d0a25b4 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ allprojects { mavenLocal() } - project.version = "1.0.0-beta01"; + project.version = "1.0.0-beta02-SNAPSHOT"; } task clean(type: Delete) { diff --git a/core/build.gradle b/core/build.gradle index 6e2e9722..d691a43f 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -151,7 +151,7 @@ publishing { tasks.withType(Sign) { onlyIf { - isReleaseVersion + isReleaseVersion && !gradle.taskGraph.hasTask("publishToMavenLocal") } } From c997ef2ac309fd1a85a499682d9f46b2077204e7 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 3 May 2019 15:19:03 -0700 Subject: [PATCH 08/17] add PayPal get test to Hyperwallet test suite --- .../test/java/com/hyperwallet/android/HyperwalletTestSuite.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java index 605d89f0..11a0948e 100644 --- a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java +++ b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java @@ -9,6 +9,7 @@ import com.hyperwallet.android.transfermethod.HyperwalletDeactivatePayPalAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletGetBankAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletGetBankCardTest; +import com.hyperwallet.android.transfermethod.HyperwalletGetPayPalTest; import com.hyperwallet.android.transfermethod.HyperwalletListBankAccountsTest; import com.hyperwallet.android.transfermethod.HyperwalletListBankCardsTest; import com.hyperwallet.android.transfermethod.HyperwalletListTransferMethodsTest; @@ -29,6 +30,7 @@ HyperwalletCreatePayPalAccountTest.class, HyperwalletGetBankAccountTest.class, HyperwalletGetBankCardTest.class, + HyperwalletGetPayPalTest.class, HyperwalletUpdateBankAccountTest.class, HyperwalletUpdateBankCardTest.class, HyperwalletUpdatePayPalAccountTest.class, From 9ce7c71965f16645dac386f6724b147924104251 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 3 May 2019 15:27:35 -0700 Subject: [PATCH 09/17] fix javadoc --- core/src/main/java/com/hyperwallet/android/Hyperwallet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index 0f48f5df..f00a42ec 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -210,7 +210,7 @@ public void createBankCard(@NonNull final HyperwalletBankCard bankCard, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param payPalAccount the {@code PayPalAccount} to be created; must not be null @@ -341,7 +341,7 @@ public void updateBankCard(@NonNull final HyperwalletBankCard bankCard, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param payPalAccount the {@code PayPalAccount} to be created; must not be null From ac055ea0856e7087f468e9f42eba8a39f674255d Mon Sep 17 00:00:00 2001 From: Anna <48258136+azakrevska-epam@users.noreply.github.com> Date: Fri, 3 May 2019 23:49:14 +0300 Subject: [PATCH 10/17] HW-51226. PayPalAccount update (#1) * HW-51226. Add support to PayPal account update --- core/src/main/java/com/hyperwallet/android/Hyperwallet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index f00a42ec..33766d2c 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -161,7 +161,7 @@ public void createBankAccount(@NonNull final HyperwalletBankAccount bankAccount, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankAccountPagination the ordering and filtering criteria @@ -186,7 +186,7 @@ public void listBankAccounts(@Nullable final HyperwalletBankAccountPagination ba *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankCard the {@code HyperwalletBankCard} to be created; must not be null From 381a03cd2e328e32f86cf319a744afe7269f607f Mon Sep 17 00:00:00 2001 From: vshcherbyna-epam <48257687+vshcherbyna-epam@users.noreply.github.com> Date: Sat, 4 May 2019 00:18:51 +0300 Subject: [PATCH 11/17] HW-51321: Get paypal account (#3) * HW-51321: Add support to retrieve PayPal accounts --- core/src/main/java/com/hyperwallet/android/Hyperwallet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index 33766d2c..f00a42ec 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -161,7 +161,7 @@ public void createBankAccount(@NonNull final HyperwalletBankAccount bankAccount, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankAccountPagination the ordering and filtering criteria @@ -186,7 +186,7 @@ public void listBankAccounts(@Nullable final HyperwalletBankAccountPagination ba *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankCard the {@code HyperwalletBankCard} to be created; must not be null From 3df53c58f30b2d55d84fa781758bb33a25f5a0da Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Tue, 30 Apr 2019 13:30:47 +0300 Subject: [PATCH 12/17] HW-51228. PayPal Account Deactivation --- .../com/hyperwallet/android/Hyperwallet.java | 33 +++++ .../android/HyperwalletTestSuite.java | 2 + ...yperwalletDeactivatePayPalAccountTest.java | 113 ++++++++++++++++++ .../deactivated_paypal_account_response.json | 16 +++ 4 files changed, 164 insertions(+) create mode 100644 core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletDeactivatePayPalAccountTest.java create mode 100644 core/src/test/resources/deactivated_paypal_account_response.json diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index 70f3d975..3f89cf42 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -423,6 +423,39 @@ public void deactivateBankCard(@NonNull final String transferMethodToken, @Nulla performRestTransaction(builder, listener); } + /** + * Deactivates the {@link PayPalAccount} linked to the transfer method token specified. The + * {@code PayPalAccount} being deactivated must belong to the User that is associated with the + * authentication token returned from + * {@link HyperwalletAuthenticationTokenProvider#retrieveAuthenticationToken(HyperwalletAuthenticationTokenListener)}. + * + *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from + * processing the request.

+ * + *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + * if the current one is expired or about to expire.

+ * + * @param transferMethodToken the Hyperwallet specific unique identifier for the {@code PayPalAccount} + * being deactivated; must not be null + * @param notes a note regarding the status change + * @param listener the callback handler of responses from the Hyperwallet platform; must not be null + */ + public void deactivatePayPalAccount(@NonNull final String transferMethodToken, @Nullable final String notes, + @NonNull final HyperwalletListener listener) { + PathFormatter pathFormatter = new PathFormatter("users/{0}/paypal-accounts/{1}/status-transitions", + transferMethodToken); + + final HyperwalletStatusTransition deactivatedStatusTransition = new HyperwalletStatusTransition( + HyperwalletStatusTransition.StatusDefinition.DE_ACTIVATED); + deactivatedStatusTransition.setNotes(notes); + RestTransaction.Builder builder = new RestTransaction.Builder<>(PUT, pathFormatter, + new TypeReference() { + }, listener).jsonModel(deactivatedStatusTransition); + + performRestTransaction(builder, listener); + } + + /** * Returns the {@link HyperwalletTransferMethod} (Bank Account, Bank Card, PayPay Account, Prepaid Card, * Paper Checks) for the User associated with the authentication token returned from diff --git a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java index 6e878f01..11a0948e 100644 --- a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java +++ b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java @@ -6,6 +6,7 @@ import com.hyperwallet.android.transfermethod.HyperwalletCreatePayPalAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletDeactivateBankAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletDeactivateBankCardTest; +import com.hyperwallet.android.transfermethod.HyperwalletDeactivatePayPalAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletGetBankAccountTest; import com.hyperwallet.android.transfermethod.HyperwalletGetBankCardTest; import com.hyperwallet.android.transfermethod.HyperwalletGetPayPalTest; @@ -35,6 +36,7 @@ HyperwalletUpdatePayPalAccountTest.class, HyperwalletDeactivateBankAccountTest.class, HyperwalletDeactivateBankCardTest.class, + HyperwalletDeactivatePayPalAccountTest.class, HyperwalletListTransferMethodsTest.class, HyperwalletListBankCardsTest.class, HyperwalletRetrieveTransferMethodConfigurationKeysTest.class, diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletDeactivatePayPalAccountTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletDeactivatePayPalAccountTest.java new file mode 100644 index 00000000..112853b6 --- /dev/null +++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletDeactivatePayPalAccountTest.java @@ -0,0 +1,113 @@ +package com.hyperwallet.android.transfermethod; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import com.hyperwallet.android.Hyperwallet; +import com.hyperwallet.android.exception.HyperwalletException; +import com.hyperwallet.android.listener.HyperwalletListener; +import com.hyperwallet.android.model.HyperwalletError; +import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.HyperwalletStatusTransition; +import com.hyperwallet.android.rule.HyperwalletExternalResourceManager; +import com.hyperwallet.android.rule.HyperwalletMockWebServer; +import com.hyperwallet.android.rule.HyperwalletSdkMock; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.robolectric.RobolectricTestRunner; + +import java.net.HttpURLConnection; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +@RunWith(RobolectricTestRunner.class) +public class HyperwalletDeactivatePayPalAccountTest { + + @Rule + public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer(); + @Rule + public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer); + @Rule + public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager(); + @Rule + public MockitoRule mMockitoRule = MockitoJUnit.rule(); + @Mock + private HyperwalletListener mListener; + @Captor + private ArgumentCaptor mStatusTransitionCaptor; + @Captor + private ArgumentCaptor mExceptionArgumentCaptor; + + private final CountDownLatch mAwait = new CountDownLatch(1); + + @Test + public void testDeactivatePayPalAccount_successfulStatusTransition() throws Exception { + + String responseBody = mExternalResourceManager.getResourceContent( + "deactivated_paypal_account_response.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_CREATED).withBody(responseBody).mock(); + + Hyperwallet.getDefault().deactivatePayPalAccount("trm-da21954a-3910-4d70-b83d-0c2d96104394", null, + mListener); + mAwait.await(50, TimeUnit.MILLISECONDS); + + verify(mListener).onSuccess(mStatusTransitionCaptor.capture()); + verify(mListener, never()).onFailure(any(HyperwalletException.class)); + HyperwalletStatusTransition statusTransitionResponse = mStatusTransitionCaptor.getValue(); + assertNotNull(statusTransitionResponse); + assertThat(statusTransitionResponse.getFromStatus(), + is(HyperwalletStatusTransition.StatusDefinition.ACTIVATED)); + assertThat(statusTransitionResponse.getToStatus(), + is(HyperwalletStatusTransition.StatusDefinition.DE_ACTIVATED)); + assertThat(statusTransitionResponse.getTransition(), + is(HyperwalletStatusTransition.StatusDefinition.DE_ACTIVATED)); + assertThat(statusTransitionResponse.getToken(), is("sts-70ddc78a-0c14-4a72-8390-75d49ff376f2")); + assertNotNull(statusTransitionResponse.getCreatedOn()); + assertThat(mServer.getRequest().getPath(), endsWith( + "users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-da21954a-3910-4d70-b83d" + + "-0c2d96104394/status-transitions")); + } + + @Test + public void testDeactivatePayPalAccount_unsuccessfulStatusTransition() throws Exception { + + String responseBody = mExternalResourceManager.getResourceContentError("invalid_status_transition.json"); + mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock(); + + Hyperwallet.getDefault().deactivatePayPalAccount("trm-fake-token", null, mListener); + mAwait.await(100, TimeUnit.MILLISECONDS); + + verify(mListener).onFailure(mExceptionArgumentCaptor.capture()); + verify(mListener, never()).onSuccess(any(HyperwalletStatusTransition.class)); + HyperwalletException hyperwalletException = mExceptionArgumentCaptor.getValue(); + assertNotNull(hyperwalletException); + final HyperwalletErrors hyperwalletErrors = hyperwalletException.getHyperwalletErrors(); + assertNotNull(hyperwalletErrors); + final List statusTransitionErrorList = hyperwalletErrors.getErrors(); + assertNotNull(statusTransitionErrorList); + assertThat(statusTransitionErrorList, hasSize(1)); + HyperwalletError statusTransitionError = statusTransitionErrorList.get(0); + assertNotNull(statusTransitionError); + assertThat(statusTransitionError.getCode(), is("INVALID_FIELD_VALUE")); + assertThat(statusTransitionError.getFieldName(), is("transition")); + assertThat(statusTransitionError.getMessage(), is("transition is invalid")); + assertThat(mServer.getRequest().getPath(), + endsWith( + "users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-fake-token/status" + + "-transitions")); + } +} diff --git a/core/src/test/resources/deactivated_paypal_account_response.json b/core/src/test/resources/deactivated_paypal_account_response.json new file mode 100644 index 00000000..277fd08d --- /dev/null +++ b/core/src/test/resources/deactivated_paypal_account_response.json @@ -0,0 +1,16 @@ +{ + "token": "sts-70ddc78a-0c14-4a72-8390-75d49ff376f2", + "createdOn": "2017-10-30T18:50:20", + "transition": "DE_ACTIVATED", + "fromStatus": "ACTIVATED", + "toStatus": "DE_ACTIVATED", + "notes": "Closing this account.", + "links": [ + { + "params": { + "rel": "self" + }, + "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-f695ef43-9614-4e17-9269-902c234616c3/paypal-accounts/trm-da21954a-3910-4d70-b83d-0c2d96104394/status-transitions/sts-70ddc78a-0c14-4a72-8390-75d49ff376f2" + } + ] +} \ No newline at end of file From 0509925da717b600bd05888a08f16cd798ba0579 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Thu, 2 May 2019 09:58:57 +0300 Subject: [PATCH 13/17] HW-51228. Changed PUT tp POST --- core/src/main/java/com/hyperwallet/android/Hyperwallet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index 3f89cf42..0f48f5df 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -432,7 +432,7 @@ public void deactivateBankCard(@NonNull final String transferMethodToken, @Nulla *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param transferMethodToken the Hyperwallet specific unique identifier for the {@code PayPalAccount} @@ -448,7 +448,7 @@ public void deactivatePayPalAccount(@NonNull final String transferMethodToken, @ final HyperwalletStatusTransition deactivatedStatusTransition = new HyperwalletStatusTransition( HyperwalletStatusTransition.StatusDefinition.DE_ACTIVATED); deactivatedStatusTransition.setNotes(notes); - RestTransaction.Builder builder = new RestTransaction.Builder<>(PUT, pathFormatter, + RestTransaction.Builder builder = new RestTransaction.Builder<>(POST, pathFormatter, new TypeReference() { }, listener).jsonModel(deactivatedStatusTransition); From 3e0a8ff284b8884ac6204aeffd0b0953816f0174 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 3 May 2019 15:27:35 -0700 Subject: [PATCH 14/17] fix javadoc --- core/src/main/java/com/hyperwallet/android/Hyperwallet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index 0f48f5df..f00a42ec 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -210,7 +210,7 @@ public void createBankCard(@NonNull final HyperwalletBankCard bankCard, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param payPalAccount the {@code PayPalAccount} to be created; must not be null @@ -341,7 +341,7 @@ public void updateBankCard(@NonNull final HyperwalletBankCard bankCard, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param payPalAccount the {@code PayPalAccount} to be created; must not be null From aa7bfee71c9759fc43626e2eaa29e0d1ce946298 Mon Sep 17 00:00:00 2001 From: Anna <48258136+azakrevska-epam@users.noreply.github.com> Date: Fri, 3 May 2019 23:49:14 +0300 Subject: [PATCH 15/17] HW-51226. PayPalAccount update (#1) * HW-51226. Add support to PayPal account update --- core/src/main/java/com/hyperwallet/android/Hyperwallet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index f00a42ec..33766d2c 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -161,7 +161,7 @@ public void createBankAccount(@NonNull final HyperwalletBankAccount bankAccount, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankAccountPagination the ordering and filtering criteria @@ -186,7 +186,7 @@ public void listBankAccounts(@Nullable final HyperwalletBankAccountPagination ba *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankCard the {@code HyperwalletBankCard} to be created; must not be null From 1da01f5c0bcaeb229fecd8c846fcb09a56377ee1 Mon Sep 17 00:00:00 2001 From: vshcherbyna-epam <48257687+vshcherbyna-epam@users.noreply.github.com> Date: Sat, 4 May 2019 00:18:51 +0300 Subject: [PATCH 16/17] HW-51321: Get paypal account (#3) * HW-51321: Add support to retrieve PayPal accounts --- core/src/main/java/com/hyperwallet/android/Hyperwallet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index 33766d2c..f00a42ec 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -161,7 +161,7 @@ public void createBankAccount(@NonNull final HyperwalletBankAccount bankAccount, *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankAccountPagination the ordering and filtering criteria @@ -186,7 +186,7 @@ public void listBankAccounts(@Nullable final HyperwalletBankAccountPagination ba *

The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from * * processing the request.

* - *

This function will requests a new authentication token via {@link HyperwalletAuthenticationTokenProvider} + *

This function will request a new authentication token via {@link HyperwalletAuthenticationTokenProvider} * if the current one is expired or about to expire.

* * @param bankCard the {@code HyperwalletBankCard} to be created; must not be null From 0f01edcba325c8045e3b9f1d2556bc9659080060 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 3 May 2019 18:17:47 -0700 Subject: [PATCH 17/17] test --- core/src/main/java/com/hyperwallet/android/Hyperwallet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index f00a42ec..6328331b 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -388,7 +388,7 @@ public void deactivateBankAccount(@NonNull final String transferMethodToken, @Nu new TypeReference() { }, listener).jsonModel(deactivatedStatusTransition); - performRestTransaction(builder, listener); + performRestTransaction(builder, listener); } /**