From c719430d61c49a99efab8b67485e0c035ccea705 Mon Sep 17 00:00:00 2001 From: Viktor Shcherbyna Date: Tue, 30 Apr 2019 13:16:20 +0300 Subject: [PATCH 1/6] HW-51321: Get paypal account --- .../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 d0eecf36..a9a1e886 100644 --- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java +++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java @@ -216,7 +216,7 @@ public void createBankCard(@NonNull final HyperwalletBankCard bankCard, * 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); @@ -490,6 +490,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 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 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..92ef72f1 --- /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.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(), is(notNullValue())); + assertThat(errors.getErrors().size(), is(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 f0c5799cc801a376df66d80289cff816556031f5 Mon Sep 17 00:00:00 2001 From: Viktor Shcherbyna Date: Tue, 30 Apr 2019 15:22:29 +0300 Subject: [PATCH 2/6] test optimization --- .../android/transfermethod/HyperwalletGetPayPalTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetPayPalTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetPayPalTest.java index 92ef72f1..9722bae4 100644 --- a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetPayPalTest.java +++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetPayPalTest.java @@ -4,6 +4,7 @@ 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; @@ -137,8 +138,7 @@ public void testGetGetPayPalAccount_returnsError() throws InterruptedException { assertThat(exception, is(notNullValue())); HyperwalletErrors errors = exception.getHyperwalletErrors(); assertThat(errors, is(notNullValue())); - assertThat(errors.getErrors(), is(notNullValue())); - assertThat(errors.getErrors().size(), is(1)); + assertThat(errors.getErrors(), hasSize(1)); HyperwalletError error = errors.getErrors().get(0); assertThat(error.getCode(), is("SYSTEM_ERROR")); From 5dd0ef1ab04b5c6050c7ea42e94d4a18f6ba754a Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Tue, 30 Apr 2019 12:45:42 -0700 Subject: [PATCH 3/6] 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 0275ec00826787cb293c84a7c329d8e5dfb80ca5 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Tue, 30 Apr 2019 15:23:32 -0700 Subject: [PATCH 4/6] 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 afca6718ec793fbd1ca9aa4b3001e49580f01624 Mon Sep 17 00:00:00 2001 From: Viktor Shcherbyna Date: Tue, 30 Apr 2019 13:16:20 +0300 Subject: [PATCH 5/6] HW-51321: Get paypal account --- .../com/hyperwallet/android/Hyperwallet.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java index a9a1e886..0b5f0aa9 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 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 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 @@ -394,7 +394,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 @@ -434,7 +434,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 @@ -473,7 +473,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 @@ -496,7 +496,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 transferMethodToken the Hyperwallet specific unique identifier for the {@code PayPalAccount} @@ -522,7 +522,7 @@ public void getPayPalAccount(@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 transferMethodConfigurationKeysQuery containing the transfer method configuration key query, @@ -549,7 +549,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 97dd003a71fd4f9e68b4556bf50e766327bae9ab Mon Sep 17 00:00:00 2001 From: Viktor Shcherbyna Date: Fri, 3 May 2019 14:58:06 +0300 Subject: [PATCH 6/6] revert unneeded changes --- build.gradle | 2 +- core/build.gradle | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 6d0a25b4..ea4665c4 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ allprojects { mavenLocal() } - project.version = "1.0.0-beta02-SNAPSHOT"; + project.version = "1.0.0-beta01"; } task clean(type: Delete) { diff --git a/core/build.gradle b/core/build.gradle index d691a43f..d842635a 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -115,9 +115,6 @@ 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 { @@ -151,7 +148,7 @@ publishing { tasks.withType(Sign) { onlyIf { - isReleaseVersion && !gradle.taskGraph.hasTask("publishToMavenLocal") + isReleaseVersion } }