use of alfio.model.transaction.capabilities.OfflineProcessor in project alf.io by alfio-event.
the class TicketReservationManager method checkOfflinePaymentsForEvent.
private void checkOfflinePaymentsForEvent(Event event) {
log.trace("check offline payments for event {}", event.getShortName());
var paymentContext = new PaymentContext(event);
var providers = paymentManager.streamActiveProvidersByProxyAndCapabilities(PaymentProxy.OFFLINE, paymentContext, List.of(OfflineProcessor.class)).collect(toList());
if (providers.isEmpty()) {
log.trace("No active offline provider has been found. Exiting...");
return;
}
var pendingReservationsMap = ticketSearchRepository.findOfflineReservationsWithPendingTransaction(event.getId()).stream().collect(toMap(tr -> tr.getTicketReservation().getId(), Function.identity()));
if (pendingReservationsMap.isEmpty()) {
log.trace("no pending reservations found. Exiting...");
return;
}
var errors = new ArrayList<String>();
var confirmed = new ArrayList<String>();
var pendingReview = new ArrayList<String>();
int matchingCount = 0;
for (int i = 0; !pendingReservationsMap.isEmpty() && i < providers.size(); i++) {
OfflineProcessor offlineProcessor = (OfflineProcessor) providers.get(i);
Result<List<String>> matching = offlineProcessor.checkPendingReservations(pendingReservationsMap.values(), paymentContext, null);
if (matching.isSuccess()) {
int resultSize = matching.getData().size();
matchingCount += resultSize;
log.trace("found {} matches for provider {}", matchingCount, offlineProcessor.getClass().getName());
if (resultSize > 0) {
processResults(event, pendingReservationsMap, errors, confirmed, pendingReview, matching);
}
}
}
if (matchingCount > 0) {
var organization = organizationRepository.getById(event.getOrganizationId());
var cc = notificationManager.getCCForEventOrganizer(event);
var subject = String.format("%d matching payments found for: %s", matchingCount, event.getDisplayName());
Map<String, Object> model = Map.of("matchingCount", matchingCount, "eventName", event.getDisplayName(), "pendingReviewMatches", !pendingReview.isEmpty(), "pendingReview", pendingReview, "automaticApprovedMatches", !confirmed.isEmpty(), "automaticApproved", confirmed, "automaticApprovalErrors", !errors.isEmpty(), "approvalErrors", errors);
notificationManager.sendSimpleEmail(event, null, organization.getEmail(), cc, subject, () -> templateManager.renderTemplate(event, TemplateResource.OFFLINE_PAYMENT_MATCHES_FOUND, model, Locale.ENGLISH));
}
}
Aggregations