use of alfio.model.transaction.capabilities.ServerInitiatedTransaction in project alf.io by alfio-event.
the class TicketReservationManager method cancelPendingPayment.
public boolean cancelPendingPayment(String reservationId, PurchaseContext purchaseContext) {
var optionalReservation = findById(reservationId);
if (optionalReservation.isEmpty()) {
return false;
}
var optionalTransaction = transactionRepository.loadOptionalByReservationId(reservationId);
if (optionalTransaction.isEmpty() || optionalTransaction.get().getStatus() != Transaction.Status.PENDING) {
log.warn("Trying to cancel a non-pending transaction for reservation {}", reservationId);
return false;
}
Transaction transaction = optionalTransaction.get();
boolean remoteDeleteResult = paymentManager.lookupProviderByTransactionAndCapabilities(transaction, List.of(ServerInitiatedTransaction.class)).map(provider -> ((ServerInitiatedTransaction) provider).discardTransaction(optionalTransaction.get(), purchaseContext)).orElse(true);
if (remoteDeleteResult) {
reTransitionToPending(reservationId);
auditingRepository.insert(reservationId, null, purchaseContext.event().map(Event::getId).orElse(null), RESET_PAYMENT, new Date(), RESERVATION, reservationId);
return true;
}
log.warn("Cannot delete payment with ID {} for reservation {}", transaction.getPaymentId(), reservationId);
return false;
}
Aggregations