DisabledPaymentMethodService implements DisabledPaymentMethodRepository { @Override public void handleDisableablePayment(@NonNull final PaymentResult paymentResult) { if (isDisableablePayment(paymentResult)) { final boolean isSplitPayment = paymentResult.getPaymentDataList().size() > 1; final String paymentMethodId; final String paymentTypeId = paymentResult.getPaymentData().getPaymentMethod().getPaymentTypeId(); if (isSplitPayment && TextUtil.isNotEmpty(paymentResult.getPaymentMethodId())) { paymentMethodId = paymentResult.getPaymentMethodId(); } else if ( PaymentTypes.isCardPaymentType(paymentResult.getPaymentData().getPaymentMethod().getPaymentTypeId()) && paymentResult.getPaymentData().getToken() != null && TextUtil.isNotEmpty(paymentResult.getPaymentData().getToken().getCardId())) { paymentMethodId = paymentResult.getPaymentData().getToken().getCardId(); } else { paymentMethodId = paymentResult.getPaymentData().getPaymentMethod().getId(); } if (!PaymentTypes.isCardPaymentType(paymentTypeId) || isNotEmpty(paymentResult.getPaymentData().getToken().getCardId())) { storeDisabledPaymentMethodId(paymentMethodId, paymentResult.getPaymentStatusDetail()); } } } DisabledPaymentMethodService(@NonNull final SharedPreferences sharedPreferences); @Override void storeDisabledPaymentMethodsIds(@NonNull final Collection<String> paymentMethodsIds); @NonNull @Override Map<String, DisabledPaymentMethod> getDisabledPaymentMethods(); @Override DisabledPaymentMethod getDisabledPaymentMethod(@NonNull final String paymentMethodId); @Override void reset(); @Override boolean hasPaymentMethodId(@NonNull final String paymentMethodId); @Override void handleDisableablePayment(@NonNull final PaymentResult paymentResult);  }
@Test public void whenPaymentRejectedWithDisableableStatusVerifyDisableablePaymentManaged() { final PaymentResult paymentResult = mock(PaymentResult.class); mockPayment(paymentResult, PaymentTypes.ACCOUNT_MONEY, PaymentMethods.ACCOUNT_MONEY); disabledPaymentMethodService.handleDisableablePayment(paymentResult); verifyDisableablePaymentManaged(true); }
@Test public void whenGenericPaymentRejectedWithDisableableStatusVerifyDisableablePaymentManaged() { final PaymentResult paymentResult = mock(PaymentResult.class); mockPayment(paymentResult, PaymentTypes.ACCOUNT_MONEY, PaymentMethods.ACCOUNT_MONEY); disabledPaymentMethodService.handleDisableablePayment(paymentResult); verifyDisableablePaymentManaged(true); }
@Test public void whenBusinessPaymentRejectedWithDisableableStatusVerifyDisableablePaymentManaged() { final PaymentResult paymentResult = mock(PaymentResult.class); mockPayment(paymentResult, PaymentTypes.ACCOUNT_MONEY, PaymentMethods.ACCOUNT_MONEY); disabledPaymentMethodService.handleDisableablePayment(paymentResult); verifyDisableablePaymentManaged(true); }
@Test public void whenPaymentRejectedWithDisableableStatusAndCardVerifyDisableablePaymentManaged() { final PaymentResult paymentResult = mock(PaymentResult.class); mockPayment(paymentResult, PaymentTypes.CREDIT_CARD, PaymentMethods.ARGENTINA.VISA); when(paymentResult.getPaymentData().getToken()).thenReturn(mock(Token.class)); when(paymentResult.getPaymentData().getToken().getCardId()).thenReturn(CARD_ID); disabledPaymentMethodService.handleDisableablePayment(paymentResult); verifyDisableablePaymentManaged(true); }
@Test public void whenPaymentRejectedWithDisableableStatusAndGuessingCardVerifyDisableablePaymentManaged() { final PaymentResult paymentResult = mock(PaymentResult.class); mockPayment(paymentResult, PaymentTypes.CREDIT_CARD, PaymentMethods.ARGENTINA.VISA); when(paymentResult.getPaymentData().getToken()).thenReturn(mock(Token.class)); disabledPaymentMethodService.handleDisableablePayment(paymentResult); verifyDisableablePaymentManaged(false); }