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;
}
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());
}
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()));
}
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()));
}
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));
}
Aggregations