PaymentService implements PaymentRepository { @Override public void startExpressPayment(@NonNull final PaymentConfiguration configuration) { handlerWrapper.createTransactionLiveData(); initRepository.init().enqueue(new Callback<InitResponse>() { @Override public void success(final InitResponse initResponse) { final Pair<String, String> pair = new Pair<>(configuration.getPaymentMethodId(), configuration.getPaymentTypeId()); final PaymentMethod paymentMethod = new PaymentMethodMapper(initResponse).map(pair); userSelectionRepository.select(paymentMethod, null); if (PaymentTypes.isCardPaymentType(paymentMethod.getPaymentTypeId())) { final Card card = initResponse.getCardById(configuration.getCustomOptionId()); if (configuration.getSplitPayment()) { final String secondaryPaymentMethodId = amountConfigurationRepository .getConfigurationFor(card.getId()) .getSplitConfiguration().secondaryPaymentMethod.paymentMethodId; userSelectionRepository .select(card, initResponse.getPaymentMethodById(secondaryPaymentMethodId)); } else if (card != null) { userSelectionRepository.select(card, null); } } userSelectionRepository.select(configuration.getPayerCost()); startPayment(); } @Override public void failure(final ApiException apiException) { throw new IllegalStateException("empty payment methods"); } }); } PaymentService(@NonNull final UserSelectionRepository userSelectionRepository,
        @NonNull final PaymentSettingRepository paymentSettingRepository,
        @NonNull final DisabledPaymentMethodRepository disabledPaymentMethodRepository,
        @NonNull final PluginRepository pluginRepository,
        @NonNull final DiscountRepository discountRepository,
        @NonNull final AmountRepository amountRepository,
        @NonNull final Context context,
        @NonNull final EscPaymentManager escPaymentManager,
        @NonNull final ESCManagerBehaviour escManagerBehaviour,
        @NonNull final TokenRepository tokenRepository,
        @NonNull final InstructionsRepository instructionsRepository,
        @NonNull final InitRepository initRepository,
        @NonNull final AmountConfigurationRepository amountConfigurationRepository,
        @NonNull final CongratsRepository congratsRepository,
        @NonNull final FileManager fileManager); @Override PaymentServiceEventHandler getObservableEvents(); @Override void reset(); @Override void storePayment(@NonNull final IPaymentDescriptor payment); @Nullable @Override IPaymentDescriptor getPayment(); @Override boolean hasRecoverablePayment(); @NonNull @Override PaymentRecovery createRecoveryForInvalidESC(); @NonNull @Override PaymentRecovery createPaymentRecovery(); @Override void startExpressPayment(@NonNull final PaymentConfiguration configuration); @Override void startPayment(); @Override boolean isExplodingAnimationCompatible(); @NonNull @Override List<PaymentData> getPaymentDataList(); @NonNull @Override PaymentResult createPaymentResult(@NonNull final IPaymentDescriptor payment); @Override int getPaymentTimeout(); MercadoPagoError getError();  }
@Test public void whenOneTapPaymentIsCardSelectCard() { final Card card = creditCardPresetMock(CARD_ID_ESC_APPROVED); when(amountConfigurationRepository.getCurrentConfiguration()).thenThrow(IllegalStateException.class); paymentService.startExpressPayment(mockPaymentConfiguration(node, payerCost)); verify(userSelectionRepository).select(reflectionEquals(card), any()); }
@Test public void whenOneTapPaymentIsCardSelectPayerCost() { creditCardPresetMock(CARD_ID_ESC_APPROVED); when(amountConfigurationRepository.getCurrentConfiguration()).thenThrow(IllegalStateException.class); paymentService.startExpressPayment(mockPaymentConfiguration(node, payerCost)); verify(userSelectionRepository).select(payerCost); }
@Test public void whenOneTapPaymentIsCardPayerCostAndCardSet() { final Card card = creditCardPresetMock(CARD_ID_ESC_APPROVED); when(amountConfigurationRepository.getCurrentConfiguration()).thenThrow(IllegalStateException.class); paymentService.startExpressPayment(mockPaymentConfiguration(node, payerCost)); verify(userSelectionRepository).select(reflectionEquals(card), any()); verify(userSelectionRepository).select(payerCost); }
@Test public void whenOneTapPaymentWhenSavedCardAndESCSavedThenAskTokenSuccess() { final Card card = savedCreditCardOneTapPresent(CARD_ID_ESC_APPROVED); when(escPaymentManager.hasEsc(card)).thenReturn(true); final MPCall<Token> tokenMPCall = mock(MPCall.class); when(tokenRepository.createToken(card)).thenReturn(tokenMPCall); when(escManagerBehaviour.isESCEnabled()).thenReturn(true); paymentService.startExpressPayment(mockPaymentConfiguration(node, payerCost)); verify(escPaymentManager).hasEsc(card); verifyNoMoreInteractions(escPaymentManager); verify(tokenRepository).createToken(card); verifyNoMoreInteractions(tokenRepository); }
@Test public void whenOneTapPaymentWhenNotSavedCardAndESCSavedThenAskCVV() { final Card card = savedCreditCardOneTapPresent(CARD_ID_ESC_APPROVED); when(escPaymentManager.hasEsc(card)).thenReturn(false); when(escManagerBehaviour.isESCEnabled()).thenReturn(true); paymentService.startExpressPayment(mockPaymentConfiguration(node, payerCost)); verify(escPaymentManager).hasEsc(card); verifyNoMoreInteractions(escPaymentManager); verifyNoMoreInteractions(tokenRepository); }
@Test public void whenOneTapPaymentWhenCapNotExceededAndNotApproved() { final Card card = savedCreditCardOneTapPresent(CARD_ID_ESC_NOT_AVAILABLE); final MPCall<Token> tokenMPCall = mock(MPCall.class); when(tokenRepository.createToken(card)).thenReturn(tokenMPCall); when(escPaymentManager.hasEsc(card)).thenReturn(true); when(escManagerBehaviour.isESCEnabled()).thenReturn(true); paymentService.startExpressPayment(mockPaymentConfiguration(node, payerCost)); verify(escPaymentManager).hasEsc(card); verifyNoMoreInteractions(escPaymentManager); verify(tokenRepository).createToken(card); verifyNoMoreInteractions(tokenRepository); }