Search in sources :

Example 1 with PaymentSuccessEvent

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

the class DoPaymentEventHandler method execute.

@KafkaListener(topics = "PaymentProcessEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(PaymentProcessEvent dto) throws EventStoreException, EventPulisherException, ConcurrentEventException {
    PaymentSuccessEvent paymentSuccessEvent = new PaymentSuccessEvent();
    BeanUtils.copyProperties(dto.getPaymentInformation(), paymentSuccessEvent);
    paymentSuccessEvent.setOrderId(dto.getSender().getEntityId());
    if (dto.getPaymentInformation().getAmount() > 2000)
        throw new RuntimeException("Bla Bla");
    if (dto.getPaymentInformation().getAmount() > 1000) {
        PaymentFailedEvent paymentFailedEvent = new PaymentFailedEvent();
        BeanUtils.copyProperties(dto.getPaymentInformation(), paymentFailedEvent);
        paymentFailedEvent.setOrderId(dto.getSender().getEntityId());
        return eventRepository.recordAndPublish(paymentFailedEvent);
    }
    return eventRepository.recordAndPublish(paymentSuccessEvent);
}
Also used : PaymentSuccessEvent(com.kloia.sample.dto.event.PaymentSuccessEvent) PaymentFailedEvent(com.kloia.sample.dto.event.PaymentFailedEvent) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Aggregations

PaymentFailedEvent (com.kloia.sample.dto.event.PaymentFailedEvent)1 PaymentSuccessEvent (com.kloia.sample.dto.event.PaymentSuccessEvent)1 KafkaListener (org.springframework.kafka.annotation.KafkaListener)1