use of alfio.model.transaction.capabilities.RefundRequest in project alf.io by alfio-event.
the class PaymentManager method refund.
public boolean refund(TicketReservation reservation, PurchaseContext purchaseContext, Integer amount, String username) {
Transaction transaction = transactionRepository.loadByReservationId(reservation.getId());
boolean res = lookupProviderByTransactionAndCapabilities(transaction, List.of(RefundRequest.class)).map(paymentProvider -> ((RefundRequest) paymentProvider).refund(transaction, purchaseContext, amount)).orElse(false);
Map<String, Object> changes = Map.of("refund", amount != null ? amount.toString() : "full", "paymentMethod", reservation.getPaymentMethod().toString());
if (res) {
auditingRepository.insert(reservation.getId(), userRepository.findIdByUserName(username).orElse(null), purchaseContext, Audit.EventType.REFUND, new Date(), Audit.EntityType.RESERVATION, reservation.getId(), Collections.singletonList(changes));
extensionManager.handleRefund(purchaseContext, reservation, getInfo(reservation, purchaseContext));
} else {
auditingRepository.insert(reservation.getId(), userRepository.findIdByUserName(username).orElse(null), purchaseContext, Audit.EventType.REFUND_ATTEMPT_FAILED, new Date(), Audit.EntityType.RESERVATION, reservation.getId(), Collections.singletonList(changes));
}
return res;
}
Aggregations