Search in sources :

Example 1 with RefundHistory

use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.

the class RefundDaoJpaIT method updateParityCheckStatus_shouldUpdateParityCheckColumnsOnRefundCorrectly.

@Test
public void updateParityCheckStatus_shouldUpdateParityCheckColumnsOnRefundCorrectly() {
    RefundEntity refundEntity = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
    refundEntity.setStatus(CREATED);
    refundDao.persist(refundEntity);
    Optional<RefundEntity> mayBeRefundEntityFromDB = refundDao.findByExternalId(refundEntity.getExternalId());
    List<RefundHistory> refundHistoryList = refundDao.getRefundHistoryByRefundExternalId(refundEntity.getExternalId());
    assertThat(mayBeRefundEntityFromDB.get().getParityCheckDate(), is(nullValue()));
    assertThat(mayBeRefundEntityFromDB.get().getParityCheckStatus(), is(nullValue()));
    assertThat(refundHistoryList.size(), is(1));
    ZonedDateTime parityCheckDate = ZonedDateTime.now(UTC);
    refundDao.updateParityCheckStatus(refundEntity.getExternalId(), parityCheckDate, MISSING_IN_LEDGER);
    mayBeRefundEntityFromDB = refundDao.findByExternalId(refundEntity.getExternalId());
    refundHistoryList = refundDao.getRefundHistoryByRefundExternalId(refundEntity.getExternalId());
    assertThat(mayBeRefundEntityFromDB.get().getParityCheckDate().toLocalDateTime(), is(parityCheckDate.toLocalDateTime()));
    assertThat(mayBeRefundEntityFromDB.get().getParityCheckStatus(), is(MISSING_IN_LEDGER));
    assertThat(refundHistoryList.size(), is(1));
}
Also used : RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) ZonedDateTime(java.time.ZonedDateTime) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 2 with RefundHistory

use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.

the class RefundDaoJpaIT method shouldSearchAllHistoryStatusTypesByChargeId.

@Test
public void shouldSearchAllHistoryStatusTypesByChargeId() {
    RefundEntity refundEntity = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
    refundEntity.setGatewayTransactionId(refundGatewayTransactionId);
    refundEntity.setStatus(CREATED);
    refundDao.persist(refundEntity);
    refundEntity.setStatus(REFUND_SUBMITTED);
    refundDao.merge(refundEntity);
    List<RefundHistory> refundHistoryList = refundDao.searchAllHistoryByChargeExternalId(chargeTestRecord.getExternalChargeId());
    assertThat(refundHistoryList.size(), is(2));
}
Also used : RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 3 with RefundHistory

use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.

the class RefundDaoJpaIT method persist_shouldSearchHistoryByChargeExternalId.

@Test
public void persist_shouldSearchHistoryByChargeExternalId() {
    RefundEntity refundEntity = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
    refundEntity.setStatus(REFUND_SUBMITTED);
    refundEntity.setGatewayTransactionId(refundGatewayTransactionId);
    refundDao.persist(refundEntity);
    List<RefundHistory> refundHistoryList = refundDao.searchHistoryByChargeExternalId(chargeTestRecord.getExternalChargeId());
    assertThat(refundHistoryList.size(), is(1));
    RefundHistory refundHistory = refundHistoryList.get(0);
    assertThat(refundHistory.getId(), is(refundEntity.getId()));
    assertThat(refundHistory.getExternalId(), is(refundEntity.getExternalId()));
    assertThat(refundHistory.getAmount(), is(refundEntity.getAmount()));
    assertThat(refundHistory.getStatus(), is(refundEntity.getStatus()));
    assertThat(refundHistory.getUserEmail(), is(refundEntity.getUserEmail()));
    assertThat(refundHistory.getCreatedDate(), is(refundEntity.getCreatedDate()));
    assertThat(refundHistory.getVersion(), is(refundEntity.getVersion()));
    assertThat(refundEntity.getUserExternalId(), is(userExternalId));
    assertThat(refundEntity.getUserEmail(), is(refundEntity.getUserEmail()));
    assertThat(refundHistory.getUserExternalId(), is(refundEntity.getUserExternalId()));
    assertThat(refundHistory.getGatewayTransactionId(), is(refundEntity.getGatewayTransactionId()));
    assertThat(refundHistory.getChargeExternalId(), is(chargeTestRecord.getExternalChargeId()));
}
Also used : RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 4 with RefundHistory

