Search in sources :

Example 1 with ChargeEventEntity

use of uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity in project pay-connector by alphagov.

the class ChargeService method transitionChargeState.

@Transactional
public ChargeEntity transitionChargeState(ChargeEntity charge, ChargeStatus targetChargeState, ZonedDateTime gatewayEventTime) {
    ChargeStatus fromChargeState = ChargeStatus.fromString(charge.getStatus());
    charge.setStatus(targetChargeState);
    ChargeEventEntity chargeEventEntity = chargeEventDao.persistChargeEventOf(charge, gatewayEventTime);
    if (shouldEmitPaymentStateTransitionEvents) {
        stateTransitionService.offerPaymentStateTransition(charge.getExternalId(), fromChargeState, targetChargeState, chargeEventEntity);
    }
    taskQueueService.offerTasksOnStateTransition(charge);
    return charge;
}
Also used : ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) Transactional(com.google.inject.persist.Transactional)

Example 2 with ChargeEventEntity

use of uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity in project pay-connector by alphagov.

the class StateTransitionServiceTest method shouldOfferPaymentStateTransitionMessageForAValidStateTransitionIntoNonLockingState.

@Test
public void shouldOfferPaymentStateTransitionMessageForAValidStateTransitionIntoNonLockingState() {
    ChargeEventEntity chargeEvent = aValidChargeEventEntity().withId(100L).build();
    stateTransitionService.offerPaymentStateTransition("external-id", ChargeStatus.CREATED, ENTERING_CARD_DETAILS, chargeEvent);
    ArgumentCaptor<PaymentStateTransition> paymentStateTransitionArgumentCaptor = ArgumentCaptor.forClass(PaymentStateTransition.class);
    verify(mockStateTransitionQueue).offer(paymentStateTransitionArgumentCaptor.capture());
    assertThat(paymentStateTransitionArgumentCaptor.getValue().getChargeEventId(), is(100L));
    assertThat(paymentStateTransitionArgumentCaptor.getValue().getStateTransitionEventClass(), is(PaymentStarted.class));
    verify(mockEventService).recordOfferedEvent(PAYMENT, "external-id", "PAYMENT_STARTED", chargeEvent.getUpdated());
}
Also used : PaymentStarted(uk.gov.pay.connector.events.model.charge.PaymentStarted) ChargeEventEntityFixture.aValidChargeEventEntity(uk.gov.pay.connector.pact.ChargeEventEntityFixture.aValidChargeEventEntity) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Test(org.junit.Test)

Example 3 with ChargeEventEntity

use of uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity in project pay-connector by alphagov.

the class EventFactoryTest method shouldCreatedCorrectEventForPaymentNotificationCreated.

@Test
public void shouldCreatedCorrectEventForPaymentNotificationCreated() throws Exception {
    ChargeEntity charge = ChargeEntityFixture.aValidChargeEntity().withStatus(ChargeStatus.PAYMENT_NOTIFICATION_CREATED).build();
    Long chargeEventEntityId = 100L;
    ChargeEventEntity chargeEventEntity = ChargeEventEntityFixture.aValidChargeEventEntity().withCharge(charge).withId(chargeEventEntityId).build();
    when(chargeEventDao.findById(ChargeEventEntity.class, chargeEventEntityId)).thenReturn(Optional.of(chargeEventEntity));
    PaymentStateTransition paymentStateTransition = new PaymentStateTransition(chargeEventEntityId, PaymentNotificationCreated.class);
    List<Event> events = eventFactory.createEvents(paymentStateTransition);
    assertThat(events.size(), is(1));
    PaymentNotificationCreated event = (PaymentNotificationCreated) events.get(0);
    assertThat(event, is(instanceOf(PaymentNotificationCreated.class)));
    assertThat(event.getEventDetails(), instanceOf(PaymentNotificationCreatedEventDetails.class));
    assertThat(event.getResourceExternalId(), is(chargeEventEntity.getChargeEntity().getExternalId()));
    PaymentNotificationCreatedEventDetails eventDetails = (PaymentNotificationCreatedEventDetails) event.getEventDetails();
    assertThat(eventDetails.getGatewayTransactionId(), is(charge.getGatewayTransactionId()));
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) Event(uk.gov.pay.connector.events.model.Event) PaymentNotificationCreated(uk.gov.pay.connector.events.model.charge.PaymentNotificationCreated) PaymentNotificationCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentNotificationCreatedEventDetails) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Test(org.junit.Test)

Example 4 with ChargeEventEntity

use of uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity in project pay-connector by alphagov.

the class EventFactoryTest method shouldCreatedCorrectEventForBackfillRecreatedUserEmailCollectedEvent.

