diff --git a/CHANGELOG.md b/CHANGELOG.md
index b5189f42..2a3547c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,4 +7,9 @@ Changelog
* Create Bank Account and Bank Card for United States (USD)
* Retrieve field requirements for bank Accounts and Bank Cards
* List Accounts
-* Deactivate (Remove) Accounts
\ No newline at end of file
+* Deactivate (Remove) Accounts
+
+1.0.0-beta02
+-------------------
+* Added PayPal as a Transfer method
+* Added support to get User object
\ No newline at end of file
diff --git a/README.md b/README.md
index f22a496d..d0a07b0e 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ We also provide an out-of-the-box [Hyperwallet Android UI SDK](https://github.c
To install Hyperwallet Core SDK, you just need to add the dependency into your build.gradle file in Android Studio (or Gradle). For example:
```bash
-api 'com.hyperwallet.android:core-sdk:1.0.0-beta01'
+api 'com.hyperwallet.android:core-sdk:1.0.0-beta02'
```
## Initialization
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")
}
}
diff --git a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java
index 3a7c7773..1a2ea7f9 100644
--- a/core/src/main/java/com/hyperwallet/android/Hyperwallet.java
+++ b/core/src/main/java/com/hyperwallet/android/Hyperwallet.java
@@ -21,8 +21,6 @@
import static com.hyperwallet.android.util.HttpMethod.POST;
import static com.hyperwallet.android.util.HttpMethod.PUT;
-import android.os.Handler;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -34,9 +32,12 @@
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.HyperwalletUser;
+import com.hyperwallet.android.model.PayPalAccount;
import com.hyperwallet.android.model.TypeReference;
import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationFieldResult;
import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKeyResult;
@@ -121,7 +122,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 +162,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 +187,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
@@ -203,20 +204,44 @@ public void createBankCard(@NonNull final HyperwalletBankCard bankCard,
performRestTransaction(builder, listener);
}
+ /**
+ * Creates a {@link PayPalAccount} for the User associated with the authentication token returned from
+ * {@link HyperwalletAuthenticationTokenProvider#retrieveAuthenticationToken(HyperwalletAuthenticationTokenListener)}.
+ *
+ * The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from
+ * * processing the request.
+ *
+ * This function will 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
+ * @param listener the callback handler of responses from the Hyperwallet platform; must not be null
+ */
+ public void createPayPalAccount(@NonNull final PayPalAccount payPalAccount,
+ @NonNull final HyperwalletListener listener) {
+ PathFormatter pathFormatter = new PathFormatter("users/{0}/paypal-accounts");
+
+ RestTransaction.Builder builder = new RestTransaction.Builder<>(POST, pathFormatter,
+ new TypeReference() {
+ }, listener).jsonModel(payPalAccount);
+
+ performRestTransaction(builder, listener);
+ }
+
/**
* Returns the {@link HyperwalletBankAccount} linked to the transfer method token specified, or null if none exists.
*
* 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);
@@ -233,7 +258,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}
@@ -250,6 +275,27 @@ public void getBankCard(@NonNull final String transferMethodToken,
performRestTransaction(builder, listener);
}
+ /**
+ * Returns the {@link HyperwalletUser} linked to the 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 listener the callback handler of responses from the Hyperwallet platform; must not be null
+ */
+ public void getUser(@NonNull final HyperwalletListener listener) {
+ PathFormatter pathFormatter = new PathFormatter("users/{0}");
+
+ RestTransaction.Builder builder = new RestTransaction.Builder<>(GET, pathFormatter,
+ new TypeReference() {
+ }, listener);
+
+ performRestTransaction(builder, listener);
+ }
+
/**
* Updates the {@link HyperwalletBankAccount} for the User associated with the authentication token returned from
* {@link HyperwalletAuthenticationTokenProvider#retrieveAuthenticationToken(HyperwalletAuthenticationTokenListener)}.
@@ -260,7 +306,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 +335,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
@@ -307,6 +353,34 @@ public void updateBankCard(@NonNull final HyperwalletBankCard bankCard,
performRestTransaction(builder, listener);
}
+ /**
+ * Updates the {@link PayPalAccount} for the User associated with the authentication token returned from
+ * {@link HyperwalletAuthenticationTokenProvider#retrieveAuthenticationToken(HyperwalletAuthenticationTokenListener)}.
+ *
+ * To identify the {@code PayPalAccount} that is going to be updated, the transfer method token must be
+ * set as part of the {@code PayPalAccount} object passed in.
+ *
+ * The {@link HyperwalletListener} that is passed in to this method invocation will receive the responses from
+ * processing the request.
+ *
+ * This function will 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
+ * @param listener the callback handler of responses from the Hyperwallet platform; must not be null
+ */
+ public void updatePayPalAccount(@NonNull final PayPalAccount payPalAccount,
+ @NonNull final HyperwalletListener listener) {
+ PathFormatter pathFormatter = new PathFormatter("users/{0}/paypal-accounts/{1}",
+ payPalAccount.getField(HyperwalletTransferMethod.TransferMethodFields.TOKEN));
+
+ RestTransaction.Builder builder = new RestTransaction.Builder<>(PUT, pathFormatter,
+ new TypeReference() {
+ }, listener).jsonModel(payPalAccount);
+
+ performRestTransaction(builder, listener);
+ }
+
/**
* Deactivates the {@link HyperwalletBankAccount} linked to the transfer method token specified. The
* {@code HyperwalletBankAccount} being deactivated must belong to the User that is associated with the
@@ -316,7 +390,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 +422,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
@@ -371,6 +445,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
@@ -394,7 +501,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 +541,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
@@ -451,6 +558,70 @@ public void listBankCards(@Nullable final HyperwalletBankCardPagination bankCard
performRestTransaction(builder, listener);
}
+ /**
+ * Returns the {@link PayPalAccount} for the User associated with the authentication token returned from
+ * {@link HyperwalletAuthenticationTokenProvider#retrieveAuthenticationToken(HyperwalletAuthenticationTokenListener)},
+ * 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 HyperwalletPayPalAccountPagination} object, if it is not null. Otherwise the default ordering and
+ * filtering will be applied.
+ *
+ *
+ * - Offset: 0
+ * - Limit: 10
+ * - Created Before: N/A
+ * - Created After: N/A
+ * - Type: PAYPAL_ACCOUNT
+ * - Status: All
+ * - Sort By: Created On
+ *
+ *
+ * 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 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 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>() {
+ }, listener).query(urlQuery);
+
+ 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
@@ -459,7 +630,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 transferMethodConfigurationKeysQuery containing the transfer method configuration key query,
@@ -486,7 +657,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
@@ -642,7 +813,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/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/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/HyperwalletTransferMethod.java b/core/src/main/java/com/hyperwallet/android/model/HyperwalletTransferMethod.java
index 33c21e47..b0082afe 100644
--- a/core/src/main/java/com/hyperwallet/android/model/HyperwalletTransferMethod.java
+++ b/core/src/main/java/com/hyperwallet/android/model/HyperwalletTransferMethod.java
@@ -58,6 +58,7 @@ public final class TransferMethodTypes {
public static final String PAPER_CHECK = "PAPER_CHECK";
public static final String PREPAID_CARD = "PREPAID_CARD";
public static final String WIRE_ACCOUNT = "WIRE_ACCOUNT";
+ public static final String PAYPAL_ACCOUNT = "PAYPAL_ACCOUNT";
}
@Retention(RetentionPolicy.SOURCE)
@@ -106,7 +107,8 @@ public final class TransferMethodTypes {
TransferMethodFields.CARD_NUMBER,
TransferMethodFields.CARD_TYPE,
TransferMethodFields.DATE_OF_EXPIRY,
- TransferMethodFields.CVV
+ TransferMethodFields.CVV,
+ TransferMethodFields.EMAIL
})
public @interface TransferMethodFieldKey {
}
@@ -140,6 +142,7 @@ public final class TransferMethodFields {
public static final String PHONE_NUMBER = "phoneNumber";
public static final String POSTAL_CODE = "postalCode";
public static final String STATE_PROVINCE = "stateProvince";
+ public static final String EMAIL = "email";
// bank account field keys
public static final String BANK_ACCOUNT_ID = "bankAccountId";
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 57090d9a..46ac5c4f 100644
--- a/core/src/main/java/com/hyperwallet/android/model/HyperwalletTransferMethodPagination.java
+++ b/core/src/main/java/com/hyperwallet/android/model/HyperwalletTransferMethodPagination.java
@@ -23,6 +23,7 @@
import static com.hyperwallet.android.model.HyperwalletStatusTransition.StatusDefinition.VERIFIED;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.WIRE_ACCOUNT;
import static com.hyperwallet.android.util.DateUtil.fromDateTimeString;
@@ -58,7 +59,8 @@ public class HyperwalletTransferMethodPagination extends HyperwalletPagination {
@StringDef({
BANK_ACCOUNT,
WIRE_ACCOUNT,
- BANK_CARD
+ BANK_CARD,
+ PAYPAL_ACCOUNT
})
public @interface TransferMethodTypeQuery {
}
@@ -128,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/main/java/com/hyperwallet/android/model/HyperwalletUser.java b/core/src/main/java/com/hyperwallet/android/model/HyperwalletUser.java
new file mode 100644
index 00000000..7e537b18
--- /dev/null
+++ b/core/src/main/java/com/hyperwallet/android/model/HyperwalletUser.java
@@ -0,0 +1,779 @@
+/*
+ * 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 android.os.Parcel;
+import android.os.Parcelable;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.StringDef;
+
+import com.hyperwallet.android.model.meta.HyperwalletField;
+import com.hyperwallet.android.util.JsonUtils;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Represents the User fields.
+ */
+public final class HyperwalletUser implements HyperwalletJsonModel, Parcelable {
+
+ @Retention(RetentionPolicy.SOURCE)
+ @StringDef({
+ UserStatuses.PRE_ACTIVATED,
+ UserStatuses.ACTIVATED,
+ UserStatuses.LOCKED,
+ UserStatuses.FROZEN,
+ UserStatuses.DE_ACTIVATED
+ })
+ public @interface UserStatus {
+ }
+
+ public interface UserStatuses {
+ String PRE_ACTIVATED = "PRE_ACTIVATED";
+ String ACTIVATED = "ACTIVATED";
+ String LOCKED = "LOCKED";
+ String FROZEN = "FROZEN";
+ String DE_ACTIVATED = "DE_ACTIVATED";
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @StringDef({
+ VerificationStatuses.NOT_REQUIRED,
+ VerificationStatuses.REQUIRED,
+ VerificationStatuses.FAILED,
+ VerificationStatuses.UNDER_REVIEW,
+ VerificationStatuses.VERIFIED
+ })
+ public @interface VerificationStatus {
+ }
+
+
+ public interface VerificationStatuses {
+ String NOT_REQUIRED = "NOT_REQUIRED";
+ String REQUIRED = "REQUIRED";
+ String FAILED = "FAILED";
+ String UNDER_REVIEW = "UNDER_REVIEW";
+ String VERIFIED = "VERIFIED";
+ }
+
+ public interface BusinessContactRoles {
+ String DIRECTOR = "DIRECTOR";
+ String OWNER = "OWNER";
+ String OTHER = "OTHER";
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @StringDef({
+ BusinessContactRoles.DIRECTOR,
+ BusinessContactRoles.OWNER,
+ BusinessContactRoles.OTHER
+ })
+ public @interface BusinessContactRole {
+
+ }
+
+ public interface BusinessTypes {
+ String CORPORATION = "CORPORATION";
+ String PARTNERSHIP = "PARTNERSHIP";
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @StringDef({
+ BusinessTypes.CORPORATION,
+ BusinessTypes.PARTNERSHIP
+ })
+ public @interface BusinessType {
+
+ }
+
+ public interface GovernmentIdTypes {
+ String PASSPORT = "PASSPORT";
+ String NATIONAL_ID_CARD = "NATIONAL_ID_CARD";
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @StringDef({
+ GovernmentIdTypes.PASSPORT,
+ GovernmentIdTypes.NATIONAL_ID_CARD
+ })
+ public @interface GovernmentIdType {
+
+ }
+
+ public interface ProfileTypes {
+ String INDIVIDUAL = "INDIVIDUAL";
+ String BUSINESS = "BUSINESS";
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @StringDef({
+ ProfileTypes.INDIVIDUAL,
+ ProfileTypes.BUSINESS
+ })
+ public @interface ProfileType {
+
+ }
+
+ public interface Genders {
+ String MALE = "MALE";
+ String FEMALE = "FEMALE";
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @StringDef({
+ Genders.MALE,
+ Genders.FEMALE
+ })
+ public @interface Gender {
+
+ }
+
+ /**
+ * Common User field keys
+ */
+ public interface UserFields {
+ String TOKEN = "token";
+ String STATUS = "status";
+ String VERIFICATION_STATUS = "verificationStatus";
+ String CREATED_ON = "createdOn";
+ String CLIENT_USER_ID = "clientUserId";
+ String ADDRESS_LINE_1 = "addressLine1";
+ String ADDRESS_LINE_2 = "addressLine2";
+ String BUSINESS_CONTACT_ROLE = "businessContactRole";
+ String BUSINESS_NAME = "businessName";
+ String BUSINESS_REGISTRATION_COUNTRY = "businessRegistrationCountry";
+ String BUSINESS_REGISTRATION_ID = "businessRegistrationId";
+ String BUSINESS_REGISTRATION_STATE_PROVINCE = "businessRegistrationStateProvince";
+ String BUSINESS_CONTACT_ADDRESS_LINE_1 = "businessContactAddressLine1";
+ String BUSINESS_CONTACT_ADDRESS_LINE_2 = "businessContactAddressLine2";
+ String BUSINESS_CONTACT_CITY = "businessContactCity";
+ String BUSINESS_CONTACT_STATE_PROVINCE = "businessContactStateProvince";
+ String BUSINESS_CONTACT_COUNTRY = "businessContactCountry";
+ String BUSINESS_CONTACT_POSTAL_CODE = "businessContactPostalCode";
+ String BUSINESS_OPERATING_NAME = "businessOperatingName";
+ String BUSINESS_TYPE = "businessType";
+ String CITY = "city";
+ String COUNTRY = "country";
+ String COUNTRY_OF_BIRTH = "countryOfBirth";
+ String COUNTRY_OF_NATIONALITY = "countryOfNationality";
+ String DATE_OF_BIRTH = "dateOfBirth";
+ String DRIVERS_LICENSE_ID = "driversLicenseId";
+ String EMAIL = "email";
+ String EMPLOYER_ID = "employerId";
+ String FIRST_NAME = "firstName";
+ String GENDER = "gender";
+ String GOVERNMENT_ID = "governmentId";
+ String GOVERNMENT_ID_TYPE = "governmentIdType";
+ String LANGUAGE = "language";
+ String LAST_NAME = "lastName";
+ String MIDDLE_NAME = "middleName";
+ String MOBILE_NUMBER = "mobileNumber";
+ String PASSPORT_ID = "passportId";
+ String PHONE_NUMBER = "phoneNumber";
+ String POSTAL_CODE = "postalCode";
+ String PROFILE_TYPE = "profileType";
+ String PROGRAM_TOKEN = "programToken";
+ String STATE_PROVINCE = "stateProvince";
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @StringDef({
+ UserFields.TOKEN,
+ UserFields.STATUS,
+ UserFields.VERIFICATION_STATUS,
+ UserFields.CREATED_ON,
+ UserFields.CLIENT_USER_ID,
+ UserFields.ADDRESS_LINE_1,
+ UserFields.ADDRESS_LINE_2,
+ UserFields.BUSINESS_CONTACT_ROLE,
+ UserFields.BUSINESS_NAME,
+ UserFields.BUSINESS_REGISTRATION_COUNTRY,
+ UserFields.BUSINESS_REGISTRATION_ID,
+ UserFields.BUSINESS_REGISTRATION_STATE_PROVINCE,
+ UserFields.BUSINESS_CONTACT_ADDRESS_LINE_1,
+ UserFields.BUSINESS_CONTACT_ADDRESS_LINE_2,
+ UserFields.BUSINESS_CONTACT_CITY,
+ UserFields.BUSINESS_CONTACT_STATE_PROVINCE,
+ UserFields.BUSINESS_CONTACT_COUNTRY,
+ UserFields.BUSINESS_CONTACT_POSTAL_CODE,
+ UserFields.BUSINESS_OPERATING_NAME,
+ UserFields.BUSINESS_TYPE,
+ UserFields.CITY,
+ UserFields.COUNTRY,
+ UserFields.COUNTRY_OF_BIRTH,
+ UserFields.COUNTRY_OF_NATIONALITY,
+ UserFields.DATE_OF_BIRTH,
+ UserFields.DRIVERS_LICENSE_ID,
+ UserFields.EMAIL,
+ UserFields.EMPLOYER_ID,
+ UserFields.FIRST_NAME,
+ UserFields.GENDER,
+ UserFields.GOVERNMENT_ID,
+ UserFields.GOVERNMENT_ID_TYPE,
+ UserFields.LANGUAGE,
+ UserFields.LAST_NAME,
+ UserFields.MIDDLE_NAME,
+ UserFields.MOBILE_NUMBER,
+ UserFields.PASSPORT_ID,
+ UserFields.PHONE_NUMBER,
+ UserFields.POSTAL_CODE,
+ UserFields.PROFILE_TYPE,
+ UserFields.PROGRAM_TOKEN,
+ UserFields.STATE_PROVINCE
+ })
+ public @interface UserField {
+ }
+
+ private Map mFields;
+
+ public HyperwalletUser(@NonNull JSONObject jsonObject) throws JSONException {
+ toMap(jsonObject);
+ }
+
+ public HyperwalletUser(@NonNull Map fields) {
+ super();
+ setFields(fields);
+ }
+
+ /**
+ * Converts a {@code Map} to a {@link JSONObject}
+ *
+ * @return a {@link JSONObject}
+ */
+ @Override
+ @NonNull
+ public JSONObject toJsonObject() throws JSONException {
+ return JsonUtils.mapToJsonObject(mFields);
+ }
+
+ /**
+ * Invokes {@link #toJsonObject()} and converts {@link JSONObject} to a String
+ *
+ * @return String of the {@link JSONObject}
+ * @throws JSONException if any errors will occurred during json parsing
+ */
+ @NonNull
+ @Override
+ public String toJsonString() throws JSONException {
+ return toJsonObject().toString();
+ }
+
+ /**
+ * Convert a json String to a {@code Map}
+ *
+ * @param jsonObject is a response from Rest API in {@link String} format
+ */
+ private void toMap(@NonNull JSONObject jsonObject) throws JSONException {
+ mFields = JsonUtils.jsonObjectToMap(jsonObject);
+ }
+
+ /**
+ * Returns a {@link String} value of a {@code Map}
+ *
+ * Please use {@code getField(@NonNull String key, @NonNull Class clazz)} if the value is not a {@link String}
+ *
+ *
+ * @param key can only be a {@link String} that represents a {@link HyperwalletUser.UserField} name
+ * @return a {@link String} value that represents the value of a {@link HyperwalletField}
+ */
+ @Nullable
+ public String getField(@NonNull @UserField String key) {
+ return mFields.get(key) != null ? (String) mFields.get(key) : null;
+ }
+
+ @Nullable
+ public String getToken() {
+ return (String) mFields.get(UserFields.TOKEN);
+ }
+
+ @Nullable
+ public @UserStatus
+ String getStatus() {
+ return (String) mFields.get(UserFields.STATUS);
+ }
+
+ @Nullable
+ public @VerificationStatus
+ String getVerificationStatus() {
+ return (String) mFields.get(UserFields.VERIFICATION_STATUS);
+ }
+
+ @Nullable
+ public String getCreatedOn() {
+ return (String) mFields.get(UserFields.CREATED_ON);
+ }
+
+ @Nullable
+ public String getClientUserId() {
+ return (String) mFields.get(UserFields.CLIENT_USER_ID);
+ }
+
+ @Nullable
+ public String getAddressLine1() {
+ return (String) mFields.get(UserFields.ADDRESS_LINE_1);
+ }
+
+ @Nullable
+ public String getAddressLine2() {
+ return (String) mFields.get(UserFields.ADDRESS_LINE_2);
+ }
+
+ @Nullable
+ public @BusinessContactRole
+ String getBusinessContactRole() {
+ return (String) mFields.get(UserFields.BUSINESS_CONTACT_ROLE);
+ }
+
+ @Nullable
+ public String getBusinessName() {
+ return (String) mFields.get(UserFields.BUSINESS_NAME);
+ }
+
+ @Nullable
+ public String getBusinessRegistrationCountry() {
+ return (String) mFields.get(UserFields.BUSINESS_REGISTRATION_COUNTRY);
+ }
+
+ @Nullable
+ public String getBusinessRegistrationId() {
+ return (String) mFields.get(UserFields.BUSINESS_REGISTRATION_ID);
+ }
+
+ @Nullable
+ public String getBusinessRegistrationStateProvince() {
+ return (String) mFields.get(UserFields.BUSINESS_REGISTRATION_STATE_PROVINCE);
+ }
+
+ @Nullable
+ public String getBusinessContactAddressLine1() {
+ return (String) mFields.get(UserFields.BUSINESS_CONTACT_ADDRESS_LINE_1);
+ }
+
+ @Nullable
+ public String getBusinessContactAddressLine2() {
+ return (String) mFields.get(UserFields.BUSINESS_CONTACT_ADDRESS_LINE_2);
+ }
+
+ @Nullable
+ public String getBusinessContactCity() {
+ return (String) mFields.get(UserFields.BUSINESS_CONTACT_CITY);
+ }
+
+ @Nullable
+ public String getBusinessContactStateProvince() {
+ return (String) mFields.get(UserFields.BUSINESS_CONTACT_STATE_PROVINCE);
+ }
+
+ @Nullable
+ public String getBusinessContactCountry() {
+ return (String) mFields.get(UserFields.BUSINESS_CONTACT_COUNTRY);
+ }
+
+ @Nullable
+ public String getBusinessContactPostalCode() {
+ return (String) mFields.get(UserFields.BUSINESS_CONTACT_POSTAL_CODE);
+ }
+
+ @Nullable
+ public String getBusinessOperatingName() {
+ return (String) mFields.get(UserFields.BUSINESS_OPERATING_NAME);
+ }
+
+ @Nullable
+ public @BusinessType
+ String getBusinessType() {
+ return (String) mFields.get(UserFields.BUSINESS_TYPE);
+ }
+
+ @Nullable
+ public String getCity() {
+ return (String) mFields.get(UserFields.CITY);
+ }
+
+ @Nullable
+ public String getCountry() {
+ return (String) mFields.get(UserFields.COUNTRY);
+ }
+
+ @Nullable
+ public String getCountryOfBirth() {
+ return (String) mFields.get(UserFields.COUNTRY_OF_BIRTH);
+ }
+
+ @Nullable
+ public String getCountryOfNationality() {
+ return (String) mFields.get(UserFields.COUNTRY_OF_NATIONALITY);
+ }
+
+ @Nullable
+ public String getDateOfBirth() {
+ return (String) mFields.get(UserFields.DATE_OF_BIRTH);
+ }
+
+ @Nullable
+ public String getDriversLicenseId() {
+ return (String) mFields.get(UserFields.DRIVERS_LICENSE_ID);
+ }
+
+ @Nullable
+ public String getEmail() {
+ return (String) mFields.get(UserFields.EMAIL);
+ }
+
+ @Nullable
+ public String getEmployerId() {
+ return (String) mFields.get(UserFields.EMPLOYER_ID);
+ }
+
+ @Nullable
+ public String getFirstName() {
+ return (String) mFields.get(UserFields.FIRST_NAME);
+ }
+
+ @Nullable
+ public @Gender
+ String getGender() {
+ return (String) mFields.get(UserFields.GENDER);
+ }
+
+ @Nullable
+ public String getGovernmentId() {
+ return (String) mFields.get(UserFields.GOVERNMENT_ID);
+ }
+
+ @Nullable
+ public @GovernmentIdType
+ String getGovernmentIdType() {
+ return (String) mFields.get(UserFields.GOVERNMENT_ID_TYPE);
+ }
+
+ @Nullable
+ public String getLanguage() {
+ return (String) mFields.get(UserFields.LANGUAGE);
+ }
+
+ @Nullable
+ public String getLastName() {
+ return (String) mFields.get(UserFields.LAST_NAME);
+ }
+
+ @Nullable
+ public String getMiddleName() {
+ return (String) mFields.get(UserFields.MIDDLE_NAME);
+ }
+
+ @Nullable
+ public String getMobileNumber() {
+ return (String) mFields.get(UserFields.MOBILE_NUMBER);
+ }
+
+ @Nullable
+ public String getPassportId() {
+ return (String) mFields.get(UserFields.PASSPORT_ID);
+ }
+
+ @Nullable
+ public String getPhoneNumber() {
+ return (String) mFields.get(UserFields.PHONE_NUMBER);
+ }
+
+ @Nullable
+ public String getPostalCode() {
+ return (String) mFields.get(UserFields.POSTAL_CODE);
+ }
+
+ @Nullable
+ public @ProfileType
+ String getProfileType() {
+ return (String) mFields.get(UserFields.PROFILE_TYPE);
+ }
+
+ @Nullable
+ public String getProgramToken() {
+ return (String) mFields.get(UserFields.PROGRAM_TOKEN);
+ }
+
+ @Nullable
+ public String getStateProvince() {
+ return (String) mFields.get(UserFields.STATE_PROVINCE);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeMap(mFields);
+ }
+
+ public static final Creator CREATOR =
+ new Creator() {
+ @Override
+ public HyperwalletUser createFromParcel(Parcel source) {
+ final Map fields = new HashMap<>();
+ source.readMap(fields, this.getClass().getClassLoader());
+ return new HyperwalletUser(fields);
+ }
+
+ @Override
+ public HyperwalletUser[] newArray(int size) {
+ return new HyperwalletUser[0];
+ }
+ };
+
+ protected void setFields(@NonNull Map fields) {
+ mFields = fields;
+ }
+
+ public static class Builder {
+ private Map mFields;
+
+ public Builder() {
+ mFields = new HashMap<>();
+ }
+
+ public HyperwalletUser.Builder token(@NonNull final String token) {
+ mFields.put(UserFields.TOKEN, token);
+ return this;
+ }
+
+ public HyperwalletUser.Builder status(@Nullable @UserStatus final String status) {
+ mFields.put(UserFields.STATUS, status);
+ return this;
+ }
+
+ public HyperwalletUser.Builder verificationStatus(
+ @Nullable @VerificationStatus final String verificationStatus) {
+ mFields.put(UserFields.VERIFICATION_STATUS, verificationStatus);
+ return this;
+ }
+
+ public HyperwalletUser.Builder createdOn(@Nullable final String createdOn) {
+ mFields.put(UserFields.CREATED_ON, createdOn);
+ return this;
+ }
+
+ public HyperwalletUser.Builder clientUserId(@Nullable final String clientUserId) {
+ mFields.put(UserFields.CLIENT_USER_ID, clientUserId);
+ return this;
+ }
+
+ public HyperwalletUser.Builder addressLine1(@Nullable final String addressLine1) {
+ mFields.put(UserFields.ADDRESS_LINE_1, addressLine1);
+ return this;
+ }
+
+ public HyperwalletUser.Builder addressLine2(@Nullable final String addressLine2) {
+ mFields.put(UserFields.ADDRESS_LINE_2, addressLine2);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessContactRole(
+ @Nullable final @BusinessContactRole String businessContactRole) {
+ mFields.put(UserFields.BUSINESS_CONTACT_ROLE, businessContactRole);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessName(@Nullable final String businessName) {
+ mFields.put(UserFields.BUSINESS_NAME, businessName);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessRegistrationCountry(@Nullable final String businessRegistrationCountry) {
+ mFields.put(UserFields.BUSINESS_REGISTRATION_COUNTRY, businessRegistrationCountry);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessRegistrationId(@Nullable final String businessRegistrationId) {
+ mFields.put(UserFields.BUSINESS_REGISTRATION_ID, businessRegistrationId);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessRegistrationStateProvince(
+ @Nullable final String businessRegistrationStateProvince) {
+ mFields.put(UserFields.BUSINESS_REGISTRATION_STATE_PROVINCE, businessRegistrationStateProvince);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessContactAddressLine1(@Nullable final String businessContactAddressLine1) {
+ mFields.put(UserFields.BUSINESS_CONTACT_ADDRESS_LINE_1, businessContactAddressLine1);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessContactAddressLine2(@Nullable final String businessContactAddressLine2) {
+ mFields.put(UserFields.BUSINESS_CONTACT_ADDRESS_LINE_2, businessContactAddressLine2);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessContactCity(@Nullable final String businessContactCity) {
+ mFields.put(UserFields.BUSINESS_CONTACT_CITY, businessContactCity);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessContactStateProvince(
+ @Nullable final String businessContactStateProvince) {
+ mFields.put(UserFields.BUSINESS_CONTACT_STATE_PROVINCE, businessContactStateProvince);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessContactCountry(@Nullable final String businessContactCountry) {
+ mFields.put(UserFields.BUSINESS_CONTACT_COUNTRY, businessContactCountry);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessContactPostalCode(@Nullable final String businessContactPostalCode) {
+ mFields.put(UserFields.BUSINESS_CONTACT_POSTAL_CODE, businessContactPostalCode);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessOperatingName(@Nullable final String businessOperatingName) {
+ mFields.put(UserFields.BUSINESS_OPERATING_NAME, businessOperatingName);
+ return this;
+ }
+
+ public HyperwalletUser.Builder businessType(@Nullable @BusinessType final String businessType) {
+ mFields.put(UserFields.BUSINESS_TYPE, businessType);
+ return this;
+ }
+
+ public HyperwalletUser.Builder city(@Nullable final String city) {
+ mFields.put(UserFields.CITY, city);
+ return this;
+ }
+
+ public HyperwalletUser.Builder country(@Nullable final String country) {
+ mFields.put(UserFields.COUNTRY, country);
+ return this;
+ }
+
+ public HyperwalletUser.Builder countryOfBirth(@Nullable final String countryOfBirth) {
+ mFields.put(UserFields.COUNTRY_OF_BIRTH, countryOfBirth);
+ return this;
+ }
+
+ public HyperwalletUser.Builder countryOfNationality(@Nullable final String countryOfNationality) {
+ mFields.put(UserFields.COUNTRY_OF_NATIONALITY, countryOfNationality);
+ return this;
+ }
+
+ public HyperwalletUser.Builder dateOfBirth(@Nullable final String dateOfBirth) {
+ mFields.put(UserFields.DATE_OF_BIRTH, dateOfBirth);
+ return this;
+ }
+
+ public HyperwalletUser.Builder driversLicenseId(@Nullable final String driversLicenseId) {
+ mFields.put(UserFields.DRIVERS_LICENSE_ID, driversLicenseId);
+ return this;
+ }
+
+ public HyperwalletUser.Builder email(@Nullable final String email) {
+ mFields.put(UserFields.EMAIL, email);
+ return this;
+ }
+
+ public HyperwalletUser.Builder employerId(@Nullable final String employerId) {
+ mFields.put(UserFields.EMPLOYER_ID, employerId);
+ return this;
+ }
+
+ public HyperwalletUser.Builder firstName(@Nullable final String firstName) {
+ mFields.put(UserFields.FIRST_NAME, firstName);
+ return this;
+ }
+
+ public HyperwalletUser.Builder gender(@Nullable @Gender final String gender) {
+ mFields.put(UserFields.GENDER, gender);
+ return this;
+ }
+
+ public HyperwalletUser.Builder governmentId(@Nullable final String governmentId) {
+ mFields.put(UserFields.GOVERNMENT_ID, governmentId);
+ return this;
+ }
+
+ public HyperwalletUser.Builder governmentIdType(@Nullable @GovernmentIdType final String governmentIdType) {
+ mFields.put(UserFields.GOVERNMENT_ID_TYPE, governmentIdType);
+ return this;
+ }
+
+ public HyperwalletUser.Builder language(@Nullable final String language) {
+ mFields.put(UserFields.LANGUAGE, language);
+ return this;
+ }
+
+ public HyperwalletUser.Builder lastName(@Nullable final String lastName) {
+ mFields.put(UserFields.LAST_NAME, lastName);
+ return this;
+ }
+
+ public HyperwalletUser.Builder middleName(@Nullable final String middleName) {
+ mFields.put(UserFields.MIDDLE_NAME, middleName);
+ return this;
+ }
+
+ public HyperwalletUser.Builder mobileNumber(@Nullable final String mobileNumber) {
+ mFields.put(UserFields.MOBILE_NUMBER, mobileNumber);
+ return this;
+ }
+
+ public HyperwalletUser.Builder passportId(@Nullable final String passportId) {
+ mFields.put(UserFields.PASSPORT_ID, passportId);
+ return this;
+ }
+
+ public HyperwalletUser.Builder phoneNumber(@Nullable final String phoneNumber) {
+ mFields.put(UserFields.PHONE_NUMBER, phoneNumber);
+ return this;
+ }
+
+ public HyperwalletUser.Builder postalCode(@Nullable final String postalCode) {
+ mFields.put(UserFields.POSTAL_CODE, postalCode);
+ return this;
+ }
+
+ public HyperwalletUser.Builder profileType(@Nullable @ProfileType final String profileType) {
+ mFields.put(UserFields.PROFILE_TYPE, profileType);
+ return this;
+ }
+
+ public HyperwalletUser.Builder programToken(@Nullable final String programToken) {
+ mFields.put(UserFields.PROGRAM_TOKEN, programToken);
+ return this;
+ }
+
+ public HyperwalletUser.Builder stateProvince(@Nullable final String stateProvince) {
+ mFields.put(UserFields.STATE_PROVINCE, stateProvince);
+ return this;
+ }
+
+ public HyperwalletUser build() {
+ return new HyperwalletUser(mFields);
+ }
+ }
+}
diff --git a/core/src/main/java/com/hyperwallet/android/model/PayPalAccount.java b/core/src/main/java/com/hyperwallet/android/model/PayPalAccount.java
new file mode 100644
index 00000000..87a51e7d
--- /dev/null
+++ b/core/src/main/java/com/hyperwallet/android/model/PayPalAccount.java
@@ -0,0 +1,110 @@
+/*
+ * 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.TransferMethodFields.EMAIL;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_CURRENCY;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Represents the PayPal Account fields.
+ */
+
+public class PayPalAccount extends HyperwalletTransferMethod {
+
+ /**
+ * Constructor to build PayPal Account, based on json object
+ */
+ public PayPalAccount(@NonNull JSONObject jsonObject) throws JSONException {
+ super(jsonObject);
+ }
+
+ private PayPalAccount(@NonNull Map fields) {
+ super();
+ setFields(fields);
+ }
+
+ @Nullable
+ public String getCountry() {
+ return getField(TRANSFER_METHOD_COUNTRY);
+ }
+
+ @Nullable
+ public String getCurrency() {
+ return getField(TRANSFER_METHOD_CURRENCY);
+ }
+
+ @Nullable
+ public String getEmail() {
+ return getField(EMAIL);
+ }
+
+ public static class Builder {
+ private Map mFields;
+
+ public Builder() {
+ mFields = new HashMap<>();
+ mFields.put(TransferMethodFields.TYPE, TransferMethodTypes.PAYPAL_ACCOUNT);
+ }
+
+ public Builder(@NonNull String transferMethodCountry,
+ @NonNull String transferMethodCurrency,
+ @NonNull String email) {
+
+ mFields = new HashMap<>();
+ mFields.put(TransferMethodFields.TYPE, TransferMethodTypes.PAYPAL_ACCOUNT);
+ mFields.put(TRANSFER_METHOD_CURRENCY, transferMethodCurrency);
+ mFields.put(TRANSFER_METHOD_COUNTRY, transferMethodCountry);
+ mFields.put(TransferMethodFields.EMAIL, email);
+ }
+
+ public Builder email(String email) {
+ mFields.put(TransferMethodFields.EMAIL, email);
+ return this;
+ }
+
+ public Builder token(@NonNull String token) {
+ mFields.put(TransferMethodFields.TOKEN, token);
+ return this;
+ }
+
+ public Builder transferMethodCountry(@NonNull String transferMethodCountry) {
+ mFields.put(TRANSFER_METHOD_COUNTRY, transferMethodCountry);
+ return this;
+ }
+
+ public Builder transferMethodCurrency(@NonNull String transferMethodCurrency) {
+ mFields.put(TRANSFER_METHOD_CURRENCY, transferMethodCurrency);
+ return this;
+ }
+
+ public PayPalAccount build() {
+ return new PayPalAccount(mFields);
+ }
+ }
+}
diff --git a/core/src/main/java/com/hyperwallet/android/model/PayPalAccountPagination.java b/core/src/main/java/com/hyperwallet/android/model/PayPalAccountPagination.java
new file mode 100644
index 00000000..21861b7a
--- /dev/null
+++ b/core/src/main/java/com/hyperwallet/android/model/PayPalAccountPagination.java
@@ -0,0 +1,46 @@
+/*
+ * 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 java.util.Map;
+
+/**
+ * Represents the PayPal Account pagination fields
+ */
+public class PayPalAccountPagination extends HyperwalletTransferMethodPagination {
+
+ /**
+ * Constructs the default implementation of the PayPal Account pagination.
+ */
+ public PayPalAccountPagination() {
+ 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 PayPalAccountPagination(Map urlQueryMap) {
+ super(urlQueryMap);
+ setType(PAYPAL_ACCOUNT);
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java
index 27b1182e..3a753994 100644
--- a/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java
+++ b/core/src/test/java/com/hyperwallet/android/HyperwalletTestSuite.java
@@ -3,16 +3,22 @@
import com.hyperwallet.android.model.meta.HyperwalletRetrieveTransferMethodConfigurationFieldsTest;
import com.hyperwallet.android.transfermethod.HyperwalletCreateBankAccountTest;
import com.hyperwallet.android.transfermethod.HyperwalletCreateBankCardTest;
+import com.hyperwallet.android.transfermethod.HyperwalletCreatePayPalAccountTest;
import com.hyperwallet.android.transfermethod.HyperwalletDeactivateBankAccountTest;
import com.hyperwallet.android.transfermethod.HyperwalletDeactivateBankCardTest;
+import com.hyperwallet.android.transfermethod.HyperwalletDeactivatePayPalAccountTest;
import com.hyperwallet.android.transfermethod.HyperwalletGetBankAccountTest;
import com.hyperwallet.android.transfermethod.HyperwalletGetBankCardTest;
+import com.hyperwallet.android.transfermethod.HyperwalletGetPayPalTest;
+import com.hyperwallet.android.transfermethod.HyperwalletGetUserTest;
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;
import com.hyperwallet.android.transfermethod.HyperwalletUpdateBankCardTest;
+import com.hyperwallet.android.transfermethod.HyperwalletUpdatePayPalAccountTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -23,16 +29,22 @@
HyperwalletCreateBankAccountTest.class,
HyperwalletListBankAccountsTest.class,
HyperwalletCreateBankCardTest.class,
+ HyperwalletCreatePayPalAccountTest.class,
HyperwalletGetBankAccountTest.class,
HyperwalletGetBankCardTest.class,
+ HyperwalletGetPayPalTest.class,
+ HyperwalletGetUserTest.class,
HyperwalletUpdateBankAccountTest.class,
HyperwalletUpdateBankCardTest.class,
+ HyperwalletUpdatePayPalAccountTest.class,
HyperwalletDeactivateBankAccountTest.class,
HyperwalletDeactivateBankCardTest.class,
+ HyperwalletDeactivatePayPalAccountTest.class,
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/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
new file mode 100644
index 00000000..514f865c
--- /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("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"));
+ 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/model/HyperwalletUserTest.java b/core/src/test/java/com/hyperwallet/android/model/HyperwalletUserTest.java
new file mode 100644
index 00000000..9a5cc12f
--- /dev/null
+++ b/core/src/test/java/com/hyperwallet/android/model/HyperwalletUserTest.java
@@ -0,0 +1,346 @@
+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 org.hamcrest.Matchers.notNullValue;
+
+import static com.hyperwallet.android.model.HyperwalletUser.BusinessContactRoles.DIRECTOR;
+import static com.hyperwallet.android.model.HyperwalletUser.BusinessContactRoles.OWNER;
+import static com.hyperwallet.android.model.HyperwalletUser.BusinessTypes.CORPORATION;
+import static com.hyperwallet.android.model.HyperwalletUser.Genders.MALE;
+import static com.hyperwallet.android.model.HyperwalletUser.GovernmentIdTypes.PASSPORT;
+import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.ADDRESS_LINE_1;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.ADDRESS_LINE_2;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_CONTACT_ADDRESS_LINE_1;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_CONTACT_ADDRESS_LINE_2;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_CONTACT_CITY;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_CONTACT_COUNTRY;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_CONTACT_POSTAL_CODE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_CONTACT_ROLE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_CONTACT_STATE_PROVINCE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_NAME;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_OPERATING_NAME;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_REGISTRATION_COUNTRY;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_REGISTRATION_ID;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_REGISTRATION_STATE_PROVINCE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.BUSINESS_TYPE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CITY;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CLIENT_USER_ID;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.COUNTRY;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.COUNTRY_OF_BIRTH;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.COUNTRY_OF_NATIONALITY;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CREATED_ON;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.DATE_OF_BIRTH;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.DRIVERS_LICENSE_ID;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.EMAIL;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.EMPLOYER_ID;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.FIRST_NAME;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.GENDER;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.GOVERNMENT_ID;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.GOVERNMENT_ID_TYPE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.LANGUAGE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.LAST_NAME;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.MIDDLE_NAME;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.MOBILE_NUMBER;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.PASSPORT_ID;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.PHONE_NUMBER;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.POSTAL_CODE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.PROFILE_TYPE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.PROGRAM_TOKEN;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.STATE_PROVINCE;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.STATUS;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.TOKEN;
+import static com.hyperwallet.android.model.HyperwalletUser.UserFields.VERIFICATION_STATUS;
+import static com.hyperwallet.android.model.HyperwalletUser.UserStatuses.LOCKED;
+import static com.hyperwallet.android.model.HyperwalletUser.VerificationStatuses.UNDER_REVIEW;
+import static com.hyperwallet.android.util.JsonUtils.fromJsonString;
+
+import android.os.Parcel;
+
+import com.hyperwallet.android.rule.HyperwalletExternalResourceManager;
+
+import org.json.JSONObject;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class HyperwalletUserTest {
+ @Rule
+ public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager();
+
+ @Test
+ public void testFromJsonString_userResponse() throws Exception {
+ HyperwalletUser actualUser = fromJsonString(
+ mExternalResourceManager.getResourceContent("user_response_all_fields.json"),
+ new TypeReference() {
+ });
+
+ assertThat(actualUser, is(notNullValue()));
+ assertThat(actualUser.getField(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5"));
+ assertThat(actualUser.getField(STATUS), is("PRE_ACTIVATED"));
+ assertThat(actualUser.getField(VERIFICATION_STATUS), is("NOT_REQUIRED"));
+ assertThat(actualUser.getField(CREATED_ON), is("2017-10-30T22:15:45"));
+ assertThat(actualUser.getField(CLIENT_USER_ID), is("123345789"));
+ assertThat(actualUser.getField(PROFILE_TYPE), is("INDIVIDUAL"));
+ assertThat(actualUser.getField(FIRST_NAME), is("Some"));
+ assertThat(actualUser.getField(MIDDLE_NAME), is("Nice"));
+ assertThat(actualUser.getField(LAST_NAME), is("Guy"));
+ assertThat(actualUser.getField(DATE_OF_BIRTH), is("1991-01-01"));
+ assertThat(actualUser.getField(GENDER), is(nullValue()));
+ assertThat(actualUser.getField(COUNTRY_OF_BIRTH), is("US"));
+ assertThat(actualUser.getField(COUNTRY_OF_NATIONALITY), is("US"));
+ assertThat(actualUser.getField(EMAIL), is("someguy@hyperwallet.com"));
+ assertThat(actualUser.getField(PHONE_NUMBER), is("+1 604 777888"));
+ assertThat(actualUser.getField(MOBILE_NUMBER), is("+1 604 123456"));
+ assertThat(actualUser.getField(GOVERNMENT_ID), is("123456789"));
+ assertThat(actualUser.getField(GOVERNMENT_ID_TYPE), is(PASSPORT));
+ assertThat(actualUser.getField(PASSPORT_ID), is("ABC-12345"));
+ assertThat(actualUser.getField(DRIVERS_LICENSE_ID), is("7788899"));
+ assertThat(actualUser.getField(ADDRESS_LINE_1), is("575 Market Street"));
+ assertThat(actualUser.getField(ADDRESS_LINE_2), is("Unit 2"));
+ assertThat(actualUser.getField(CITY), is("San Francisco"));
+ assertThat(actualUser.getField(STATE_PROVINCE), is("CA"));
+ assertThat(actualUser.getField(COUNTRY), is("US"));
+ assertThat(actualUser.getField(POSTAL_CODE), is("94105"));
+ assertThat(actualUser.getField(EMPLOYER_ID), is("7778889"));
+ assertThat(actualUser.getField(BUSINESS_CONTACT_ROLE), is(DIRECTOR));
+ assertThat(actualUser.getField(BUSINESS_NAME), is("Hyperwallet"));
+ assertThat(actualUser.getField(BUSINESS_REGISTRATION_COUNTRY), is("US"));
+ assertThat(actualUser.getField(BUSINESS_REGISTRATION_ID), is("ABC-1234"));
+ assertThat(actualUser.getField(BUSINESS_REGISTRATION_STATE_PROVINCE), is("CA"));
+ assertThat(actualUser.getField(BUSINESS_CONTACT_ADDRESS_LINE_1), is("123 Townsend St."));
+ assertThat(actualUser.getField(BUSINESS_CONTACT_ADDRESS_LINE_2), is("Sixth Floor"));
+ assertThat(actualUser.getField(BUSINESS_CONTACT_CITY), is("San Francisco"));
+ assertThat(actualUser.getField(BUSINESS_CONTACT_STATE_PROVINCE), is("CA"));
+ assertThat(actualUser.getField(BUSINESS_CONTACT_COUNTRY), is("US"));
+ assertThat(actualUser.getField(BUSINESS_CONTACT_POSTAL_CODE), is("94107"));
+ assertThat(actualUser.getField(BUSINESS_OPERATING_NAME), is("Hyperwallet"));
+ assertThat(actualUser.getField(BUSINESS_TYPE), is("CORPORATION"));
+ assertThat(actualUser.getField(LANGUAGE), is("en"));
+ assertThat(actualUser.getField(PROGRAM_TOKEN), is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c"));
+
+ }
+
+ @Test
+ public void testToJsonObject_user() throws Exception {
+
+ final HyperwalletUser expectedUser = new HyperwalletUser.Builder()
+ .token("usr-f9154016-94e8-4686-a840-075688ac07b5")
+ .status(LOCKED)
+ .verificationStatus(UNDER_REVIEW)
+ .createdOn("2017-10-30T22:15:45")
+ .clientUserId("123345789")
+ .addressLine1("575 Market Street")
+ .addressLine2("247 Tottenham Court Rd")
+ .businessContactRole(OWNER)
+ .businessName("My Company")
+ .businessRegistrationCountry("CA")
+ .businessRegistrationId("werqq")
+ .businessRegistrationStateProvince("BC")
+ .businessContactAddressLine1("34 Zoo pl")
+ .businessContactAddressLine2("102 Park ave")
+ .businessContactCity("Zippy")
+ .businessContactStateProvince("Quebec")
+ .businessContactCountry("CA")
+ .businessContactPostalCode("QC H2Y 2E2")
+ .businessOperatingName("OP name")
+ .businessType(CORPORATION)
+ .city("Montréal")
+ .country("CA")
+ .countryOfBirth("US")
+ .countryOfNationality("CA")
+ .dateOfBirth("1991-03-09")
+ .driversLicenseId("ID-45dff")
+ .email("someguy@hyperwallet.com")
+ .employerId("34333")
+ .firstName("Jany")
+ .gender(MALE)
+ .governmentId("CA-MO-12")
+ .governmentIdType(PASSPORT)
+ .language("fr")
+ .lastName("Smith")
+ .middleName("de")
+ .mobileNumber("+1514-496-7678")
+ .passportId("AV54467")
+ .phoneNumber("496-7678")
+ .postalCode("94105")
+ .profileType(INDIVIDUAL)
+ .programToken("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")
+ .stateProvince("BC")
+ .build();
+
+ JSONObject jsonObject = expectedUser.toJsonObject();
+
+ assertThat(jsonObject.getString(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5"));
+ assertThat(jsonObject.getString(STATUS), is(LOCKED));
+ assertThat(jsonObject.getString(VERIFICATION_STATUS), is(UNDER_REVIEW));
+ assertThat(jsonObject.getString(CREATED_ON), is("2017-10-30T22:15:45"));
+ assertThat(jsonObject.getString(CLIENT_USER_ID), is("123345789"));
+ assertThat(jsonObject.getString(ADDRESS_LINE_1), is("575 Market Street"));
+ assertThat(jsonObject.getString(ADDRESS_LINE_2), is("247 Tottenham Court Rd"));
+ assertThat(jsonObject.getString(BUSINESS_CONTACT_ROLE), is(OWNER));
+ assertThat(jsonObject.getString(BUSINESS_NAME), is("My Company"));
+ assertThat(jsonObject.getString(BUSINESS_REGISTRATION_COUNTRY), is("CA"));
+ assertThat(jsonObject.getString(BUSINESS_REGISTRATION_ID), is("werqq"));
+ assertThat(jsonObject.getString(BUSINESS_REGISTRATION_STATE_PROVINCE), is("BC"));
+ assertThat(jsonObject.getString(BUSINESS_CONTACT_ADDRESS_LINE_1), is("34 Zoo pl"));
+ assertThat(jsonObject.getString(BUSINESS_CONTACT_ADDRESS_LINE_2), is("102 Park ave"));
+ assertThat(jsonObject.getString(BUSINESS_CONTACT_CITY), is("Zippy"));
+ assertThat(jsonObject.getString(BUSINESS_CONTACT_STATE_PROVINCE), is("Quebec"));
+ assertThat(jsonObject.getString(BUSINESS_CONTACT_COUNTRY), is("CA"));
+ assertThat(jsonObject.getString(BUSINESS_CONTACT_POSTAL_CODE), is("QC H2Y 2E2"));
+ assertThat(jsonObject.getString(BUSINESS_OPERATING_NAME), is("OP name"));
+ assertThat(jsonObject.getString(BUSINESS_TYPE), is(CORPORATION));
+ assertThat(jsonObject.getString(CITY), is("Montréal"));
+ assertThat(jsonObject.getString(COUNTRY), is("CA"));
+ assertThat(jsonObject.getString(COUNTRY_OF_BIRTH), is("US"));
+ assertThat(jsonObject.getString(COUNTRY_OF_NATIONALITY), is("CA"));
+ assertThat(jsonObject.getString(DATE_OF_BIRTH), is("1991-03-09"));
+ assertThat(jsonObject.getString(DRIVERS_LICENSE_ID), is("ID-45dff"));
+ assertThat(jsonObject.getString(EMAIL), is("someguy@hyperwallet.com"));
+ assertThat(jsonObject.getString(EMPLOYER_ID), is("34333"));
+ assertThat(jsonObject.getString(FIRST_NAME), is("Jany"));
+ assertThat(jsonObject.getString(GENDER), is(MALE));
+ assertThat(jsonObject.getString(GOVERNMENT_ID), is("CA-MO-12"));
+ assertThat(jsonObject.getString(GOVERNMENT_ID_TYPE), is(PASSPORT));
+ assertThat(jsonObject.getString(LANGUAGE), is("fr"));
+ assertThat(jsonObject.getString(LAST_NAME), is("Smith"));
+ assertThat(jsonObject.getString(MIDDLE_NAME), is("de"));
+ assertThat(jsonObject.getString(MOBILE_NUMBER), is("+1514-496-7678"));
+ assertThat(jsonObject.getString(PASSPORT_ID), is("AV54467"));
+ assertThat(jsonObject.getString(PHONE_NUMBER), is("496-7678"));
+ assertThat(jsonObject.getString(POSTAL_CODE), is("94105"));
+ assertThat(jsonObject.getString(PROFILE_TYPE), is(INDIVIDUAL));
+ assertThat(jsonObject.getString(PROGRAM_TOKEN), is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c"));
+ assertThat(jsonObject.getString(STATE_PROVINCE), is("BC"));
+ }
+
+
+ @Test
+ public void testHyperwalletUser_isParcelable() throws Exception {
+
+ String json = mExternalResourceManager.getResourceContent("user_response_all_fields.json");
+
+ HyperwalletUser user = fromJsonString(json, new TypeReference() {
+ });
+
+ Parcel parcel = Parcel.obtain();
+ user.writeToParcel(parcel, user.describeContents());
+ parcel.setDataPosition(0);
+ HyperwalletUser bundledUser = HyperwalletUser.CREATOR.createFromParcel(parcel);
+
+ assertThat(bundledUser, is(notNullValue()));
+ assertThat(bundledUser.getToken(), is("usr-f9154016-94e8-4686-a840-075688ac07b5"));
+ assertThat(bundledUser.getStatus(), is("PRE_ACTIVATED"));
+ assertThat(bundledUser.getVerificationStatus(), is("NOT_REQUIRED"));
+ assertThat(bundledUser.getCreatedOn(), is("2017-10-30T22:15:45"));
+ assertThat(bundledUser.getClientUserId(), is("123345789"));
+ assertThat(bundledUser.getProfileType(), is("INDIVIDUAL"));
+ assertThat(bundledUser.getFirstName(), is("Some"));
+ assertThat(bundledUser.getLastName(), is("Guy"));
+ assertThat(bundledUser.getDateOfBirth(), is("1991-01-01"));
+ assertThat(bundledUser.getEmail(), is("someguy@hyperwallet.com"));
+ assertThat(bundledUser.getAddressLine1(), is("575 Market Street"));
+ assertThat(bundledUser.getCity(), is("San Francisco"));
+ assertThat(bundledUser.getStateProvince(), is("CA"));
+ assertThat(bundledUser.getCountry(), is("US"));
+ assertThat(bundledUser.getPostalCode(), is("94105"));
+ assertThat(bundledUser.getLanguage(), is("en"));
+ assertThat(bundledUser.getProgramToken(), is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c"));
+ }
+
+ @Test
+ public void testHyperwalletUser_fieldsAccessors() {
+ final HyperwalletUser expectedUser = new HyperwalletUser.Builder()
+ .token("usr-f9154016-94e8-4686-a840-075688ac07b5")
+ .status(LOCKED)
+ .verificationStatus(UNDER_REVIEW)
+ .createdOn("2017-10-30T22:15:45")
+ .clientUserId("123345789")
+ .addressLine1("575 Market Street")
+ .addressLine2("247 Tottenham Court Rd")
+ .businessContactRole(OWNER)
+ .businessName("My Company")
+ .businessRegistrationCountry("CA")
+ .businessRegistrationId("werqq")
+ .businessRegistrationStateProvince("BC")
+ .businessContactAddressLine1("34 Zoo pl")
+ .businessContactAddressLine2("102 Park ave")
+ .businessContactCity("Zippy")
+ .businessContactStateProvince("Quebec")
+ .businessContactCountry("CA")
+ .businessContactPostalCode("QC H2Y 2E2")
+ .businessOperatingName("OP name")
+ .businessType(CORPORATION)
+ .city("Montréal")
+ .country("CA")
+ .countryOfBirth("US")
+ .countryOfNationality("CA")
+ .dateOfBirth("1991-03-09")
+ .driversLicenseId("ID-45dff")
+ .email("someguy@hyperwallet.com")
+ .employerId("34333")
+ .firstName("Jany")
+ .gender(MALE)
+ .governmentId("CA-MO-12")
+ .governmentIdType(PASSPORT)
+ .language("fr")
+ .lastName("Smith")
+ .middleName("de")
+ .mobileNumber("+1514-496-7678")
+ .passportId("AV54467")
+ .phoneNumber("496-7678")
+ .postalCode("94105")
+ .profileType(INDIVIDUAL)
+ .programToken("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")
+ .stateProvince("BC")
+ .build();
+
+ assertThat(expectedUser.getToken(), is("usr-f9154016-94e8-4686-a840-075688ac07b5"));
+ assertThat(expectedUser.getStatus(), is(LOCKED));
+ assertThat(expectedUser.getVerificationStatus(), is(UNDER_REVIEW));
+ assertThat(expectedUser.getCreatedOn(), is("2017-10-30T22:15:45"));
+ assertThat(expectedUser.getClientUserId(), is("123345789"));
+ assertThat(expectedUser.getAddressLine1(), is("575 Market Street"));
+ assertThat(expectedUser.getAddressLine2(), is("247 Tottenham Court Rd"));
+ assertThat(expectedUser.getBusinessContactRole(), is(OWNER));
+ assertThat(expectedUser.getBusinessName(), is("My Company"));
+ assertThat(expectedUser.getBusinessRegistrationCountry(), is("CA"));
+ assertThat(expectedUser.getBusinessRegistrationId(), is("werqq"));
+ assertThat(expectedUser.getBusinessRegistrationStateProvince(), is("BC"));
+ assertThat(expectedUser.getBusinessContactAddressLine1(), is("34 Zoo pl"));
+ assertThat(expectedUser.getBusinessContactAddressLine2(), is("102 Park ave"));
+ assertThat(expectedUser.getBusinessContactCity(), is("Zippy"));
+ assertThat(expectedUser.getBusinessContactStateProvince(), is("Quebec"));
+ assertThat(expectedUser.getBusinessContactCountry(), is("CA"));
+ assertThat(expectedUser.getBusinessContactPostalCode(), is("QC H2Y 2E2"));
+ assertThat(expectedUser.getBusinessOperatingName(), is("OP name"));
+ assertThat(expectedUser.getBusinessType(), is(CORPORATION));
+ assertThat(expectedUser.getCity(), is("Montréal"));
+ assertThat(expectedUser.getCountry(), is("CA"));
+ assertThat(expectedUser.getCountryOfBirth(), is("US"));
+ assertThat(expectedUser.getCountryOfNationality(), is("CA"));
+ assertThat(expectedUser.getDateOfBirth(), is("1991-03-09"));
+ assertThat(expectedUser.getDriversLicenseId(), is("ID-45dff"));
+ assertThat(expectedUser.getEmail(), is("someguy@hyperwallet.com"));
+ assertThat(expectedUser.getEmployerId(), is("34333"));
+ assertThat(expectedUser.getFirstName(), is("Jany"));
+ assertThat(expectedUser.getGender(), is(MALE));
+ assertThat(expectedUser.getGovernmentId(), is("CA-MO-12"));
+ assertThat(expectedUser.getGovernmentIdType(), is(PASSPORT));
+ assertThat(expectedUser.getLanguage(), is("fr"));
+ assertThat(expectedUser.getLastName(), is("Smith"));
+ assertThat(expectedUser.getMiddleName(), is("de"));
+ assertThat(expectedUser.getMobileNumber(), is("+1514-496-7678"));
+ assertThat(expectedUser.getPassportId(), is("AV54467"));
+ assertThat(expectedUser.getPhoneNumber(), is("496-7678"));
+ assertThat(expectedUser.getPostalCode(), is("94105"));
+ assertThat(expectedUser.getProfileType(), is(INDIVIDUAL));
+ assertThat(expectedUser.getProgramToken(), is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c"));
+ assertThat(expectedUser.getStateProvince(), is("BC"));
+ }
+}
diff --git a/core/src/test/java/com/hyperwallet/android/model/PayPalAccountTest.java b/core/src/test/java/com/hyperwallet/android/model/PayPalAccountTest.java
new file mode 100644
index 00000000..44170b3c
--- /dev/null
+++ b/core/src/test/java/com/hyperwallet/android/model/PayPalAccountTest.java
@@ -0,0 +1,65 @@
+package com.hyperwallet.android.model;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+
+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 static com.hyperwallet.android.util.JsonUtils.fromJsonString;
+
+import com.hyperwallet.android.rule.HyperwalletExternalResourceManager;
+
+import org.json.JSONObject;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class PayPalAccountTest {
+ @Rule
+ public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager();
+
+ @Test
+ public void testFromJsonString_payPalAccountResponse() throws Exception {
+ PayPalAccount actualPayPalAccount = fromJsonString(
+ mExternalResourceManager.getResourceContent("paypal_account_response.json"),
+ new TypeReference() {
+ });
+
+ assertThat(actualPayPalAccount, is(notNullValue()));
+ assertThat(actualPayPalAccount.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"));
+ assertThat(actualPayPalAccount.getCountry(), is("US"));
+ assertThat(actualPayPalAccount.getCurrency(), is("USD"));
+ assertThat(actualPayPalAccount.getField(TYPE), is(PAYPAL_ACCOUNT));
+ assertThat(actualPayPalAccount.getField(CREATED_ON), is("2019-01-09T22:50:14"));
+ assertThat(actualPayPalAccount.getEmail(), is("jsmith@paypal.com"));
+ assertThat(actualPayPalAccount.getField(STATUS), is("ACTIVATED"));
+ }
+
+ @Test
+ public void testToJsonObject_payPalAccount() throws Exception {
+
+ final PayPalAccount payPalAccount = new PayPalAccount.Builder()
+ .transferMethodCountry("US")
+ .transferMethodCurrency("USD")
+ .email("jsmith@paypal.com")
+ .token("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b")
+ .build();
+
+ JSONObject jsonObject = payPalAccount.toJsonObject();
+
+ assertThat(jsonObject.getString(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"));
+ assertThat(jsonObject.getString(TRANSFER_METHOD_COUNTRY), is("US"));
+ assertThat(jsonObject.getString(TRANSFER_METHOD_CURRENCY), is("USD"));
+ assertThat(jsonObject.getString(TYPE), is(PAYPAL_ACCOUNT));
+ assertThat(jsonObject.getString(EMAIL), is("jsmith@paypal.com"));
+ }
+}
diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletCreatePayPalAccountTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletCreatePayPalAccountTest.java
new file mode 100644
index 00000000..1bd23bda
--- /dev/null
+++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletCreatePayPalAccountTest.java
@@ -0,0 +1,135 @@
+package com.hyperwallet.android.transfermethod;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import static com.hyperwallet.android.model.HyperwalletStatusTransition.StatusDefinition.ACTIVATED;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.CREATED_ON;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.EMAIL;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.STATUS;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TOKEN;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_CURRENCY;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TYPE;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;
+
+import com.hyperwallet.android.Hyperwallet;
+import com.hyperwallet.android.exception.HyperwalletException;
+import com.hyperwallet.android.listener.HyperwalletListener;
+import com.hyperwallet.android.model.HyperwalletError;
+import com.hyperwallet.android.model.HyperwalletErrors;
+import com.hyperwallet.android.model.PayPalAccount;
+import com.hyperwallet.android.rule.HyperwalletExternalResourceManager;
+import com.hyperwallet.android.rule.HyperwalletMockWebServer;
+import com.hyperwallet.android.rule.HyperwalletSdkMock;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+
+import java.net.HttpURLConnection;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.mockwebserver.RecordedRequest;
+
+@RunWith(RobolectricTestRunner.class)
+public class HyperwalletCreatePayPalAccountTest {
+ @Rule
+ public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer();
+ @Rule
+ public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer);
+ @Rule
+ public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager();
+ @Rule
+ public MockitoRule mMockito = MockitoJUnit.rule();
+
+ @Mock
+ private HyperwalletListener mListener;
+
+ @Captor
+ private ArgumentCaptor mPayPalAccountCaptor;
+ @Captor
+ private ArgumentCaptor mExceptionCaptor;
+
+ private final CountDownLatch mAwait = new CountDownLatch(1);
+
+ @Test
+ public void testCreatePayPalAccount_withSuccess() throws InterruptedException {
+
+ String responseBody = mExternalResourceManager.getResourceContent("paypal_account_response.json");
+ mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_CREATED).withBody(responseBody).mock();
+
+ final PayPalAccount payPalAccount = new PayPalAccount
+ .Builder("US", "USD", "jsmith@paypal.com")
+ .build();
+
+ assertThat(payPalAccount.getField(TRANSFER_METHOD_COUNTRY), is("US"));
+ assertThat(payPalAccount.getField(TRANSFER_METHOD_CURRENCY), is("USD"));
+ assertThat(payPalAccount.getField(EMAIL), is("jsmith@paypal.com"));
+
+ Hyperwallet.getDefault().createPayPalAccount(payPalAccount, mListener);
+ mAwait.await(50, TimeUnit.MILLISECONDS);
+
+ RecordedRequest recordedRequest = mServer.getRequest();
+ verify(mListener).onSuccess(mPayPalAccountCaptor.capture());
+ verify(mListener, never()).onFailure(any(HyperwalletException.class));
+
+ PayPalAccount paypalAccountResponse = mPayPalAccountCaptor.getValue();
+ assertThat(paypalAccountResponse, is(notNullValue()));
+
+ //paypal account info
+ assertThat(recordedRequest.getPath(),
+ is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts"));
+
+ assertThat(paypalAccountResponse.getField(STATUS), is(ACTIVATED));
+ assertThat(paypalAccountResponse.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"));
+ assertThat(paypalAccountResponse.getField(TRANSFER_METHOD_COUNTRY), is("US"));
+ assertThat(paypalAccountResponse.getField(TRANSFER_METHOD_CURRENCY), is("USD"));
+ assertThat(paypalAccountResponse.getField(TYPE), is(PAYPAL_ACCOUNT));
+ assertThat(paypalAccountResponse.getField(CREATED_ON), is(notNullValue()));
+ assertThat(paypalAccountResponse.getField(EMAIL), is("jsmith@paypal.com"));
+ }
+
+ @Test
+ public void testCreatePayPalAccount_withValidationError() throws InterruptedException {
+ String responseBody = mExternalResourceManager.getResourceContentError("transfer_method_error_response.json");
+ mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock();
+
+ final PayPalAccount payPalAccount = new PayPalAccount
+ .Builder("", "USD", "jsmith@paypal.com")
+ .build();
+
+ Hyperwallet.getDefault().createPayPalAccount(payPalAccount, mListener);
+ mAwait.await(50, TimeUnit.MILLISECONDS);
+
+ RecordedRequest recordedRequest = mServer.getRequest();
+ verify(mListener, never()).onSuccess(any(PayPalAccount.class));
+ verify(mListener).onFailure(mExceptionCaptor.capture());
+
+ HyperwalletException hyperwalletException = mExceptionCaptor.getValue();
+ assertThat(hyperwalletException, is(notNullValue()));
+
+ assertThat(recordedRequest.getPath(),
+ is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts"));
+
+ HyperwalletErrors hyperwalletErrors = hyperwalletException.getHyperwalletErrors();
+ assertThat(hyperwalletErrors.getErrors(), hasSize(1));
+
+ HyperwalletError hyperwalletError = hyperwalletErrors.getErrors().get(0);
+ assertThat(hyperwalletError.getCode(), is("CONSTRAINT_VIOLATIONS"));
+ assertThat(hyperwalletError.getFieldName(), is("transferMethodCountry"));
+ assertThat(hyperwalletError.getMessage(), is("You must provide a value for this field"));
+ }
+}
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/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)."));
+
+ }
+}
diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetUserTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetUserTest.java
new file mode 100644
index 00000000..c0468ad7
--- /dev/null
+++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetUserTest.java
@@ -0,0 +1,146 @@
+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.util.HttpMethod.GET;
+
+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.HyperwalletUser;
+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 HyperwalletGetUserTest {
+ private static final long AWAIT_TIMEOUT_MILLIS = 100l;
+ @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 mUserArgumentCaptor;
+ @Captor
+ private ArgumentCaptor mExceptionCaptor;
+
+ private CountDownLatch mAwait = new CountDownLatch(1);
+
+ @Test
+ public void testGetUser_returnsUser() throws InterruptedException {
+ String responseBody = mExternalResourceManager.getResourceContent("user_response.json");
+ mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_OK).withBody(responseBody).mock();
+
+ Hyperwallet.getDefault().getUser(mListener);
+ mAwait.await(AWAIT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
+
+ RecordedRequest recordedRequest = mServer.getRequest();
+ assertThat(recordedRequest.getPath(),
+ is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7"));
+ assertThat(recordedRequest.getMethod(), is(GET.name()));
+
+ verify(mListener).onSuccess(mUserArgumentCaptor.capture());
+ verify(mListener, never()).onFailure(any(HyperwalletException.class));
+
+ HyperwalletUser userResponse = mUserArgumentCaptor.getValue();
+ assertThat(userResponse, is(notNullValue()));
+ assertThat(userResponse.getToken(), is("usr-f9154016-94e8-4686-a840-075688ac07b5"));
+ assertThat(userResponse.getStatus(), is("PRE_ACTIVATED"));
+ assertThat(userResponse.getVerificationStatus(), is("NOT_REQUIRED"));
+ assertThat(userResponse.getCreatedOn(), is("2017-10-30T22:15:45"));
+ assertThat(userResponse.getClientUserId(), is("123345789"));
+ assertThat(userResponse.getProfileType(), is("INDIVIDUAL"));
+ assertThat(userResponse.getFirstName(), is("Some"));
+ assertThat(userResponse.getLastName(), is("Guy"));
+ assertThat(userResponse.getDateOfBirth(), is("1991-01-01"));
+ assertThat(userResponse.getEmail(), is("someguy@hyperwallet.com"));
+ assertThat(userResponse.getAddressLine1(), is("575 Market Street"));
+ assertThat(userResponse.getCity(), is("San Francisco"));
+ assertThat(userResponse.getStateProvince(), is("CA"));
+ assertThat(userResponse.getCountry(), is("US"));
+ assertThat(userResponse.getPostalCode(), is("94105"));
+ assertThat(userResponse.getLanguage(), is("en"));
+ assertThat(userResponse.getProgramToken(), is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c"));
+ }
+
+ @Test
+ public void testGetUser_returnsNoUser() throws InterruptedException {
+ String responseBody = "";
+ mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_NO_CONTENT).withBody(responseBody).mock();
+
+ Hyperwallet.getDefault().getUser(mListener);
+ mAwait.await(AWAIT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
+
+ RecordedRequest recordedRequest = mServer.getRequest();
+ assertThat(recordedRequest.getPath(),
+ is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7"));
+ assertThat(recordedRequest.getMethod(), is(GET.name()));
+
+ verify(mListener).onSuccess(mUserArgumentCaptor.capture());
+ verify(mListener, never()).onFailure(any(HyperwalletException.class));
+
+ HyperwalletUser hyperwalletUser = mUserArgumentCaptor.getValue();
+ assertThat(hyperwalletUser, is(nullValue()));
+ }
+
+ @Test
+ public void testGetUser_returnsError() throws InterruptedException {
+ String responseBody = mExternalResourceManager.getResourceContentError("system_error_response.json");
+ mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock();
+
+ Hyperwallet.getDefault().getUser(mListener);
+ mAwait.await(AWAIT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
+
+ RecordedRequest recordedRequest = mServer.getRequest();
+ assertThat(recordedRequest.getPath(),
+ is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7"));
+ assertThat(recordedRequest.getMethod(), is(GET.name()));
+
+ verify(mListener, never()).onSuccess(any(HyperwalletUser.class));
+ verify(mListener).onFailure(mExceptionCaptor.capture());
+
+ HyperwalletException hyperwalletException = mExceptionCaptor.getValue();
+ assertThat(hyperwalletException, is(notNullValue()));
+ 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)."));
+ }
+}
diff --git a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListBankCardsTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListBankCardsTest.java
index 557b57bf..9453878b 100644
--- a/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListBankCardsTest.java
+++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListBankCardsTest.java
@@ -120,7 +120,7 @@ public void testListBankCards_returnsNoCards() throws InterruptedException {
@Test
public void testListBankCards_returnsError() throws InterruptedException {
- String responseBody = mExternalResourceManager.getResourceContentError("bank_cards_error_response.json");
+ String responseBody = mExternalResourceManager.getResourceContentError("system_error_response.json");
mServer.mockResponse().withHttpResponseCode(HTTP_INTERNAL_ERROR).withBody(responseBody).mock();
HyperwalletBankCardPagination actualBankCard = new HyperwalletBankCardPagination();
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..4def36f9
--- /dev/null
+++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletListPayPalAccountsTest.java
@@ -0,0 +1,179 @@
+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 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;
+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.hamcrest.Matchers;
+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> mListPayPalCaptor;
+ @Captor
+ private ArgumentCaptor mExceptionCaptor;
+
+ private CountDownLatch mAwait = new CountDownLatch(1);
+
+
+ @Test
+ public void testListPayPalAccounts_returnsActivatedAccounts() throws InterruptedException {
+
+ String responseBody = mExternalResourceManager.getResourceContent("paypal_accounts_response.json");
+ mServer.mockResponse().withHttpResponseCode(HTTP_OK).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();
+ verify(mListener).onSuccess(mListPayPalCaptor.capture());
+ verify(mListener, never()).onFailure(any(HyperwalletException.class));
+
+ HyperwalletPageList payPalAccountsResponse = mListPayPalCaptor.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"));
+
+ 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
+ public void testListPayPalAccounts_returnsNoAccounts() throws InterruptedException {
+ mServer.mockResponse().withHttpResponseCode(HTTP_NO_CONTENT).withBody("").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(mListPayPalCaptor.capture());
+ verify(mListener, never()).onFailure(any(HyperwalletException.class));
+
+ HyperwalletPageList payPalAccountsResponse = mListPayPalCaptor.getValue();
+ assertThat(payPalAccountsResponse, is(nullValue()));
+ }
+
+ @Test
+ public void testListPayPalAccounts_returnsError() throws InterruptedException {
+ String responseBody = mExternalResourceManager.getResourceContentError("system_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(), Matchers.hasSize(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/java/com/hyperwallet/android/transfermethod/HyperwalletUpdatePayPalAccountTest.java b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletUpdatePayPalAccountTest.java
new file mode 100644
index 00000000..004331e2
--- /dev/null
+++ b/core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletUpdatePayPalAccountTest.java
@@ -0,0 +1,147 @@
+package com.hyperwallet.android.transfermethod;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.CREATED_ON;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.EMAIL;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.STATUS;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TOKEN;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_CURRENCY;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TYPE;
+import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;
+
+import com.hyperwallet.android.Hyperwallet;
+import com.hyperwallet.android.exception.HyperwalletException;
+import com.hyperwallet.android.exception.HyperwalletRestException;
+import com.hyperwallet.android.listener.HyperwalletListener;
+import com.hyperwallet.android.model.HyperwalletError;
+import com.hyperwallet.android.model.HyperwalletErrors;
+import com.hyperwallet.android.model.PayPalAccount;
+import com.hyperwallet.android.rule.HyperwalletExternalResourceManager;
+import com.hyperwallet.android.rule.HyperwalletMockWebServer;
+import com.hyperwallet.android.rule.HyperwalletSdkMock;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+
+import java.net.HttpURLConnection;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.mockwebserver.RecordedRequest;
+
+@RunWith(RobolectricTestRunner.class)
+public class HyperwalletUpdatePayPalAccountTest {
+ @Rule
+ public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer();
+ @Rule
+ public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer);
+ @Rule
+ public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager();
+ @Rule
+ public MockitoRule mMockito = MockitoJUnit.rule();
+
+ @Mock
+ private HyperwalletListener mListener;
+
+ @Captor
+ private ArgumentCaptor mPayPalAccountCaptor;
+ @Captor
+ private ArgumentCaptor mExceptionCaptor;
+
+ private final CountDownLatch mAwait = new CountDownLatch(1);
+
+ @Test
+ public void testUpdatePayPalAccount_withSuccess() throws InterruptedException {
+ String responseBody = mExternalResourceManager.getResourceContent("paypal_account_update_response.json");
+ mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_OK).withBody(responseBody).mock();
+
+ final PayPalAccount payPalAccount = new PayPalAccount
+ .Builder()
+ .email("jsmith2@paypal.com")
+ .token("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b")
+ .build();
+
+ assertThat(payPalAccount.getField(EMAIL), is("jsmith2@paypal.com"));
+ assertThat(payPalAccount.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"));
+
+ Hyperwallet.getDefault().updatePayPalAccount(payPalAccount, mListener);
+ mAwait.await(50, TimeUnit.MILLISECONDS);
+
+ RecordedRequest recordedRequest = mServer.getRequest();
+ verify(mListener).onSuccess(mPayPalAccountCaptor.capture());
+ verify(mListener, never()).onFailure(any(HyperwalletException.class));
+
+ PayPalAccount payPalAccountResponse = mPayPalAccountCaptor.getValue();
+ assertThat(payPalAccountResponse, is(notNullValue()));
+
+ assertThat(recordedRequest.getPath(),
+ is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-ac5727ac-8fe7-42fb"
+ + "-b69d-977ebdd7b48b"));
+
+ assertThat(payPalAccountResponse.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"));
+ assertThat(payPalAccountResponse.getField(STATUS), is("ACTIVATED"));
+ assertThat(payPalAccountResponse.getField(TYPE), is(PAYPAL_ACCOUNT));
+ assertThat(payPalAccountResponse.getField(EMAIL), is("jsmith2@paypal.com"));
+ assertThat(payPalAccountResponse.getField(TRANSFER_METHOD_CURRENCY), is("USD"));
+ assertThat(payPalAccountResponse.getField(TRANSFER_METHOD_COUNTRY), is("US"));
+ assertThat(payPalAccountResponse.getField(CREATED_ON), is("2019-01-09T22:50:14"));
+ }
+
+ @Test
+ public void testUpdatePayPalAccount_withValidationError() throws InterruptedException {
+
+ String responseBody = mExternalResourceManager.getResourceContentError(
+ "paypal_account_update_error_response.json");
+ mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock();
+
+ final PayPalAccount payPalAccount = new PayPalAccount
+ .Builder()
+ .email("00G0G1ema.com")
+ .token("trm-56b976c5-26b2-42fa-87cf-14b3366673c6")
+ .build();
+
+ assertThat(payPalAccount.getField(EMAIL), is("00G0G1ema.com"));
+ assertThat(payPalAccount.getField(TOKEN),
+ is("trm-56b976c5-26b2-42fa-87cf-14b3366673c6"));
+
+ Hyperwallet.getDefault().updatePayPalAccount(payPalAccount, mListener);
+ mAwait.await(50, TimeUnit.MILLISECONDS);
+
+ RecordedRequest recordedRequest = mServer.getRequest();
+ verify(mListener, never()).onSuccess(any(PayPalAccount.class));
+ verify(mListener).onFailure(mExceptionCaptor.capture());
+
+ HyperwalletException hyperwalletException = mExceptionCaptor.getValue();
+ assertThat(hyperwalletException, is(notNullValue()));
+ assertThat(((HyperwalletRestException) hyperwalletException).getHttpCode(),
+ is(HttpURLConnection.HTTP_BAD_REQUEST));
+
+ assertThat(recordedRequest.getPath(),
+ is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-56b976c5-26b2-42fa-87cf"
+ + "-14b3366673c6"));
+
+ HyperwalletErrors hyperwalletErrors = hyperwalletException.getHyperwalletErrors();
+ assertThat(hyperwalletErrors, is(notNullValue()));
+ assertThat(hyperwalletErrors.getErrors(), hasSize(1));
+
+ HyperwalletError hyperwalletError1 = hyperwalletErrors.getErrors().get(0);
+ assertThat(hyperwalletError1.getCode(), is("CONSTRAINT_VIOLATIONS"));
+ assertThat(hyperwalletError1.getFieldName(), is("email"));
+ assertThat(hyperwalletError1.getMessage(), is("Invalid Email"));
+ }
+}
diff --git a/core/src/test/resources/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
diff --git a/core/src/test/resources/errors/bank_cards_error_response.json b/core/src/test/resources/errors/bank_cards_error_response.json
deleted file mode 100644
index 88024b4b..00000000
--- a/core/src/test/resources/errors/bank_cards_error_response.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "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/errors/paypal_account_update_error_response.json b/core/src/test/resources/errors/paypal_account_update_error_response.json
new file mode 100644
index 00000000..408baab1
--- /dev/null
+++ b/core/src/test/resources/errors/paypal_account_update_error_response.json
@@ -0,0 +1,9 @@
+{
+ "errors": [
+ {
+ "message": "Invalid Email",
+ "fieldName": "email",
+ "code": "CONSTRAINT_VIOLATIONS"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/core/src/test/resources/paypal_account_response.json b/core/src/test/resources/paypal_account_response.json
new file mode 100644
index 00000000..2af282e8
--- /dev/null
+++ b/core/src/test/resources/paypal_account_response.json
@@ -0,0 +1,17 @@
+{
+ "token": "trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b",
+ "type": "PAYPAL_ACCOUNT",
+ "status": "ACTIVATED",
+ "createdOn": "2019-01-09T22:50:14",
+ "transferMethodCountry": "US",
+ "transferMethodCurrency": "USD",
+ "email": "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-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/core/src/test/resources/paypal_account_update_response.json b/core/src/test/resources/paypal_account_update_response.json
new file mode 100644
index 00000000..a157c0a0
--- /dev/null
+++ b/core/src/test/resources/paypal_account_update_response.json
@@ -0,0 +1,17 @@
+{
+ "token": "trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b",
+ "type": "PAYPAL_ACCOUNT",
+ "status": "ACTIVATED",
+ "createdOn": "2019-01-09T22:50:14",
+ "transferMethodCountry": "US",
+ "transferMethodCurrency": "USD",
+ "email": "jsmith2@paypal.com",
+ "links": [
+ {
+ "params": {
+ "rel": "self"
+ },
+ "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-c4292f1a-866f-4310-a289-b916853939de/paypal-accounts/trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/core/src/test/resources/paypal_accounts_response.json b/core/src/test/resources/paypal_accounts_response.json
new file mode 100644
index 00000000..e3f03b85
--- /dev/null
+++ b/core/src/test/resources/paypal_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/user_response.json b/core/src/test/resources/user_response.json
new file mode 100644
index 00000000..24558fa8
--- /dev/null
+++ b/core/src/test/resources/user_response.json
@@ -0,0 +1,27 @@
+{
+ "token": "usr-f9154016-94e8-4686-a840-075688ac07b5",
+ "status": "PRE_ACTIVATED",
+ "verificationStatus": "NOT_REQUIRED",
+ "createdOn": "2017-10-30T22:15:45",
+ "clientUserId": "123345789",
+ "profileType": "INDIVIDUAL",
+ "firstName": "Some",
+ "lastName": "Guy",
+ "dateOfBirth": "1991-01-01",
+ "email": "someguy@hyperwallet.com",
+ "addressLine1": "575 Market Street",
+ "city": "San Francisco",
+ "stateProvince": "CA",
+ "country": "US",
+ "postalCode": "94105",
+ "language": "en",
+ "programToken": "prg-83836cdf-2ce2-4696-8bc5-f1b86077238c",
+ "links": [
+ {
+ "params": {
+ "rel": "self"
+ },
+ "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-f9154016-94e8-4686-a840-075688ac07b5"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/core/src/test/resources/user_response_all_fields.json b/core/src/test/resources/user_response_all_fields.json
new file mode 100644
index 00000000..f2e68d7d
--- /dev/null
+++ b/core/src/test/resources/user_response_all_fields.json
@@ -0,0 +1,51 @@
+{
+ "token": "usr-f9154016-94e8-4686-a840-075688ac07b5",
+ "status": "PRE_ACTIVATED",
+ "verificationStatus": "NOT_REQUIRED",
+ "createdOn": "2017-10-30T22:15:45",
+ "clientUserId": "123345789",
+ "profileType": "INDIVIDUAL",
+ "firstName": "Some",
+ "middleName": "Nice",
+ "lastName": "Guy",
+ "dateOfBirth": "1991-01-01",
+ "countryOfBirth": "US",
+ "countryOfNationality": "US",
+ "email": "someguy@hyperwallet.com",
+ "phoneNumber": "+1 604 777888",
+ "mobileNumber": "+1 604 123456",
+ "governmentId": "123456789",
+ "governmentIdType": "PASSPORT",
+ "passportId": "ABC-12345",
+ "driversLicenseId": "7788899",
+ "addressLine1": "575 Market Street",
+ "addressLine2": "Unit 2",
+ "city": "San Francisco",
+ "stateProvince": "CA",
+ "country": "US",
+ "postalCode": "94105",
+ "employerId": "7778889",
+ "businessContactRole": "DIRECTOR",
+ "businessName": "Hyperwallet",
+ "businessRegistrationCountry": "US",
+ "businessRegistrationId": "ABC-1234",
+ "businessRegistrationStateProvince": "CA",
+ "businessContactAddressLine1": "123 Townsend St.",
+ "businessContactAddressLine2": "Sixth Floor",
+ "businessContactCity": "San Francisco",
+ "businessContactStateProvince": "CA",
+ "businessContactCountry": "US",
+ "businessContactPostalCode": "94107",
+ "businessOperatingName": "Hyperwallet",
+ "businessType": "CORPORATION",
+ "language": "en",
+ "programToken": "prg-83836cdf-2ce2-4696-8bc5-f1b86077238c",
+ "links": [
+ {
+ "params": {
+ "rel": "self"
+ },
+ "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-f9154016-94e8-4686-a840-075688ac07b5"
+ }
+ ]
+}
\ No newline at end of file