Search in sources :

Example 1 with Payment

use of com.kloia.sample.model.Payment in project eventapis by kloiasoft.

the class ReturnPaymentCommand method execute.

@RequestMapping(value = "/payment/{paymentId}/return", method = RequestMethod.POST)
@Command
public EventKey execute(@PathVariable("paymentId") String paymentId, @RequestBody @Valid ReturnPaymentCommandDto dto) throws Exception {
    dto.setPaymentId(paymentId);
    Payment payment = paymentViewQuery.queryEntity(dto.getPaymentId());
    if (payment.getState() == PaymentState.PAID) {
        PaymentReturnedEvent paymentReturnedEvent = new PaymentReturnedEvent(payment.getOrderId(), payment.getAmount());
        return eventRepository.recordAndPublish(payment, paymentReturnedEvent);
    } else
        throw new EventStoreException("Payment state is not valid for this Operation: " + dto);
}
Also used : PaymentReturnedEvent(com.kloia.sample.dto.event.PaymentReturnedEvent) EventStoreException(com.kloia.eventapis.exception.EventStoreException) Payment(com.kloia.sample.model.Payment) Command(com.kloia.eventapis.api.Command) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Command (com.kloia.eventapis.api.Command)1 EventStoreException (com.kloia.eventapis.exception.EventStoreException)1 PaymentReturnedEvent (com.kloia.sample.dto.event.PaymentReturnedEvent)1 Payment (com.kloia.sample.model.Payment)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1