@Test
public void shouldCreatedCorrectEventForBackfillRecreatedUserEmailCollectedEvent() throws Exception {
    ChargeEntity charge = ChargeEntityFixture.aValidChargeEntity().withStatus(ChargeStatus.USER_CANCELLED).withEmail("test@example.org").build();
    Long chargeEventEntityId = 100L;
    ChargeEventEntity chargeEventEntity = ChargeEventEntityFixture.aValidChargeEventEntity().withCharge(charge).withChargeStatus(ENTERING_CARD_DETAILS).withId(chargeEventEntityId).build();
    charge.getEvents().add(chargeEventEntity);
    when(chargeEventDao.findById(ChargeEventEntity.class, chargeEventEntityId)).thenReturn(Optional.of(chargeEventEntity));
    PaymentStateTransition paymentStateTransition = new PaymentStateTransition(chargeEventEntityId, BackfillerRecreatedUserEmailCollected.class);
    List<Event> events = eventFactory.createEvents(paymentStateTransition);
    assertThat(events.size(), is(1));
    BackfillerRecreatedUserEmailCollected event = (BackfillerRecreatedUserEmailCollected) events.get(0);
    assertThat(event, is(instanceOf(BackfillerRecreatedUserEmailCollected.class)));
    assertThat(event.getEventDetails(), instanceOf(UserEmailCollectedEventDetails.class));
    assertThat(event.getResourceExternalId(), is(chargeEventEntity.getChargeEntity().getExternalId()));
    UserEmailCollectedEventDetails eventDetails = (UserEmailCollectedEventDetails) event.getEventDetails();
    assertThat(eventDetails.getEmail(), is(charge.getEmail()));
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) BackfillerRecreatedUserEmailCollected(uk.gov.pay.connector.events.model.charge.BackfillerRecreatedUserEmailCollected) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) UserEmailCollectedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.UserEmailCollectedEventDetails) Event(uk.gov.pay.connector.events.model.Event) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Test(org.junit.Test)

Example 5 with ChargeEventEntity

use of uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity in project pay-connector by alphagov.

the class EventFactoryTest method shouldCreatedRefundAvailabilityUpdatedEventForTerminalAndOtherStatesAffectingRefundability.

@Test
@Parameters(method = "statesAffectingRefundability")
public void shouldCreatedRefundAvailabilityUpdatedEventForTerminalAndOtherStatesAffectingRefundability(Class eventClass, Class eventDetailsClass) throws Exception {
    Long chargeEventEntityId = 100L;
    ChargeEventEntity chargeEventEntity = ChargeEventEntityFixture.aValidChargeEventEntity().withCharge(charge).withId(chargeEventEntityId).build();
    when(chargeEventDao.findById(ChargeEventEntity.class, chargeEventEntityId)).thenReturn(Optional.of(chargeEventEntity));
    PaymentStateTransition paymentStateTransition = new PaymentStateTransition(chargeEventEntityId, eventClass);
    List<Event> events = eventFactory.createEvents(paymentStateTransition);
    assertThat(events.size(), is(2));
    Event event1 = events.get(0);
    assertThat(event1, instanceOf(eventClass));
    assertThat(event1.getEventDetails(), instanceOf(eventDetailsClass));
    RefundAvailabilityUpdated event2 = (RefundAvailabilityUpdated) events.get(1);
    assertThat(event2, instanceOf(RefundAvailabilityUpdated.class));
    assertThat(event2.getEventDetails(), instanceOf(RefundAvailabilityUpdatedEventDetails.class));
}
Also used : ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) Event(uk.gov.pay.connector.events.model.Event) RefundAvailabilityUpdatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.RefundAvailabilityUpdatedEventDetails) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)62 Test (org.junit.Test)42 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)25 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)14 ZonedDateTime (java.time.ZonedDateTime)12 ChargeEventEntityBuilder.aChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity.ChargeEventEntityBuilder.aChargeEventEntity)12 Event (uk.gov.pay.connector.events.model.Event)12 ChargeEventEntityFixture.aValidChargeEventEntity (uk.gov.pay.connector.pact.ChargeEventEntityFixture.aValidChargeEventEntity)11 Before (org.junit.Before)10 PaymentStateTransition (uk.gov.pay.connector.queue.statetransition.PaymentStateTransition)8 Auth3dsRequiredEntity (uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity)6 PactVerifyProvider (au.com.dius.pact.provider.PactVerifyProvider)5 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)4 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)4 ConnectorConfiguration (uk.gov.pay.connector.app.ConnectorConfiguration)4 ChargeStatus (uk.gov.pay.connector.charge.model.domain.ChargeStatus)4 PaymentCreated (uk.gov.pay.connector.events.model.charge.PaymentCreated)4 PaymentDetailsEntered (uk.gov.pay.connector.events.model.charge.PaymentDetailsEntered)4 CardServiceTest (uk.gov.pay.connector.paymentprocessor.service.CardServiceTest)4 StateTransition (uk.gov.pay.connector.queue.statetransition.StateTransition)4