use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.

the class RefundDaoJpaIT method expungeRefund_shouldExpungeRefundRelatedRecordsCorrectly.

@Test
public void expungeRefund_shouldExpungeRefundRelatedRecordsCorrectly() {
    RefundEntity refundToExpunge = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
    refundToExpunge.setStatus(REFUNDED);
    refundDao.persist(refundToExpunge);
    RefundEntity refundToNotBeExpunged = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
    refundToNotBeExpunged.setStatus(REFUND_ERROR);
    refundDao.persist(refundToNotBeExpunged);
    emittedEventDao.persist(anEmittedEventEntity().withResourceExternalId(refundToExpunge.getExternalId()).withResourceType("refund").withId(RandomUtils.nextLong()).build());
    // assert data is as expected
    Optional<RefundEntity> mayBeRefundEntity = refundDao.findByExternalId(refundToExpunge.getExternalId());
    List<RefundHistory> refundHistoryList = refundDao.searchHistoryByChargeExternalId(chargeTestRecord.getExternalChargeId());
    boolean containsEmittedEventForRefundExternalId = databaseTestHelper.containsEmittedEventWithExternalId(refundToExpunge.getExternalId());
    assertThat(containsEmittedEventForRefundExternalId, is(true));
    assertThat(mayBeRefundEntity.isPresent(), Matchers.is(true));
    assertThat(refundHistoryList.size(), Matchers.is(2));
    // act
    refundDao.expungeRefund(refundToExpunge.getExternalId());
    mayBeRefundEntity = refundDao.findByExternalId(refundToExpunge.getExternalId());
    refundHistoryList = refundDao.searchHistoryByChargeExternalId(chargeTestRecord.getExternalChargeId());
    containsEmittedEventForRefundExternalId = databaseTestHelper.containsEmittedEventWithExternalId(refundToExpunge.getExternalId());
    assertThat(mayBeRefundEntity.isPresent(), Matchers.is(false));
    assertThat(refundHistoryList.size(), Matchers.is(1));
    assertThat(containsEmittedEventForRefundExternalId, is(false));
}
Also used : RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 5 with RefundHistory

use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.

the class EventFactoryTest method shouldCreateCorrectEventsFromRefundCreatedStateTransition.

