Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.hyperwallet.android.model.HyperwalletBankCard;
import com.hyperwallet.android.model.HyperwalletStatusTransition;
import com.hyperwallet.android.model.HyperwalletTransferMethod;
import com.hyperwallet.android.model.PayPalAccount;
import com.hyperwallet.android.model.paging.HyperwalletPageList;

public class TransferMethodRepositoryImpl implements TransferMethodRepository {
Expand All @@ -47,7 +48,7 @@ Hyperwallet getHyperwallet() {
}

@Override
public void createTransferMethod(final HyperwalletTransferMethod transferMethod,
public void createTransferMethod(@NonNull final HyperwalletTransferMethod transferMethod,
LoadTransferMethodCallback callback) {
switch (transferMethod.getField(TYPE)) {
case BANK_ACCOUNT:
Expand All @@ -56,6 +57,9 @@ public void createTransferMethod(final HyperwalletTransferMethod transferMethod,
case BANK_CARD:
createBankCard(transferMethod, callback);
break;
case PAYPAL_ACCOUNT:
createPayPalAccount(transferMethod, callback);
break;
default: //no default action
}
}
Expand Down Expand Up @@ -204,4 +208,26 @@ public Handler getHandler() {
}
});
}

private void createPayPalAccount(@NonNull final HyperwalletTransferMethod transferMethod,
@NonNull final LoadTransferMethodCallback callback) {
PayPalAccount payPalAccount = (PayPalAccount) transferMethod;

getHyperwallet().createPayPalAccount(payPalAccount, new HyperwalletListener<PayPalAccount>() {
@Override
public void onSuccess(@Nullable PayPalAccount result) {
callback.onTransferMethodLoaded(result);
}

@Override
public void onFailure(HyperwalletException exception) {
callback.onError(exception.getHyperwalletErrors());
}

@Override
public Handler getHandler() {
return mHandler;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TYPE;
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 android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -48,6 +49,7 @@
import com.hyperwallet.android.model.HyperwalletBankCard;
import com.hyperwallet.android.model.HyperwalletError;
import com.hyperwallet.android.model.HyperwalletTransferMethod;
import com.hyperwallet.android.model.PayPalAccount;
import com.hyperwallet.android.model.meta.Fee;
import com.hyperwallet.android.model.meta.HyperwalletField;
import com.hyperwallet.android.ui.HyperwalletLocalBroadcast;
Expand Down Expand Up @@ -466,6 +468,12 @@ private void triggerSubmit() {
mTransferMethod = new HyperwalletBankCard.Builder().
transferMethodCountry(mCountry).transferMethodCurrency(mCurrency).build();
break;
case PAYPAL_ACCOUNT:
mTransferMethod = new PayPalAccount.Builder()
.transferMethodCountry(mCountry)
.transferMethodCurrency(mCurrency)
.build();
break;
default:
mTransferMethod = new HyperwalletTransferMethod();
mTransferMethod.setField(TRANSFER_METHOD_COUNTRY, mCountry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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.PAPER_CHECK;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PREPAID_CARD;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.WIRE_ACCOUNT;

Expand Down Expand Up @@ -114,6 +115,9 @@ public static String getTransferMethodName(@NonNull final Context context,
case WIRE_ACCOUNT:
title = context.getString(R.string.wire_account);
break;
case PAYPAL_ACCOUNT:
title = context.getString(R.string.paypal_account);
break;
default:
title = transferMethodType.toLowerCase(Locale.ROOT) + context.getString(
R.string.not_translated_in_braces);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
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.HyperwalletStatusTransition.StatusDefinition.DE_ACTIVATED;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.BANK_ACCOUNT_ID;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.BANK_NAME;
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;
Expand Down Expand Up @@ -71,6 +73,8 @@ public class TransferMethodRepositoryImplTest {
@Captor
private ArgumentCaptor<HyperwalletBankCard> mBankCardArgumentCaptor;
@Captor
private ArgumentCaptor<PayPalAccount> mPayPalAccountArgumentCaptor;
@Captor
private ArgumentCaptor<HyperwalletStatusTransition> mStatusTransitionArgumentCaptor;
@Captor
private ArgumentCaptor<List<HyperwalletTransferMethod>> mListTransferMethodCaptor;
Expand Down Expand Up @@ -377,7 +381,6 @@ public void testCreateTransferMethod_bankCardWithError() {
.Builder("CA", "CAD", "1232345456784", "2019-05", "234")
.build();


final HyperwalletError error = new HyperwalletError("bank card test message", "BANK_CARD_TEST_CODE");

doAnswer(new Answer() {
Expand Down Expand Up @@ -484,4 +487,75 @@ public Object answer(InvocationOnMock invocation) {

assertThat(mErrorsArgumentCaptor.getValue().getErrors(), hasItem(error));
}

@Test
public void testCreateTransferMethod_payPalAccountWithSuccess() {
// prepare
final PayPalAccount returnedPayPalAccount = new PayPalAccount.Builder()
.transferMethodCurrency("USD")
.transferMethodCountry("US")
.email("money@mail.com")
.token("trm-token-1342242314")
.build();

doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) {
HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[1];
returnedPayPalAccount.setField(STATUS, ACTIVATED);
listener.onSuccess(returnedPayPalAccount);
return listener;
}
}).when(mHyperwallet).createPayPalAccount(any(PayPalAccount.class),
ArgumentMatchers.<HyperwalletListener<PayPalAccount>>any());

PayPalAccount parameter = new PayPalAccount.Builder().build();

// test
mTransferMethodRepository.createTransferMethod(parameter, mLoadTransferMethodCallback);

// verify
verify(mLoadTransferMethodCallback).onTransferMethodLoaded(mPayPalAccountArgumentCaptor.capture());
verify(mLoadTransferMethodCallback, never()).onError(any(HyperwalletErrors.class));

// assert
PayPalAccount payPalAccount = mPayPalAccountArgumentCaptor.getValue();
assertThat(payPalAccount, is(notNullValue()));
assertThat(payPalAccount.getCountry(), is("US"));
assertThat(payPalAccount.getCurrency(), is("USD"));
assertThat(payPalAccount.getEmail(), is("money@mail.com"));
assertThat(payPalAccount.getField(STATUS), is(ACTIVATED));
assertThat(payPalAccount.getField(TOKEN), is("trm-token-1342242314"));
}

@Test
public void testCreateTransferMethod_payPalAccountWithError() {
// prepare
final HyperwalletError returnedError = new HyperwalletError("PayPal test message", "PAYPAL_TEST_CODE");

doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) {
HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[1];

List<HyperwalletError> errorList = new ArrayList<>();
errorList.add(returnedError);

listener.onFailure(new HyperwalletException(new HyperwalletErrors(errorList)));
return listener;
}
}).when(mHyperwallet).createPayPalAccount(any(PayPalAccount.class),
ArgumentMatchers.<HyperwalletListener<PayPalAccount>>any());
PayPalAccount parameter = new PayPalAccount.Builder().build();

// test
mTransferMethodRepository.createTransferMethod(parameter, mLoadTransferMethodCallback);

// verify
verify(mLoadTransferMethodCallback, never()).onTransferMethodLoaded(any(HyperwalletTransferMethod.class));
verify(mLoadTransferMethodCallback).onError(mErrorsArgumentCaptor.capture());

// assert
assertThat(mErrorsArgumentCaptor.getValue().getErrors(), hasItem(returnedError));
}
}