diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java
index 70f3d975..6328331b 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
@@ -388,7 +388,7 @@ public void deactivateBankAccount(@NonNull final String transferMethodToken, @Nu
new TypeReference() {
}, listener).jsonModel(deactivatedStatusTransition);
- performRestTransaction(builder, listener);
+ performRestTransaction(builder, listener);
}
/**
@@ -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