@Test
public void shouldCreateCorrectEventsFromRefundCreatedStateTransition() throws Exception {
    when(chargeService.findCharge(charge.getExternalId())).thenReturn(Optional.of(Charge.from(charge)));
    RefundHistory refundCreatedHistory = RefundHistoryEntityFixture.aValidRefundHistoryEntity().withStatus(RefundStatus.CREATED.getValue()).withUserExternalId("user_external_id").withUserEmail("test@example.com").withChargeExternalId(charge.getExternalId()).withAmount(charge.getAmount()).build();
    when(refundDao.getRefundHistoryByRefundExternalIdAndRefundStatus(refundCreatedHistory.getExternalId(), refundCreatedHistory.getStatus())).thenReturn(Optional.of(refundCreatedHistory));
    StateTransition refundStateTransition = new RefundStateTransition(refundCreatedHistory.getExternalId(), refundCreatedHistory.getStatus(), RefundCreatedByUser.class);
    List<Event> refundEvents = eventFactory.createEvents(refundStateTransition);
    assertThat(refundEvents.size(), is(2));
    RefundCreatedByUser refundCreatedByUser = (RefundCreatedByUser) refundEvents.stream().filter(e -> ResourceType.REFUND.equals(e.getResourceType())).findFirst().get();
    RefundCreatedByUserEventDetails eventDetails = (RefundCreatedByUserEventDetails) refundCreatedByUser.getEventDetails();
    assertThat(refundCreatedByUser.getParentResourceExternalId(), is(charge.getExternalId()));
    assertThat(eventDetails.getRefundedBy(), is("user_external_id"));
    assertThat(eventDetails.getUserEmail(), is("test@example.com"));
    assertThat(refundCreatedByUser.getResourceType(), is(ResourceType.REFUND));
    assertThat(refundCreatedByUser.getEventDetails(), is(instanceOf(RefundCreatedByUserEventDetails.class)));
    RefundAvailabilityUpdated refundAvailabilityUpdated = (RefundAvailabilityUpdated) refundEvents.stream().filter(e -> ResourceType.PAYMENT.equals(e.getResourceType())).findFirst().get();
    assertThat(refundAvailabilityUpdated.getResourceExternalId(), is(charge.getExternalId()));
    assertThat(refundAvailabilityUpdated.getResourceType(), is(ResourceType.PAYMENT));
    assertThat(refundAvailabilityUpdated.getEventDetails(), is(instanceOf(RefundAvailabilityUpdatedEventDetails.class)));
}
Also used : RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) CoreMatchers.is(org.hamcrest.CoreMatchers.is) CaptureConfirmedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CaptureConfirmedEventDetails) PaymentNotificationCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentNotificationCreatedEventDetails) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) BackfillerRecreatedUserEmailCollected(uk.gov.pay.connector.events.model.charge.BackfillerRecreatedUserEmailCollected) GatewayRequires3dsAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayRequires3dsAuthorisation) Is(org.hamcrest.core.Is) PaymentExpired(uk.gov.pay.connector.events.model.charge.PaymentExpired) CancelledByUserEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CancelledByUserEventDetails) PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) SandboxPaymentProvider(uk.gov.pay.connector.gateway.sandbox.SandboxPaymentProvider) CaptureSubmitted(uk.gov.pay.connector.events.model.charge.CaptureSubmitted) PaymentProviders(uk.gov.pay.connector.gateway.PaymentProviders) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) JUnitParamsRunner(junitparams.JUnitParamsRunner) RefundEventWithGatewayTransactionIdDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundEventWithGatewayTransactionIdDetails) ChargeEntityFixture(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture) CancelledByExternalService(uk.gov.pay.connector.events.model.charge.CancelledByExternalService) CancelledByUser(uk.gov.pay.connector.events.model.charge.CancelledByUser) EventFactory(uk.gov.pay.connector.events.model.EventFactory) GatewayTimeoutDuringAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayTimeoutDuringAuthorisation) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) CaptureSubmittedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CaptureSubmittedEventDetails) CancelledByExpiration(uk.gov.pay.connector.events.model.charge.CancelledByExpiration) LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) AuthorisationErrorCheckedWithGatewayChargeWasMissing(uk.gov.pay.connector.events.model.charge.AuthorisationErrorCheckedWithGatewayChargeWasMissing) RefundStatus(uk.gov.pay.connector.refund.model.domain.RefundStatus) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) Instant(java.time.Instant) RefundHistoryEntityFixture(uk.gov.pay.connector.pact.RefundHistoryEntityFixture) List(java.util.List) CaptureConfirmed(uk.gov.pay.connector.events.model.charge.CaptureConfirmed) Auth3dsRequiredEntity(uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity) CancelByExternalServiceSubmitted(uk.gov.pay.connector.events.model.charge.CancelByExternalServiceSubmitted) StatusCorrectedToCapturedToMatchGatewayStatus(uk.gov.pay.connector.events.model.charge.StatusCorrectedToCapturedToMatchGatewayStatus) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric) CancelByExpirationFailed(uk.gov.pay.connector.events.model.charge.CancelByExpirationFailed) RefundService(uk.gov.pay.connector.refund.service.RefundService) Optional(java.util.Optional) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) Event(uk.gov.pay.connector.events.model.Event) ResourceType(uk.gov.pay.connector.events.model.ResourceType) CancelByExternalServiceFailed(uk.gov.pay.connector.events.model.charge.CancelByExternalServiceFailed) CancelByUserFailed(uk.gov.pay.connector.events.model.charge.CancelByUserFailed) UserEmailCollectedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.UserEmailCollectedEventDetails) Parameters(junitparams.Parameters) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PaymentInstrumentService(uk.gov.pay.connector.paymentinstrument.service.PaymentInstrumentService) RefundDao(uk.gov.pay.connector.refund.dao.RefundDao) GatewayRequires3dsAuthorisationEventDetails(uk.gov.pay.connector.events.eventdetails.charge.GatewayRequires3dsAuthorisationEventDetails) ChargeEventEntityFixture(uk.gov.pay.connector.pact.ChargeEventEntityFixture) CaptureErrored(uk.gov.pay.connector.events.model.charge.CaptureErrored) RunWith(org.junit.runner.RunWith) PaymentCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentCreatedEventDetails) AuthorisationCancelled(uk.gov.pay.connector.events.model.charge.AuthorisationCancelled) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) EmptyEventDetails(uk.gov.pay.connector.events.eventdetails.EmptyEventDetails) Charge(uk.gov.pay.connector.charge.model.domain.Charge) AuthorisationRejected(uk.gov.pay.connector.events.model.charge.AuthorisationRejected) CancelledWithGatewayAfterAuthorisationError(uk.gov.pay.connector.events.model.charge.CancelledWithGatewayAfterAuthorisationError) ChargeService(uk.gov.pay.connector.charge.service.ChargeService) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) CaptureAbandonedAfterTooManyRetries(uk.gov.pay.connector.events.model.charge.CaptureAbandonedAfterTooManyRetries) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ENTERING_CARD_DETAILS(uk.gov.pay.connector.charge.model.domain.ChargeStatus.ENTERING_CARD_DETAILS) Before(org.junit.Before) AuthorisationErrorCheckedWithGatewayChargeWasRejected(uk.gov.pay.connector.events.model.charge.AuthorisationErrorCheckedWithGatewayChargeWasRejected) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) GatewayErrorDuringAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayErrorDuringAuthorisation) RefundAvailabilityUpdatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.RefundAvailabilityUpdatedEventDetails) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) AUTHORISATION_3DS_REQUIRED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.AUTHORISATION_3DS_REQUIRED) Test(org.junit.Test) ChargeEventDao(uk.gov.pay.connector.chargeevent.dao.ChargeEventDao) Mockito.when(org.mockito.Mockito.when) PaymentNotificationCreated(uk.gov.pay.connector.events.model.charge.PaymentNotificationCreated) UnexpectedGatewayErrorDuringAuthorisation(uk.gov.pay.connector.events.model.charge.UnexpectedGatewayErrorDuringAuthorisation) RefundCreatedByUserEventDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundCreatedByUserEventDetails) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Event(uk.gov.pay.connector.events.model.Event) RefundCreatedByUserEventDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundCreatedByUserEventDetails) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Aggregations

RefundHistory (uk.gov.pay.connector.refund.model.domain.RefundHistory)26 Test (org.junit.Test)19 RefundEntity (uk.gov.pay.connector.refund.model.domain.RefundEntity)10 Charge (uk.gov.pay.connector.charge.model.domain.Charge)7 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)7 StateTransition (uk.gov.pay.connector.queue.statetransition.StateTransition)7 Before (org.junit.Before)5 LedgerTransaction (uk.gov.pay.connector.client.ledger.model.LedgerTransaction)5 Event (uk.gov.pay.connector.events.model.Event)5 RefundStateTransition (uk.gov.pay.connector.queue.statetransition.RefundStateTransition)5 ZonedDateTime (java.time.ZonedDateTime)4 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)4 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)4 PaymentStateTransition (uk.gov.pay.connector.queue.statetransition.PaymentStateTransition)4 PactVerifyProvider (au.com.dius.pact.provider.PactVerifyProvider)3 Instant (java.time.Instant)3 List (java.util.List)3 Optional (java.util.Optional)3 JUnitParamsRunner (junitparams.JUnitParamsRunner)3 Parameters (junitparams.Parameters)3