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