Search in sources :

Example 1 with PaymentProcessEvent

use of com.kloia.sample.dto.event.PaymentProcessEvent in project eventapis by kloiasoft.

the class StockReservedEventHandler method execute.

@Override
@KafkaListener(topics = "StockReservedEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(StockReservedEvent dto) throws EventStoreException, ConcurrentEventException {
    Orders order = orderQuery.queryEntity(dto.getOrderId());
    if (order.getState() == OrderState.RESERVING_STOCK) {
        PaymentProcessEvent paymentProcessEvent = new PaymentProcessEvent(order.getId(), dto.getSender().getVersion(), new PaymentInformation(order.getPaymentAddress(), order.getAmount(), order.getCardInformation()));
        log.info("Payment is processing : " + dto);
        return eventRepository.recordAndPublish(order, paymentProcessEvent);
    } else
        throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
Also used : Orders(com.kloia.sample.model.Orders) EventStoreException(com.kloia.eventapis.exception.EventStoreException) PaymentProcessEvent(com.kloia.sample.dto.event.PaymentProcessEvent) PaymentInformation(com.kloia.sample.model.PaymentInformation) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Aggregations

EventStoreException (com.kloia.eventapis.exception.EventStoreException)1 PaymentProcessEvent (com.kloia.sample.dto.event.PaymentProcessEvent)1 Orders (com.kloia.sample.model.Orders)1 PaymentInformation (com.kloia.sample.model.PaymentInformation)1 KafkaListener (org.springframework.kafka.annotation.KafkaListener)1