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
@@ -233,14 +233,14 @@ public void createPayPalAccount(@NonNull final PayPalAccount payPalAccount,
* 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}
* 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);
@@ -257,7 +257,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}
@@ -284,7 +284,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
@@ -313,7 +313,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
@@ -368,7 +368,7 @@ public void updatePayPalAccount(@NonNull final PayPalAccount payPalAccount,
* 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}
@@ -400,7 +400,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
@@ -446,7 +446,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 transferMethodPagination the ordering and filtering criteria
@@ -486,7 +486,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
@@ -525,7 +525,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
@@ -542,6 +542,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
@@ -550,7 +574,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,
@@ -577,7 +601,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
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 22e89d1c4b597ed71f35d8b7473c2947a3e4b03b Mon Sep 17 00:00:00 2001
From: Flavio Mattos
Date: Tue, 30 Apr 2019 12:45:42 -0700
Subject: [PATCH 08/16] 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 c31df58a803ac62510f7922b0813701c1a79ed60 Mon Sep 17 00:00:00 2001
From: Flavio Mattos
Date: Tue, 30 Apr 2019 15:23:32 -0700
Subject: [PATCH 09/16] 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 eddeb7fb7dd5ccddd40123115abfc94530cbd241 Mon Sep 17 00:00:00 2001
From: Flavio Mattos
Date: Fri, 3 May 2019 15:19:03 -0700
Subject: [PATCH 10/16] 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 e6325f29..6e878f01 100644
--- a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java
+++ b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java
@@ -8,6 +8,7 @@
import com.hyperwallet.android.transfermethod.HyperwalletDeactivateBankCardTest;
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;
@@ -28,6 +29,7 @@
HyperwalletCreatePayPalAccountTest.class,
HyperwalletGetBankAccountTest.class,
HyperwalletGetBankCardTest.class,
+ HyperwalletGetPayPalTest.class,
HyperwalletUpdateBankAccountTest.class,
HyperwalletUpdateBankCardTest.class,
HyperwalletUpdatePayPalAccountTest.class,
From f2beb6d4cd03ae02f13ff73e8ac68ce1935e9327 Mon Sep 17 00:00:00 2001
From: Anna <48258136+azakrevska-epam@users.noreply.github.com>
Date: Sat, 4 May 2019 02:45:29 +0300
Subject: [PATCH 11/16] HW-51228. PayPal Account Deactivation (#4)
* HW-51228. Add support for PayPal account deactivation
---
.../com/hyperwallet/android/Hyperwallet.java | 37 +++++-
.../android/HyperwalletTestSuite.java | 2 +
...yperwalletDeactivatePayPalAccountTest.java | 113 ++++++++++++++++++
.../deactivated_paypal_account_response.json | 16 +++
4 files changed, 166 insertions(+), 2 deletions(-)
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..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
@@ -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 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 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<>(POST, 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 082b87e8e231d0c63c1333fe87be39f19f8bb4a7 Mon Sep 17 00:00:00 2001
From: Flavio Mattos
Date: Fri, 3 May 2019 18:18:45 -0700
Subject: [PATCH 12/16] Feature/hw 51228 deactivate pay pal account (#16)
* HW-51228. PayPal Account Deactivation
---
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);
}
/**
From b43583db9bffe36dc6cb5645ba2ce9320d7ce0b6 Mon Sep 17 00:00:00 2001
From: Viktor Shcherbyna
Date: Tue, 30 Apr 2019 13:16:20 +0300
Subject: [PATCH 13/16] HW-51229: List PayPal accounts
---
.../com/hyperwallet/android/Hyperwallet.java | 25 +--
.../HyperwalletPayPalAccountPagination.java | 70 ++++++++
.../HyperwalletTransferMethodPagination.java | 2 +-
.../android/HyperwalletTestSuite.java | 4 +-
...yperwalletPayPalAccountPaginationTest.java | 151 +++++++++++++++++
.../HyperwalletListPayPalAccountsTest.java | 160 ++++++++++++++++++
.../pay_pal_accounts_error_response.json | 8 +
.../resources/pay_pal_accounts_response.json | 49 ++++++
.../pay_pal_no_accounts_response.json | 15 ++
9 files changed, 470 insertions(+), 14 deletions(-)
create mode 100644 core/src/main/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPagination.java
create mode 100644 core/src/test/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPaginationTest.java
create mode 100644 core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
create mode 100644 core/src/test/resources/errors/pay_pal_accounts_error_response.json
create mode 100644 core/src/test/resources/pay_pal_accounts_response.json
create mode 100644 core/src/test/resources/pay_pal_no_accounts_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 6328331b..86bf5cdd 100644
--- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java
+++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java
@@ -32,11 +32,11 @@
import com.hyperwallet.android.model.HyperwalletBankCard;
import com.hyperwallet.android.model.HyperwalletBankCardPagination;
import com.hyperwallet.android.model.HyperwalletPagination;
+import com.hyperwallet.android.model.HyperwalletPayPalAccountPagination;
import com.hyperwallet.android.model.HyperwalletStatusTransition;
import com.hyperwallet.android.model.HyperwalletTransferMethod;
import com.hyperwallet.android.model.HyperwalletTransferMethodPagination;
import com.hyperwallet.android.model.PayPalAccount;
-import com.hyperwallet.android.model.PayPalAccountPagination;
import com.hyperwallet.android.model.TypeReference;
import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationFieldResult;
import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKeyResult;
@@ -523,7 +523,7 @@ public void listTransferMethods(@Nullable final HyperwalletTransferMethodPaginat
* if the current one is expired or about to expire.
*
* @param bankCardPagination the ordering and filtering criteria
- * @param listener the callback handler of responses from the Hyperwallet platform; must not be null
+ * @param listener the callback handler of responses from the Hyperwallet platform; must not be null
*/
public void listBankCards(@Nullable final HyperwalletBankCardPagination bankCardPagination,
@NonNull final HyperwalletListener> listener) {
@@ -542,7 +542,7 @@ public void listBankCards(@Nullable final HyperwalletBankCardPagination bankCard
* or an empty {@code List} if non exist.
*
* The ordering and filtering of {@code PayPalAccount} will be based on the criteria specified within the
- * {@link PayPalAccountPagination} object, if it is not null. Otherwise the default ordering and
+ * {@link HyperwalletPayPalAccountPagination} object, if it is not null. Otherwise the default ordering and
* filtering will be applied.
*
*
@@ -550,7 +550,7 @@ public void listBankCards(@Nullable final HyperwalletBankCardPagination bankCard
* - Limit: 10
* - Created Before: N/A
* - Created After: N/A
- * - Type: Bank Card
+ * - Type: PAYPAL_ACCOUNT
* - Status: All
* - Sort By: Created On
*
@@ -561,15 +561,16 @@ public void listBankCards(@Nullable final HyperwalletBankCardPagination bankCard
* 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
- * @param listener the callback handler of responses from the Hyperwallet platform; must not be null
+ * @param hyperwalletPayPalAccountPagination the ordering and filtering criteria
+ * @param listener the callback handler of responses from the Hyperwallet platform; must not be null
*/
- public void listPayPalAccounts(@Nullable final PayPalAccountPagination bankCardPagination,
- @NonNull final HyperwalletListener> listener) {
- Map urlQuery = buildUrlQueryIfRequired(bankCardPagination);
- PathFormatter pathFormatter = new PathFormatter("users/{0}/bank-cards");
+ public void listPayPalAccounts(
+ @Nullable final HyperwalletPayPalAccountPagination hyperwalletPayPalAccountPagination,
+ @NonNull final HyperwalletListener> listener) {
+ Map urlQuery = buildUrlQueryIfRequired(hyperwalletPayPalAccountPagination);
+ PathFormatter pathFormatter = new PathFormatter("users/{0}/paypal-accounts");
RestTransaction.Builder builder = new RestTransaction.Builder<>(GET, pathFormatter,
- new TypeReference>() {
+ new TypeReference>() {
}, listener).query(urlQuery);
performRestTransaction(builder, listener);
@@ -790,7 +791,7 @@ private Map buildUrlQueryIfRequired(@Nullable HyperwalletPaginat
return queryMap;
}
- public static void clearInstance(){
+ public static void clearInstance() {
sInstanceLast = null;
}
}
diff --git a/core/src/main/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPagination.java b/core/src/main/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPagination.java
new file mode 100644
index 00000000..9821b347
--- /dev/null
+++ b/core/src/main/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPagination.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2018 Hyperwallet
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
+ * the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.hyperwallet.android.model;
+
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;
+
+import androidx.annotation.NonNull;
+
+import com.hyperwallet.android.util.DateUtil;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * Represents the PayPal Account pagination fields
+ */
+public class HyperwalletPayPalAccountPagination extends HyperwalletTransferMethodPagination {
+
+ protected static final String TRANSFER_METHOD_CREATE_ON = "createdOn";
+
+ private Date mCreatedOn;
+
+ /**
+ * Constructs the default implementation of the PayPal Account pagination.
+ */
+ public HyperwalletPayPalAccountPagination() {
+ super();
+ setType(PAYPAL_ACCOUNT);
+ }
+
+ /**
+ * Constructs the PayPal Account pagination based in the preview request with extra parameters.
+ *
+ * @param urlQueryMap the map with properties to build the pagination
+ */
+ public HyperwalletPayPalAccountPagination(Map urlQueryMap) {
+ super(urlQueryMap);
+ mCreatedOn = getDateValueBy(urlQueryMap, TRANSFER_METHOD_CREATE_ON);
+ setType(PAYPAL_ACCOUNT);
+ }
+
+ public Date getCreatedOn() {
+ return mCreatedOn;
+ }
+
+ @NonNull
+ @Override
+ public Map buildQuery() {
+ Map query = super.buildQuery();
+ if (mCreatedOn != null) {
+ query.put(TRANSFER_METHOD_CREATE_ON, DateUtil.toDateTimeFormat(mCreatedOn));
+ }
+ return query;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/hyperwallet/android/model/HyperwalletTransferMethodPagination.java b/core/src/main/java/com/hyperwallet/android/model/HyperwalletTransferMethodPagination.java
index bb542f55..46ac5c4f 100644
--- a/core/src/main/java/com/hyperwallet/android/model/HyperwalletTransferMethodPagination.java
+++ b/core/src/main/java/com/hyperwallet/android/model/HyperwalletTransferMethodPagination.java
@@ -130,7 +130,7 @@ public HyperwalletTransferMethodPagination(@NonNull Map urlQuery
* @return the valid Date value or null
*/
@Nullable
- private Date getDateValueBy(@NonNull Map urlQueryMap, @NonNull String queryKey) {
+ Date getDateValueBy(@NonNull Map urlQueryMap, @NonNull String queryKey) {
if (containsKeyAndHasValue(urlQueryMap, queryKey)) {
return fromDateTimeString(urlQueryMap.get(queryKey));
}
diff --git a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java
index 11a0948e..08ec8329 100644
--- a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java
+++ b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java
@@ -12,6 +12,7 @@
import com.hyperwallet.android.transfermethod.HyperwalletGetPayPalTest;
import com.hyperwallet.android.transfermethod.HyperwalletListBankAccountsTest;
import com.hyperwallet.android.transfermethod.HyperwalletListBankCardsTest;
+import com.hyperwallet.android.transfermethod.HyperwalletListPayPalAccountsTest;
import com.hyperwallet.android.transfermethod.HyperwalletListTransferMethodsTest;
import com.hyperwallet.android.transfermethod.HyperwalletRetrieveTransferMethodConfigurationKeysTest;
import com.hyperwallet.android.transfermethod.HyperwalletUpdateBankAccountTest;
@@ -40,7 +41,8 @@
HyperwalletListTransferMethodsTest.class,
HyperwalletListBankCardsTest.class,
HyperwalletRetrieveTransferMethodConfigurationKeysTest.class,
- HyperwalletRetrieveTransferMethodConfigurationFieldsTest.class
+ HyperwalletRetrieveTransferMethodConfigurationFieldsTest.class,
+ HyperwalletListPayPalAccountsTest.class
})
public class HyperwalletTestSuite {
diff --git a/core/src/test/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPaginationTest.java b/core/src/test/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPaginationTest.java
new file mode 100644
index 00000000..e0c9d869
--- /dev/null
+++ b/core/src/test/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPaginationTest.java
@@ -0,0 +1,151 @@
+package com.hyperwallet.android.model;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import static com.hyperwallet.android.model.HyperwalletStatusTransition.StatusDefinition.ACTIVATED;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;
+import static com.hyperwallet.android.model.HyperwalletTransferMethodPagination.TransferMethodSortable.ASCENDANT_CREATE_ON;
+import static com.hyperwallet.android.model.HyperwalletTransferMethodPagination.TransferMethodSortable.ASCENDANT_STATUS;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+
+public class HyperwalletPayPalAccountPaginationTest {
+ private final static String OFFSET = "offset";
+ private final static String LIMIT = "limit";
+ private final static String CREATE_BEFORE = "createdBefore";
+ private final static String CREATE_AFTER = "createdAfter";
+ private final static String CREATE_ON = "createdOn";
+ private final static String TRANSFER_METHOD_TYPE = "type";
+ private final static String STATUS = "status";
+ private final static String SORT_BY = "sortBy";
+
+
+ @Test
+ public void testHyperwalletPayPalAccountPagination_withUrlQueryMap() {
+ Map query = new HashMap<>();
+ query.put(OFFSET, "100");
+ query.put(LIMIT, "200");
+ query.put(CREATE_BEFORE, "2017-01-01T10:12:22");
+ query.put(CREATE_AFTER, "2017-01-01T00:00:00");
+ query.put(CREATE_ON, "2017-01-01T10:10:00");
+ query.put(TRANSFER_METHOD_TYPE, PAYPAL_ACCOUNT);
+ query.put(STATUS, ACTIVATED);
+ query.put(SORT_BY, ASCENDANT_STATUS);
+
+ HyperwalletPayPalAccountPagination pagination = new HyperwalletPayPalAccountPagination(query);
+
+ assertThat(pagination.getLimit(), is(200));
+ assertThat(pagination.getOffset(), is(100));
+ assertThat(pagination.getType(), is(PAYPAL_ACCOUNT));
+ assertThat(pagination.getStatus(), is(ACTIVATED));
+ assertThat(pagination.getSortBy(), is(ASCENDANT_STATUS));
+
+ Calendar createdBefore = Calendar.getInstance();
+ createdBefore.setTime(pagination.getCreatedBefore());
+ assertThat(createdBefore.get(Calendar.YEAR), is(2017));
+ assertThat(createdBefore.get(Calendar.MONTH), is(Calendar.JANUARY));
+ assertThat(createdBefore.get(Calendar.DAY_OF_MONTH), is(1));
+ assertThat(createdBefore.get(Calendar.HOUR), is(10));
+ assertThat(createdBefore.get(Calendar.MINUTE), is(12));
+ assertThat(createdBefore.get(Calendar.SECOND), is(22));
+
+ Calendar createdAfter = Calendar.getInstance();
+ createdAfter.setTime(pagination.getCreatedAfter());
+ assertThat(createdAfter.get(Calendar.YEAR), is(2017));
+ assertThat(createdAfter.get(Calendar.MONTH), is(Calendar.JANUARY));
+ assertThat(createdAfter.get(Calendar.DAY_OF_MONTH), is(1));
+ assertThat(createdAfter.get(Calendar.HOUR), is(0));
+ assertThat(createdAfter.get(Calendar.MINUTE), is(0));
+ assertThat(createdAfter.get(Calendar.SECOND), is(0));
+
+ Calendar createdOn = Calendar.getInstance();
+ createdOn.setTime(pagination.getCreatedOn());
+ assertThat(createdOn.get(Calendar.YEAR), is(2017));
+ assertThat(createdOn.get(Calendar.MONTH), is(Calendar.JANUARY));
+ assertThat(createdOn.get(Calendar.DAY_OF_MONTH), is(1));
+ assertThat(createdOn.get(Calendar.HOUR), is(10));
+ assertThat(createdOn.get(Calendar.MINUTE), is(10));
+ assertThat(createdOn.get(Calendar.SECOND), is(0));
+
+ }
+
+
+ @Test
+ public void testHyperwalletPayPalAccountPagination_verifyDefaultValues() {
+
+ HyperwalletPayPalAccountPagination pagination = new HyperwalletPayPalAccountPagination();
+ assertThat(pagination.getLimit(), is(10));
+ assertThat(pagination.getOffset(), is(0));
+ assertThat(pagination.getType(), is(PAYPAL_ACCOUNT));
+ assertThat(pagination.getStatus(), is(nullValue()));
+ assertThat(pagination.getSortBy(), is(nullValue()));
+ assertThat(pagination.getCreatedBefore(), is(nullValue()));
+ assertThat(pagination.getCreatedAfter(), is(nullValue()));
+ }
+
+
+ @Test
+ public void testBuildQuery_verifyDefaultValues() {
+ HyperwalletPagination pagination = new HyperwalletPagination();
+
+ Map query = pagination.buildQuery();
+
+ Assert.assertNotNull(query);
+ assertThat(query.size(), is(2));
+ assertThat(query.get(OFFSET), is("0"));
+ assertThat(query.get(LIMIT), is("10"));
+ assertThat(query.get(TRANSFER_METHOD_TYPE), is(nullValue()));
+ assertThat(query.get(STATUS), is(nullValue()));
+ assertThat(query.get(SORT_BY), is(nullValue()));
+ assertThat(query.get(CREATE_BEFORE), is(nullValue()));
+ assertThat(query.get(CREATE_AFTER), is(nullValue()));
+ assertThat(query.get(CREATE_ON), is(nullValue()));
+ assertThat(query.get(TRANSFER_METHOD_TYPE), is(nullValue()));
+
+ }
+
+
+ @Test
+ public void testBuildQuery_returnsQueryParameters() {
+
+ Map query = new HashMap<>();
+ query.put(OFFSET, "100");
+ query.put(LIMIT, "200");
+ query.put(CREATE_BEFORE, "2017-01-01T10:12:22");
+ query.put(CREATE_AFTER, "2017-01-01T00:00:000");
+ query.put(CREATE_ON, "2017-01-01T10:10:00");
+ query.put(TRANSFER_METHOD_TYPE, PAYPAL_ACCOUNT);
+ query.put(STATUS, ACTIVATED);
+ query.put(SORT_BY, ASCENDANT_CREATE_ON);
+
+ HyperwalletPayPalAccountPagination pagination = new HyperwalletPayPalAccountPagination(query);
+ Map resultQuery = pagination.buildQuery();
+
+ assertThat(resultQuery.containsKey(STATUS), is(true));
+ assertThat(resultQuery.containsKey(SORT_BY), is(true));
+ assertThat(resultQuery.containsKey(OFFSET), is(true));
+ assertThat(resultQuery.containsKey(LIMIT), is(true));
+ assertThat(resultQuery.containsKey(CREATE_BEFORE), is(true));
+ assertThat(resultQuery.containsKey(CREATE_AFTER), is(true));
+ assertThat(resultQuery.containsKey(TRANSFER_METHOD_TYPE), is(true));
+
+ assertThat(resultQuery.get(LIMIT), is(String.valueOf("200")));
+ assertThat(resultQuery.get(OFFSET), is(String.valueOf("100")));
+ assertThat(resultQuery.get(STATUS), is(ACTIVATED));
+ assertThat(resultQuery.get(SORT_BY), is(ASCENDANT_CREATE_ON));
+ assertThat(resultQuery.get(CREATE_BEFORE), is("2017-01-01T10:12:22"));
+ assertThat(resultQuery.get(CREATE_AFTER), is("2017-01-01T00:00:00"));
+ assertThat(resultQuery.get(CREATE_ON), is("2017-01-01T10:10:00"));
+ assertThat(resultQuery.get(TRANSFER_METHOD_TYPE), is(PAYPAL_ACCOUNT));
+
+ }
+
+
+}
diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
new file mode 100644
index 00000000..5e56762f
--- /dev/null
+++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
@@ -0,0 +1,160 @@
+package com.hyperwallet.android.transfermethod;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
+import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
+import static java.net.HttpURLConnection.HTTP_OK;
+
+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.HyperwalletPayPalAccountPagination;
+import com.hyperwallet.android.model.PayPalAccount;
+import com.hyperwallet.android.model.paging.HyperwalletPageList;
+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.ArgumentMatchers;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.mockwebserver.RecordedRequest;
+
+@RunWith(RobolectricTestRunner.class)
+public class HyperwalletListPayPalAccountsTest {
+ @Rule
+ public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager();
+ @Rule
+ public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer();
+ @Rule
+ public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer);
+ @Rule
+ public MockitoRule mMockito = MockitoJUnit.rule();
+ @Mock
+ private HyperwalletListener> mListener;
+ @Captor
+ private ArgumentCaptor> mListTransferMethodCaptor;
+ @Captor
+ private ArgumentCaptor mExceptionCaptor;
+
+ private CountDownLatch mAwait = new CountDownLatch(1);
+
+
+ @Test
+ public void testListPayPalAccounts_returnsActivatedCards() throws InterruptedException {
+
+ String responseBody = mExternalResourceManager.getResourceContent("pay_pal_accounts_response.json");
+ mServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(responseBody).mock();
+
+ HyperwalletPayPalAccountPagination bankCardPagination = new HyperwalletPayPalAccountPagination();
+
+ assertThat(bankCardPagination, is(notNullValue()));
+ Hyperwallet.getDefault().listPayPalAccounts(bankCardPagination, mListener);
+
+ mAwait.await(500, TimeUnit.MILLISECONDS);
+
+ RecordedRequest recordedRequest = mServer.getRequest();
+ verify(mListener).onSuccess(mListTransferMethodCaptor.capture());
+ verify(mListener, never()).onFailure(any(HyperwalletException.class));
+
+ HyperwalletPageList payPalAccountsResponse = mListTransferMethodCaptor.getValue();
+
+ assertThat(payPalAccountsResponse.getCount(), is(2));
+ assertThat(payPalAccountsResponse.getDataList(), hasSize(2));
+ assertThat(payPalAccountsResponse.getOffset(), is(0));
+ assertThat(payPalAccountsResponse.getLimit(), is(10));
+
+ assertThat(recordedRequest.getPath(),
+ is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts?limit=10&offset=0&type"
+ + "=PAYPAL_ACCOUNT&status=ACTIVATED"));
+ }
+
+ @Test
+ public void testListPayPalAccounts_returnsNoCards() throws InterruptedException {
+ String responseBody = mExternalResourceManager.getResourceContent("pay_pal_no_accounts_response.json");
+ mServer.mockResponse().withHttpResponseCode(HTTP_NO_CONTENT).withBody(responseBody).mock();
+
+ HyperwalletPayPalAccountPagination payPalAccountPagination = new HyperwalletPayPalAccountPagination();
+
+ assertThat(payPalAccountPagination, is(notNullValue()));
+ Hyperwallet.getDefault().listPayPalAccounts(payPalAccountPagination, mListener);
+
+ mAwait.await(500, TimeUnit.MILLISECONDS);
+
+ RecordedRequest recordedRequest = mServer.getRequest();
+ assertThat(recordedRequest.getPath(),
+ containsString("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts?"));
+ assertThat(recordedRequest.getPath(), containsString("type=PAYPAL_ACCOUNT"));
+ assertThat(recordedRequest.getPath(), containsString("limit=10"));
+ assertThat(recordedRequest.getPath(), containsString("offset=0"));
+ assertThat(recordedRequest.getPath(), containsString("status=ACTIVATED"));
+
+ verify(mListener).onSuccess(mListTransferMethodCaptor.capture());
+ verify(mListener, never()).onFailure(any(HyperwalletException.class));
+
+ HyperwalletPageList hyperwalletBankCardsResponse = mListTransferMethodCaptor.getValue();
+ assertThat(hyperwalletBankCardsResponse, is(nullValue()));
+ }
+
+ @Test
+ public void testListPayPalAccounts_returnsError() throws InterruptedException {
+ String responseBody = mExternalResourceManager.getResourceContentError("pay_pal_accounts_error_response.json");
+ mServer.mockResponse().withHttpResponseCode(HTTP_INTERNAL_ERROR).withBody(responseBody).mock();
+
+ HyperwalletPayPalAccountPagination payPalAccountPagination = new HyperwalletPayPalAccountPagination();
+
+ Hyperwallet.getDefault().listPayPalAccounts(payPalAccountPagination, mListener);
+ mAwait.await(500, TimeUnit.MILLISECONDS);
+
+ verify(mListener, never()).onSuccess(ArgumentMatchers.>any());
+ verify(mListener).onFailure(mExceptionCaptor.capture());
+
+ HyperwalletException hyperwalletException = mExceptionCaptor.getValue();
+ assertThat(hyperwalletException, is(notNullValue()));
+ assertThat(((HyperwalletRestException) hyperwalletException).getHttpCode(),
+ is(HTTP_INTERNAL_ERROR));
+
+ HyperwalletErrors hyperwalletErrors = hyperwalletException.getHyperwalletErrors();
+ assertThat(hyperwalletErrors, is(notNullValue()));
+ assertThat(hyperwalletErrors.getErrors(), is(notNullValue()));
+ assertThat(hyperwalletErrors.getErrors().size(), is(1));
+
+ HyperwalletError hyperwalletError = hyperwalletErrors.getErrors().get(0);
+ assertThat(hyperwalletError.getCode(), is("SYSTEM_ERROR"));
+ assertThat(hyperwalletError.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)."));
+ assertThat(hyperwalletError.getFieldName(), is(nullValue()));
+ RecordedRequest recordedRequest = mServer.getRequest();
+ assertThat(recordedRequest.getPath(),
+ containsString("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts?"));
+ assertThat(recordedRequest.getPath(), containsString("type=PAYPAL_ACCOUNT"));
+ assertThat(recordedRequest.getPath(), containsString("limit=10"));
+ assertThat(recordedRequest.getPath(), containsString("offset=0"));
+ assertThat(recordedRequest.getPath(), containsString("status=ACTIVATED"));
+
+ }
+}
diff --git a/core/src/test/resources/errors/pay_pal_accounts_error_response.json b/core/src/test/resources/errors/pay_pal_accounts_error_response.json
new file mode 100644
index 00000000..88024b4b
--- /dev/null
+++ b/core/src/test/resources/errors/pay_pal_accounts_error_response.json
@@ -0,0 +1,8 @@
+{
+ "errors": [
+ {
+ "message": "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).",
+ "code": "SYSTEM_ERROR"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/core/src/test/resources/pay_pal_accounts_response.json b/core/src/test/resources/pay_pal_accounts_response.json
new file mode 100644
index 00000000..e3f03b85
--- /dev/null
+++ b/core/src/test/resources/pay_pal_accounts_response.json
@@ -0,0 +1,49 @@
+{
+ "count": 2,
+ "offset": 0,
+ "limit": 10,
+ "data": [
+ {
+ "token": "trm-7e915660-8c97-47bf-8a4f-0c1bc890d46f",
+ "type": "PAYPAL_ACCOUNT",
+ "status": "ACTIVATED",
+ "createdOn": "2019-01-09T22:50:14",
+ "transferMethodCountry": "US",
+ "transferMethodCurrency": "USD",
+ "email": "jsmith@paypal.com",
+ "links": [
+ {
+ "params": {
+ "rel": "self"
+ },
+ "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-c4292f1a-866f-4310-a289-b916853939de/paypal-accounts/trm-7e915660-8c97-47bf-8a4f-0c1bc890d46f"
+ }
+ ]
+ },
+ {
+ "token": "trm-7742f31d-452c-4bf7-8645-c003fa1511d5",
+ "type": "PAYPAL_ACCOUNT",
+ "status": "VERIFIED",
+ "createdOn": "2019-04-09T10:00:00",
+ "transferMethodCountry": "CA",
+ "transferMethodCurrency": "CAD",
+ "email": "myeee@paypal.com",
+ "links": [
+ {
+ "params": {
+ "rel": "self"
+ },
+ "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-c4292f1a-866f-4310-a289-b916853939de/paypal-accounts/trm-7742f31d-452c-4bf7-8645-c003fa1511d5"
+ }
+ ]
+ }
+ ],
+ "links": [
+ {
+ "params": {
+ "rel": "self"
+ },
+ "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-c4292f1a-866f-4310-a289-b916853939de/paypal-accounts?offset=0&limit=10"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/core/src/test/resources/pay_pal_no_accounts_response.json b/core/src/test/resources/pay_pal_no_accounts_response.json
new file mode 100644
index 00000000..2b14af19
--- /dev/null
+++ b/core/src/test/resources/pay_pal_no_accounts_response.json
@@ -0,0 +1,15 @@
+{
+ "count": 0,
+ "offset": 0,
+ "limit": 10,
+ "data": [
+ ],
+ "links": [
+ {
+ "params": {
+ "rel": "self"
+ },
+ "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-c4292f1a-866f-4310-a289-b916853939de/bank-cards?offset=0&limit=10"
+ }
+ ]
+}
\ No newline at end of file
From 47789fbdf363713fd505cdc1ec12cbf95a93356f Mon Sep 17 00:00:00 2001
From: Viktor Shcherbyna
Date: Tue, 30 Apr 2019 18:59:37 +0300
Subject: [PATCH 14/16] optimization
---
.../transfermethod/HyperwalletListPayPalAccountsTest.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
index 5e56762f..1d08282c 100644
--- a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
+++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
@@ -27,6 +27,7 @@
import com.hyperwallet.android.rule.HyperwalletMockWebServer;
import com.hyperwallet.android.rule.HyperwalletSdkMock;
+import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -140,7 +141,7 @@ public void testListPayPalAccounts_returnsError() throws InterruptedException {
HyperwalletErrors hyperwalletErrors = hyperwalletException.getHyperwalletErrors();
assertThat(hyperwalletErrors, is(notNullValue()));
assertThat(hyperwalletErrors.getErrors(), is(notNullValue()));
- assertThat(hyperwalletErrors.getErrors().size(), is(1));
+ assertThat(hyperwalletErrors.getErrors(), Matchers.hasSize(1));
HyperwalletError hyperwalletError = hyperwalletErrors.getErrors().get(0);
assertThat(hyperwalletError.getCode(), is("SYSTEM_ERROR"));
From b514c453919c48a947a1d0a8bb04368c74dc4646 Mon Sep 17 00:00:00 2001
From: Viktor Shcherbyna
Date: Thu, 2 May 2019 09:24:56 +0300
Subject: [PATCH 15/16] fixes on callouts
---
.../model/HyperwalletBankCardPagination.java | 24 +++++++++++++++
.../HyperwalletBankCardPaginationTest.java | 4 +++
...yperwalletPayPalAccountPaginationTest.java | 4 +--
.../HyperwalletListPayPalAccountsTest.java | 29 +++++++++----------
...on => paypal_accounts_error_response.json} | 0
.../pay_pal_no_accounts_response.json | 15 ----------
...nse.json => paypal_accounts_response.json} | 0
7 files changed, 44 insertions(+), 32 deletions(-)
rename core/src/test/resources/errors/{pay_pal_accounts_error_response.json => paypal_accounts_error_response.json} (100%)
delete mode 100644 core/src/test/resources/pay_pal_no_accounts_response.json
rename core/src/test/resources/{pay_pal_accounts_response.json => paypal_accounts_response.json} (100%)
diff --git a/core/src/main/java/com/hyperwallet/android/model/HyperwalletBankCardPagination.java b/core/src/main/java/com/hyperwallet/android/model/HyperwalletBankCardPagination.java
index a4c906d0..23518373 100644
--- a/core/src/main/java/com/hyperwallet/android/model/HyperwalletBankCardPagination.java
+++ b/core/src/main/java/com/hyperwallet/android/model/HyperwalletBankCardPagination.java
@@ -19,6 +19,11 @@
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
+import androidx.annotation.NonNull;
+
+import com.hyperwallet.android.util.DateUtil;
+
+import java.util.Date;
import java.util.Map;
/**
@@ -26,6 +31,10 @@
*/
public class HyperwalletBankCardPagination extends HyperwalletTransferMethodPagination {
+ protected static final String TRANSFER_METHOD_CREATE_ON = "createdOn";
+
+ private Date mCreatedOn;
+
/**
* Constructors the bank card pagination
*/
@@ -41,6 +50,21 @@ public HyperwalletBankCardPagination() {
*/
public HyperwalletBankCardPagination(Map urlQueryMap) {
super(urlQueryMap);
+ mCreatedOn = getDateValueBy(urlQueryMap, TRANSFER_METHOD_CREATE_ON);
setType(BANK_CARD);
}
+
+ public Date getCreatedOn() {
+ return mCreatedOn;
+ }
+
+ @NonNull
+ @Override
+ public Map buildQuery() {
+ Map query = super.buildQuery();
+ if (mCreatedOn != null) {
+ query.put(TRANSFER_METHOD_CREATE_ON, DateUtil.toDateTimeFormat(mCreatedOn));
+ }
+ return query;
+ }
}
\ No newline at end of file
diff --git a/core/src/test/java/com/hyperwallet/android/model/HyperwalletBankCardPaginationTest.java b/core/src/test/java/com/hyperwallet/android/model/HyperwalletBankCardPaginationTest.java
index 631b3716..8081508f 100644
--- a/core/src/test/java/com/hyperwallet/android/model/HyperwalletBankCardPaginationTest.java
+++ b/core/src/test/java/com/hyperwallet/android/model/HyperwalletBankCardPaginationTest.java
@@ -18,6 +18,7 @@ public class HyperwalletBankCardPaginationTest {
private static final String ACCOUNT_TYPE = "type";
private static final String CREATE_BEFORE = "createdBefore";
private static final String CREATE_AFTER = "createdAfter";
+ private final static String CREATE_ON = "createdOn";
private static final String LIMIT = "limit";
private static final String OFFSET = "offset";
private static final String SORT_BY = "sortBy";
@@ -36,6 +37,7 @@ public void testHyperwalletBankCardPagination_withUrlQueryMap() {
query.put(LIMIT, String.valueOf(limit));
query.put(CREATE_BEFORE, "2017-01-01T10:12:22");
query.put(CREATE_AFTER, "2017-01-01T00:00:00");
+ query.put(CREATE_ON, "2017-01-01T10:00:40");
HyperwalletBankCardPagination pagination = new HyperwalletBankCardPagination(query);
assertThat(pagination.getLimit(), is(limit));
@@ -92,6 +94,7 @@ public void testBuildQuery_returnsQueryParameters() {
query.put(LIMIT, String.valueOf(limit));
query.put(CREATE_BEFORE, "2017-01-01T10:12:22");
query.put(CREATE_AFTER, "2017-01-01T00:00:00");
+ query.put(CREATE_ON, "2017-01-01T10:00:40");
HyperwalletBankCardPagination pagination = new HyperwalletBankCardPagination(query);
Map resultQuery = pagination.buildQuery();
@@ -110,6 +113,7 @@ public void testBuildQuery_returnsQueryParameters() {
assertThat(resultQuery.get(SORT_BY), is(ASCENDANT_CREATE_ON));
assertThat(resultQuery.get(CREATE_BEFORE), is("2017-01-01T10:12:22"));
assertThat(resultQuery.get(CREATE_AFTER), is("2017-01-01T00:00:00"));
+ assertThat(resultQuery.get(CREATE_ON), is("2017-01-01T10:00:40"));
assertThat(resultQuery.get(ACCOUNT_TYPE), is(BANK_CARD));
}
diff --git a/core/src/test/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPaginationTest.java b/core/src/test/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPaginationTest.java
index e0c9d869..514f865c 100644
--- a/core/src/test/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPaginationTest.java
+++ b/core/src/test/java/com/hyperwallet/android/model/HyperwalletPayPalAccountPaginationTest.java
@@ -136,8 +136,8 @@ public void testBuildQuery_returnsQueryParameters() {
assertThat(resultQuery.containsKey(CREATE_AFTER), is(true));
assertThat(resultQuery.containsKey(TRANSFER_METHOD_TYPE), is(true));
- assertThat(resultQuery.get(LIMIT), is(String.valueOf("200")));
- assertThat(resultQuery.get(OFFSET), is(String.valueOf("100")));
+ assertThat(resultQuery.get(LIMIT), is("200"));
+ assertThat(resultQuery.get(OFFSET), is("100"));
assertThat(resultQuery.get(STATUS), is(ACTIVATED));
assertThat(resultQuery.get(SORT_BY), is(ASCENDANT_CREATE_ON));
assertThat(resultQuery.get(CREATE_BEFORE), is("2017-01-01T10:12:22"));
diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
index 1d08282c..85e2452c 100644
--- a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
+++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
@@ -57,7 +57,7 @@ public class HyperwalletListPayPalAccountsTest {
@Mock
private HyperwalletListener> mListener;
@Captor
- private ArgumentCaptor> mListTransferMethodCaptor;
+ private ArgumentCaptor> mListPayPalCaptor;
@Captor
private ArgumentCaptor mExceptionCaptor;
@@ -65,23 +65,23 @@ public class HyperwalletListPayPalAccountsTest {
@Test
- public void testListPayPalAccounts_returnsActivatedCards() throws InterruptedException {
+ public void testListPayPalAccounts_returnsActivatedAccounts() throws InterruptedException {
- String responseBody = mExternalResourceManager.getResourceContent("pay_pal_accounts_response.json");
+ String responseBody = mExternalResourceManager.getResourceContent("paypal_accounts_response.json");
mServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(responseBody).mock();
- HyperwalletPayPalAccountPagination bankCardPagination = new HyperwalletPayPalAccountPagination();
+ HyperwalletPayPalAccountPagination payPalAccountPagination = new HyperwalletPayPalAccountPagination();
- assertThat(bankCardPagination, is(notNullValue()));
- Hyperwallet.getDefault().listPayPalAccounts(bankCardPagination, mListener);
+ assertThat(payPalAccountPagination, is(notNullValue()));
+ Hyperwallet.getDefault().listPayPalAccounts(payPalAccountPagination, mListener);
mAwait.await(500, TimeUnit.MILLISECONDS);
RecordedRequest recordedRequest = mServer.getRequest();
- verify(mListener).onSuccess(mListTransferMethodCaptor.capture());
+ verify(mListener).onSuccess(mListPayPalCaptor.capture());
verify(mListener, never()).onFailure(any(HyperwalletException.class));
- HyperwalletPageList payPalAccountsResponse = mListTransferMethodCaptor.getValue();
+ HyperwalletPageList payPalAccountsResponse = mListPayPalCaptor.getValue();
assertThat(payPalAccountsResponse.getCount(), is(2));
assertThat(payPalAccountsResponse.getDataList(), hasSize(2));
@@ -94,9 +94,8 @@ public void testListPayPalAccounts_returnsActivatedCards() throws InterruptedExc
}
@Test
- public void testListPayPalAccounts_returnsNoCards() throws InterruptedException {
- String responseBody = mExternalResourceManager.getResourceContent("pay_pal_no_accounts_response.json");
- mServer.mockResponse().withHttpResponseCode(HTTP_NO_CONTENT).withBody(responseBody).mock();
+ public void testListPayPalAccounts_returnsNoAccounts() throws InterruptedException {
+ mServer.mockResponse().withHttpResponseCode(HTTP_NO_CONTENT).withBody("").mock();
HyperwalletPayPalAccountPagination payPalAccountPagination = new HyperwalletPayPalAccountPagination();
@@ -113,16 +112,16 @@ public void testListPayPalAccounts_returnsNoCards() throws InterruptedException
assertThat(recordedRequest.getPath(), containsString("offset=0"));
assertThat(recordedRequest.getPath(), containsString("status=ACTIVATED"));
- verify(mListener).onSuccess(mListTransferMethodCaptor.capture());
+ verify(mListener).onSuccess(mListPayPalCaptor.capture());
verify(mListener, never()).onFailure(any(HyperwalletException.class));
- HyperwalletPageList hyperwalletBankCardsResponse = mListTransferMethodCaptor.getValue();
- assertThat(hyperwalletBankCardsResponse, is(nullValue()));
+ HyperwalletPageList payPalAccountsResponse = mListPayPalCaptor.getValue();
+ assertThat(payPalAccountsResponse, is(nullValue()));
}
@Test
public void testListPayPalAccounts_returnsError() throws InterruptedException {
- String responseBody = mExternalResourceManager.getResourceContentError("pay_pal_accounts_error_response.json");
+ String responseBody = mExternalResourceManager.getResourceContentError("paypal_accounts_error_response.json");
mServer.mockResponse().withHttpResponseCode(HTTP_INTERNAL_ERROR).withBody(responseBody).mock();
HyperwalletPayPalAccountPagination payPalAccountPagination = new HyperwalletPayPalAccountPagination();
diff --git a/core/src/test/resources/errors/pay_pal_accounts_error_response.json b/core/src/test/resources/errors/paypal_accounts_error_response.json
similarity index 100%
rename from core/src/test/resources/errors/pay_pal_accounts_error_response.json
rename to core/src/test/resources/errors/paypal_accounts_error_response.json
diff --git a/core/src/test/resources/pay_pal_no_accounts_response.json b/core/src/test/resources/pay_pal_no_accounts_response.json
deleted file mode 100644
index 2b14af19..00000000
--- a/core/src/test/resources/pay_pal_no_accounts_response.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "count": 0,
- "offset": 0,
- "limit": 10,
- "data": [
- ],
- "links": [
- {
- "params": {
- "rel": "self"
- },
- "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-c4292f1a-866f-4310-a289-b916853939de/bank-cards?offset=0&limit=10"
- }
- ]
-}
\ No newline at end of file
diff --git a/core/src/test/resources/pay_pal_accounts_response.json b/core/src/test/resources/paypal_accounts_response.json
similarity index 100%
rename from core/src/test/resources/pay_pal_accounts_response.json
rename to core/src/test/resources/paypal_accounts_response.json
From 29d9116670977262675cbfc9ea38391e8d29a496 Mon Sep 17 00:00:00 2001
From: Viktor Shcherbyna
Date: Fri, 3 May 2019 16:17:41 +0300
Subject: [PATCH 16/16] add test for PayPalAccount form the list
---
.../HyperwalletListPayPalAccountsTest.java | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
index 85e2452c..618cf33e 100644
--- a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
+++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
@@ -14,6 +14,16 @@
import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
import static java.net.HttpURLConnection.HTTP_OK;
+import static com.hyperwallet.android.model.HyperwalletStatusTransition.CREATED_ON;
+import static com.hyperwallet.android.model.HyperwalletStatusTransition.StatusDefinition.ACTIVATED;
+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;
@@ -91,6 +101,15 @@ public void testListPayPalAccounts_returnsActivatedAccounts() throws Interrupted
assertThat(recordedRequest.getPath(),
is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts?limit=10&offset=0&type"
+ "=PAYPAL_ACCOUNT&status=ACTIVATED"));
+
+ PayPalAccount payPalAccount = payPalAccountsResponse.getDataList().get(0);
+ assertThat(payPalAccount.getField(TOKEN), is("trm-7e915660-8c97-47bf-8a4f-0c1bc890d46f"));
+ assertThat(payPalAccount.getField(TYPE), is(PAYPAL_ACCOUNT));
+ assertThat(payPalAccount.getField(STATUS), is(ACTIVATED));
+ assertThat(payPalAccount.getField(CREATED_ON), is("2019-01-09T22:50:14"));
+ assertThat(payPalAccount.getField(TRANSFER_METHOD_COUNTRY), is("US"));
+ assertThat(payPalAccount.getField(TRANSFER_METHOD_CURRENCY), is("USD"));
+ assertThat(payPalAccount.getField(EMAIL), is("jsmith@paypal.com"));
}
@Test