Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6add58b
HW-51228. PayPal Account Deactivation
azakrevska-epam Apr 30, 2019
9c48a4b
HW-51228. Changed PUT tp POST
azakrevska-epam May 2, 2019
bad9f75
HW-51226. PayPalAccount update (#1)
azakrevska-epam May 3, 2019
296bb3b
HW-51227. PayPal Account Creation (#2)
azakrevska-epam May 3, 2019
6733ab0
HW-51321: Get paypal account (#3)
vshcherbyna-epam May 3, 2019
22e89d1
Adding required properties to pom file
fmattos-hw Apr 30, 2019
c31df58
Version update and exempt maven local publish task from signing
fmattos-hw Apr 30, 2019
eddeb7f
add PayPal get test to Hyperwallet test suite
fmattos-hw May 3, 2019
b421d5a
HW-51226. PayPalAccount update (#1)
azakrevska-epam May 3, 2019
58d20c8
HW-51227. PayPal Account Creation (#2)
azakrevska-epam May 3, 2019
5a0ba23
HW-51321: Get paypal account (#3)
vshcherbyna-epam May 3, 2019
4d4ae4c
Adding required properties to pom file
fmattos-hw Apr 30, 2019
cd10fa8
Version update and exempt maven local publish task from signing
fmattos-hw Apr 30, 2019
c997ef2
add PayPal get test to Hyperwallet test suite
fmattos-hw May 3, 2019
9ce7c71
fix javadoc
fmattos-hw May 3, 2019
ac055ea
HW-51226. PayPalAccount update (#1)
azakrevska-epam May 3, 2019
381a03c
HW-51321: Get paypal account (#3)
vshcherbyna-epam May 3, 2019
3df53c5
HW-51228. PayPal Account Deactivation
azakrevska-epam Apr 30, 2019
0509925
HW-51228. Changed PUT tp POST
azakrevska-epam May 2, 2019
3e0a8ff
fix javadoc
fmattos-hw May 3, 2019
aa7bfee
HW-51226. PayPalAccount update (#1)
azakrevska-epam May 3, 2019
1da01f5
HW-51321: Get paypal account (#3)
vshcherbyna-epam May 3, 2019
892aca4
Merge remote-tracking branch 'origin/feature/HW-51228_deactivate_PayP…
fmattos-hw May 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ allprojects {
mavenLocal()
}

project.version = "1.0.0-beta01";
project.version = "1.0.0-beta02-SNAPSHOT";
}

task clean(type: Delete) {
Expand Down
5 changes: 4 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ publishing {
artifact(aarArtifact)

pom {
name = 'Hyperwallet Android Core SDK'
description = 'Hyperwallet Core SDK for Android to integrate with Hyperwallet Platform'
url = 'https://github.com/hyperwallet/hyperwallet-android-sdk'
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
Expand Down Expand Up @@ -148,7 +151,7 @@ publishing {

tasks.withType(Sign) {
onlyIf {
isReleaseVersion
isReleaseVersion && !gradle.taskGraph.hasTask("publishToMavenLocal")
}
}

Expand Down
139 changes: 124 additions & 15 deletions core/src/main/java/com/hyperwallet/android/Hyperwallet.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class PayPalAccount extends HyperwalletTransferMethod {

/**
* Constructor to build bank card, based on json object
* Constructor to build PayPal Account, based on json object
*/
public PayPalAccount(@NonNull JSONObject jsonObject) throws JSONException {
super(jsonObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
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.HyperwalletListBankAccountsTest;
import com.hyperwallet.android.transfermethod.HyperwalletListBankCardsTest;
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;
Expand All @@ -23,12 +27,16 @@
HyperwalletCreateBankAccountTest.class,
HyperwalletListBankAccountsTest.class,
HyperwalletCreateBankCardTest.class,
HyperwalletCreatePayPalAccountTest.class,
HyperwalletGetBankAccountTest.class,
HyperwalletGetBankCardTest.class,
HyperwalletGetPayPalTest.class,
HyperwalletUpdateBankAccountTest.class,
HyperwalletUpdateBankCardTest.class,
HyperwalletUpdatePayPalAccountTest.class,
HyperwalletDeactivateBankAccountTest.class,
HyperwalletDeactivateBankCardTest.class,
HyperwalletDeactivatePayPalAccountTest.class,
HyperwalletListTransferMethodsTest.class,
HyperwalletListBankCardsTest.class,
HyperwalletRetrieveTransferMethodConfigurationKeysTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.hyperwallet.android.transfermethod;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import static com.hyperwallet.android.model.HyperwalletStatusTransition.StatusDefinition.ACTIVATED;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.CREATED_ON;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.EMAIL;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.STATUS;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TOKEN;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_CURRENCY;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TYPE;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;

import com.hyperwallet.android.Hyperwallet;
import com.hyperwallet.android.exception.HyperwalletException;
import com.hyperwallet.android.listener.HyperwalletListener;
import com.hyperwallet.android.model.HyperwalletError;
import com.hyperwallet.android.model.HyperwalletErrors;
import com.hyperwallet.android.model.PayPalAccount;
import com.hyperwallet.android.rule.HyperwalletExternalResourceManager;
import com.hyperwallet.android.rule.HyperwalletMockWebServer;
import com.hyperwallet.android.rule.HyperwalletSdkMock;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;

import java.net.HttpURLConnection;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import okhttp3.mockwebserver.RecordedRequest;

@RunWith(RobolectricTestRunner.class)
public class HyperwalletCreatePayPalAccountTest {
@Rule
public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer();
@Rule
public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer);
@Rule
public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager();
@Rule
public MockitoRule mMockito = MockitoJUnit.rule();

@Mock
private HyperwalletListener<PayPalAccount> mListener;

@Captor
private ArgumentCaptor<PayPalAccount> mPayPalAccountCaptor;
@Captor
private ArgumentCaptor<HyperwalletException> mExceptionCaptor;

private final CountDownLatch mAwait = new CountDownLatch(1);

@Test
public void testCreatePayPalAccount_withSuccess() throws InterruptedException {

String responseBody = mExternalResourceManager.getResourceContent("paypal_account_response.json");
mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_CREATED).withBody(responseBody).mock();

final PayPalAccount.Builder builder = new PayPalAccount
.Builder("US", "USD", "jsmith@paypal.com")
.token("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b");

final PayPalAccount payPalAccount = builder.build();

assertThat(payPalAccount.getField(TRANSFER_METHOD_COUNTRY), is("US"));
assertThat(payPalAccount.getField(TRANSFER_METHOD_CURRENCY), is("USD"));
assertThat(payPalAccount.getField(EMAIL), is("jsmith@paypal.com"));
assertThat(payPalAccount.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"));


Hyperwallet.getDefault().createPayPalAccount(payPalAccount, mListener);
mAwait.await(50, TimeUnit.MILLISECONDS);

RecordedRequest recordedRequest = mServer.getRequest();
verify(mListener).onSuccess(mPayPalAccountCaptor.capture());
verify(mListener, never()).onFailure(any(HyperwalletException.class));

PayPalAccount paypalAccountResponse = mPayPalAccountCaptor.getValue();
assertThat(paypalAccountResponse, is(notNullValue()));

//paypal account info
assertThat(recordedRequest.getPath(),
is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts"));

assertThat(paypalAccountResponse.getField(STATUS), is(ACTIVATED));
assertThat(paypalAccountResponse.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b"));
assertThat(paypalAccountResponse.getField(TRANSFER_METHOD_COUNTRY), is("US"));
assertThat(paypalAccountResponse.getField(TRANSFER_METHOD_CURRENCY), is("USD"));
assertThat(paypalAccountResponse.getField(TYPE), is(PAYPAL_ACCOUNT));
assertThat(paypalAccountResponse.getField(CREATED_ON), is(notNullValue()));
assertThat(paypalAccountResponse.getField(EMAIL), is("jsmith@paypal.com"));
}

@Test
public void testCreatePayPalAccount_withValidationError() throws InterruptedException {
String responseBody = mExternalResourceManager.getResourceContentError("transfer_method_error_response.json");
mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock();

final PayPalAccount payPalAccount = new PayPalAccount
.Builder("", "USD", "jsmith@paypal.com")
.token("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b")
.build();

Hyperwallet.getDefault().createPayPalAccount(payPalAccount, mListener);
mAwait.await(50, TimeUnit.MILLISECONDS);

RecordedRequest recordedRequest = mServer.getRequest();
verify(mListener, never()).onSuccess(any(PayPalAccount.class));
verify(mListener).onFailure(mExceptionCaptor.capture());

HyperwalletException hyperwalletException = mExceptionCaptor.getValue();
assertThat(hyperwalletException, is(notNullValue()));

assertThat(recordedRequest.getPath(),
is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts"));

HyperwalletErrors hyperwalletErrors = hyperwalletException.getHyperwalletErrors();
assertThat(hyperwalletErrors.getErrors(), hasSize(1));

HyperwalletError hyperwalletError = hyperwalletErrors.getErrors().get(0);
assertThat(hyperwalletError.getCode(), is("CONSTRAINT_VIOLATIONS"));
assertThat(hyperwalletError.getFieldName(), is("transferMethodCountry"));
assertThat(hyperwalletError.getMessage(), is("You must provide a value for this field"));
}
}
Original file line number Diff line number Diff line change
@@ -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<HyperwalletStatusTransition> mListener;
@Captor
private ArgumentCaptor<HyperwalletStatusTransition> mStatusTransitionCaptor;
@Captor
private ArgumentCaptor<HyperwalletException> 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<HyperwalletError> 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"));
}
}
Loading