EscPaymentManagerImp implements EscPaymentManager { @Override public boolean manageEscForPayment(final List<PaymentData> paymentDataList, final String paymentStatus, final String paymentStatusDetail) { boolean isInvalidEsc = false; for (final PaymentData paymentData : paymentDataList) { if (EscUtil .shouldDeleteEsc(paymentSettingRepository.getConfiguration().getEscBlacklistedStatus(), paymentData, paymentStatus, paymentStatusDetail)) { escManager.deleteESCWith(paymentData.getToken().getCardId(), EscDeleteReason.REJECTED_PAYMENT, paymentStatusDetail); } else if (EscUtil .shouldStoreESC(paymentSettingRepository.getConfiguration().getEscBlacklistedStatus(), paymentData, paymentStatus, paymentStatusDetail)) { escManager.saveESCWith(paymentData.getToken().getCardId(), paymentData.getToken().getEsc()); } isInvalidEsc |= EscUtil.isInvalidEscPayment(paymentData, paymentStatus, paymentStatusDetail); } return isInvalidEsc; } EscPaymentManagerImp(@NonNull final ESCManagerBehaviour escManager,
        @NonNull final PaymentSettingRepository paymentSettingRepository); @Override boolean hasEsc(@NonNull final Card card); @Override boolean manageEscForPayment(final List<PaymentData> paymentDataList, final String paymentStatus,
        final String paymentStatusDetail); @Override boolean manageEscForError(final MercadoPagoError error, final List<PaymentData> paymentDataList);  }
@Test public void whenManageEscForPaymentHasValidPaymentDataAndIsApproveSavesCardReturnFalse() { final PaymentData paymentData = validCardPaymentData(); final boolean invalid = escPaymentManager .manageEscForPayment(Collections.singletonList(paymentData), Payment.StatusCodes.STATUS_APPROVED, Payment.StatusDetail.STATUS_DETAIL_ACCREDITED); verify(escManagerBehaviour).saveESCWith(paymentData.getToken().getCardId(), paymentData.getToken().getEsc()); verifyNoMoreInteractions(escManagerBehaviour); assertFalse(invalid); }
@Test public void whenManageEscForPaymentHasValidPaymentDataAndIsRejectedInvalidEscSaveESCReturnTrue() { final PaymentData paymentData = validCardPaymentData(); final boolean invalid = escPaymentManager .manageEscForPayment(Collections.singletonList(paymentData), Payment.StatusCodes.STATUS_REJECTED, Payment.StatusDetail.STATUS_DETAIL_INVALID_ESC); verify(escManagerBehaviour).saveESCWith(eq(paymentData.getToken().getCardId()), anyString()); verifyNoMoreInteractions(escManagerBehaviour); assertTrue(invalid); }
@Test public void whenManageEscForPaymentHasValidPaymentDataAndIsRejectedSaveEscReturnFalse() { final PaymentData paymentData = validCardPaymentData(); final boolean invalid = escPaymentManager .manageEscForPayment(Collections.singletonList(paymentData), Payment.StatusCodes.STATUS_REJECTED, Payment.StatusDetail.STATUS_DETAIL_CC_REJECTED_BAD_FILLED_DATE); verify(escManagerBehaviour).saveESCWith(eq(paymentData.getToken().getCardId()), anyString()); verifyNoMoreInteractions(escManagerBehaviour); assertFalse(invalid); }
@Test public void whenManageEscForPaymentHasValidPaymentDataAndIsRejectedBadFilledSecurityCodeDeleteESCReturnFalse() { final PaymentData paymentData = validCardPaymentData(); final boolean invalid = escPaymentManager .manageEscForPayment(Collections.singletonList(paymentData), Payment.StatusCodes.STATUS_REJECTED, Payment.StatusDetail.STATUS_DETAIL_CC_REJECTED_BAD_FILLED_SECURITY_CODE); verify(escManagerBehaviour).deleteESCWith(paymentData.getToken().getCardId(), EscDeleteReason.REJECTED_PAYMENT, Payment.StatusDetail.STATUS_DETAIL_CC_REJECTED_BAD_FILLED_SECURITY_CODE); verifyNoMoreInteractions(escManagerBehaviour); assertFalse(invalid); }
@Test public void whenManageEscForPaymentHasNonCardPaymentDataAndIsRejectedDoNothingReturnFalse() { final PaymentData paymentData = mock(PaymentData.class); final boolean invalid = escPaymentManager .manageEscForPayment(Collections.singletonList(paymentData), Payment.StatusCodes.STATUS_REJECTED, Payment.StatusDetail.STATUS_DETAIL_INVALID_ESC); verifyNoMoreInteractions(escManagerBehaviour); assertFalse(invalid); }
@Test public void whenManageEscForPaymentHasNonCardPaymentDataAndIsApprovedDoNothingReturnFalse() { final PaymentData paymentData = mock(PaymentData.class); final boolean invalid = escPaymentManager .manageEscForPayment(Collections.singletonList(paymentData), Payment.StatusCodes.STATUS_APPROVED, Payment.StatusDetail.STATUS_DETAIL_INVALID_ESC); verifyNoMoreInteractions(escManagerBehaviour); assertFalse(invalid); }