Search in sources :

Example 1 with OfflineProcessor

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));
    }
}
Also used : alfio.repository(alfio.repository) TicketMetadataContainer(alfio.model.metadata.TicketMetadataContainer) ZonedDateTime(java.time.ZonedDateTime) TicketCheckInUtil.ticketOnlineCheckInUrl(alfio.util.checkin.TicketCheckInUtil.ticketOnlineCheckInUrl) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) StringUtils(org.apache.commons.lang3.StringUtils) TransactionSynchronizationManager(org.springframework.transaction.support.TransactionSynchronizationManager) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) DateUtils.truncate(org.apache.commons.lang3.time.DateUtils.truncate) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) Arrays.asList(java.util.Arrays.asList) ASReservationWithOptionalCodeModification(alfio.model.modification.ASReservationWithOptionalCodeModification) Triple(org.apache.commons.lang3.tuple.Triple) TICKET(alfio.model.Audit.EntityType.TICKET) Organization(alfio.model.user.Organization) UserIdAndOrganizationId(alfio.model.support.UserIdAndOrganizationId) ZoneId(java.time.ZoneId) SubscriptionTimeUnit(alfio.model.subscription.SubscriptionDescriptor.SubscriptionTimeUnit) EventType(alfio.model.Audit.EventType) Stream(java.util.stream.Stream) Type(alfio.model.BillingDocument.Type) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) AdditionalServiceItemPriceContainer(alfio.model.decorator.AdditionalServiceItemPriceContainer) AdditionalServiceItemStatus(alfio.model.AdditionalServiceItem.AdditionalServiceItemStatus) AdditionalServiceReservationModification(alfio.model.modification.AdditionalServiceReservationModification) PromoCodeDiscount.categoriesOrNull(alfio.model.PromoCodeDiscount.categoriesOrNull) java.util(java.util) TicketHelper(alfio.controller.api.support.TicketHelper) ConfigurationLevel(alfio.manager.system.ConfigurationLevel) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) SummaryType(alfio.model.SummaryRow.SummaryType) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) BindingResult(org.springframework.validation.BindingResult) ConfigurationManager(alfio.manager.system.ConfigurationManager) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) RESERVATION(alfio.model.Audit.EntityType.RESERVATION) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) WebhookHandler(alfio.model.transaction.capabilities.WebhookHandler) Status(alfio.model.SpecialPrice.Status) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) LinkedGroup(alfio.model.group.LinkedGroup) Validate(org.apache.commons.lang3.Validate) ChronoUnit(java.time.temporal.ChronoUnit) MonetaryUtil(alfio.util.MonetaryUtil) UserManager(alfio.manager.user.UserManager) WarningMessage(alfio.model.result.WarningMessage) Wrappers.optionally(alfio.util.Wrappers.optionally) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServerInitiatedTransaction(alfio.model.transaction.capabilities.ServerInitiatedTransaction) TemplateProcessor(alfio.controller.support.TemplateProcessor) DiscountType(alfio.model.PromoCodeDiscount.DiscountType) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) AdditionalServicePriceContainer(alfio.model.decorator.AdditionalServicePriceContainer) Mailer(alfio.manager.system.Mailer) TicketStatus(alfio.model.Ticket.TicketStatus) TicketCheckInUtil(alfio.util.checkin.TicketCheckInUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) OfflineProcessor(alfio.model.transaction.capabilities.OfflineProcessor) OrganizationRepository(alfio.repository.user.OrganizationRepository) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Role(alfio.model.user.Role) Principal(java.security.Principal) Entry(java.util.Map.Entry) CodeType(alfio.model.PromoCodeDiscount.CodeType) OnlineCheckInFullInfo(alfio.model.checkin.OnlineCheckInFullInfo) IntStream(java.util.stream.IntStream) CustomEmailText(alfio.model.extension.CustomEmailText) ChronoField(java.time.temporal.ChronoField) TransactionDefinition(org.springframework.transaction.TransactionDefinition) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) Function(java.util.function.Function) alfio.util(alfio.util) ReservationPriceCalculator(alfio.manager.system.ReservationPriceCalculator) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) ObjectUtils(org.apache.commons.lang3.ObjectUtils) alfio.model.transaction(alfio.model.transaction) UserDetails(org.springframework.security.core.userdetails.UserDetails) alfio.model.subscription(alfio.model.subscription) Collections.singletonMap(java.util.Collections.singletonMap) VatStatus(alfio.model.PriceContainer.VatStatus) ONCE_PER_EVENT(alfio.model.subscription.SubscriptionDescriptor.SubscriptionUsageType.ONCE_PER_EVENT) alfio.manager.support(alfio.manager.support) BankTransferManager(alfio.manager.payment.BankTransferManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) TicketMetadata(alfio.model.metadata.TicketMetadata) DateUtils.addHours(org.apache.commons.lang3.time.DateUtils.addHours) Component(org.springframework.stereotype.Component) PaymentSpecification(alfio.manager.payment.PaymentSpecification) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) PaymentMethodStatus(alfio.manager.PaymentManager.PaymentMethodDTO.PaymentMethodStatus) Clock(java.time.Clock) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) OfflineProcessor(alfio.model.transaction.capabilities.OfflineProcessor)

Aggregations

TicketHelper (alfio.controller.api.support.TicketHelper)1 UpdateTicketOwnerForm (alfio.controller.form.UpdateTicketOwnerForm)1 TemplateProcessor (alfio.controller.support.TemplateProcessor)1 PaymentMethodStatus (alfio.manager.PaymentManager.PaymentMethodDTO.PaymentMethodStatus)1 MessageSourceManager (alfio.manager.i18n.MessageSourceManager)1 BankTransferManager (alfio.manager.payment.BankTransferManager)1 PaymentSpecification (alfio.manager.payment.PaymentSpecification)1 alfio.manager.support (alfio.manager.support)1 ConfigurationLevel (alfio.manager.system.ConfigurationLevel)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1 Mailer (alfio.manager.system.Mailer)1 ReservationPriceCalculator (alfio.manager.system.ReservationPriceCalculator)1 UserManager (alfio.manager.user.UserManager)1 alfio.model (alfio.model)1 AdditionalServiceItemStatus (alfio.model.AdditionalServiceItem.AdditionalServiceItemStatus)1 RESERVATION (alfio.model.Audit.EntityType.RESERVATION)1 TICKET (alfio.model.Audit.EntityType.TICKET)1 EventType (alfio.model.Audit.EventType)1 Type (alfio.model.BillingDocument.Type)1 VatStatus (alfio.model.PriceContainer.VatStatus)1