Search in sources :

Example 1 with DefaultCheckInResult

use of alfio.manager.support.DefaultCheckInResult in project alf.io by alfio-event.

the class AttendeeManager method registerSponsorScan.

public TicketAndCheckInResult registerSponsorScan(String eventShortName, String ticketUid, String username) {
    int userId = userRepository.getByUsername(username).getId();
    Optional<Event> maybeEvent = eventRepository.findOptionalByShortName(eventShortName);
    if (!maybeEvent.isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(CheckInStatus.EVENT_NOT_FOUND, "event not found"));
    }
    Event event = maybeEvent.get();
    Optional<Ticket> maybeTicket = ticketRepository.findOptionalByUUID(ticketUid);
    if (!maybeTicket.isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(CheckInStatus.TICKET_NOT_FOUND, "ticket not found"));
    }
    Ticket ticket = maybeTicket.get();
    if (ticket.getStatus() != Ticket.TicketStatus.CHECKED_IN) {
        return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(CheckInStatus.INVALID_TICKET_STATE, "not checked-in"));
    }
    Optional<ZonedDateTime> existingRegistration = sponsorScanRepository.getRegistrationTimestamp(userId, event.getId(), ticket.getId());
    if (!existingRegistration.isPresent()) {
        sponsorScanRepository.insert(userId, ZonedDateTime.now(event.getZoneId()), event.getId(), ticket.getId());
    }
    return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(CheckInStatus.SUCCESS, "success"));
}
Also used : Ticket(alfio.model.Ticket) TicketAndCheckInResult(alfio.manager.support.TicketAndCheckInResult) ZonedDateTime(java.time.ZonedDateTime) Event(alfio.model.Event) DefaultCheckInResult(alfio.manager.support.DefaultCheckInResult)

Example 2 with DefaultCheckInResult

use of alfio.manager.support.DefaultCheckInResult in project alf.io by alfio-event.

the class CheckInManager method checkIn.

public TicketAndCheckInResult checkIn(int eventId, String ticketIdentifier, Optional<String> ticketCode, String user) {
    TicketAndCheckInResult descriptor = extractStatus(eventId, ticketRepository.findByUUIDForUpdate(ticketIdentifier), ticketIdentifier, ticketCode);
    if (descriptor.getResult().getStatus() == OK_READY_TO_BE_CHECKED_IN) {
        checkIn(ticketIdentifier);
        scanAuditRepository.insert(ticketIdentifier, eventId, ZonedDateTime.now(), user, SUCCESS, ScanAudit.Operation.SCAN);
        auditingRepository.insert(descriptor.getTicket().getTicketsReservationId(), userRepository.findIdByUserName(user).orElse(null), eventId, Audit.EventType.CHECK_IN, new Date(), Audit.EntityType.TICKET, Integer.toString(descriptor.getTicket().getId()));
        return new TicketAndCheckInResult(descriptor.getTicket(), new DefaultCheckInResult(SUCCESS, "success"));
    }
    return descriptor;
}
Also used : TicketAndCheckInResult(alfio.manager.support.TicketAndCheckInResult) DefaultCheckInResult(alfio.manager.support.DefaultCheckInResult)

Example 3 with DefaultCheckInResult

use of alfio.manager.support.DefaultCheckInResult in project alf.io by alfio-event.

the class CheckInManager method extractStatus.

private TicketAndCheckInResult extractStatus(Optional<Event> maybeEvent, Optional<Ticket> maybeTicket, String ticketIdentifier, Optional<String> ticketCode) {
    if (!maybeEvent.isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(EVENT_NOT_FOUND, "Event not found"));
    }
    if (!maybeTicket.isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(TICKET_NOT_FOUND, "Ticket with uuid " + ticketIdentifier + " not found"));
    }
    if (!ticketCode.filter(StringUtils::isNotEmpty).isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(EMPTY_TICKET_CODE, "Missing ticket code"));
    }
    Ticket ticket = maybeTicket.get();
    Event event = maybeEvent.get();
    String code = ticketCode.get();
    TicketCategory tc = ticketCategoryRepository.getById(ticket.getCategoryId());
    ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
    if (!tc.hasValidCheckIn(now, event.getZoneId())) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy - hh:mm");
        String from = tc.getValidCheckInFrom() == null ? ".." : formatter.format(tc.getValidCheckInFrom(event.getZoneId()));
        String to = tc.getValidCheckInTo() == null ? ".." : formatter.format(tc.getValidCheckInTo(event.getZoneId()));
        String formattedNow = formatter.format(now);
        return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(INVALID_TICKET_CATEGORY_CHECK_IN_DATE, String.format("Invalid check-in date: valid range for category %s is from %s to %s, current time is: %s", tc.getName(), from, to, formattedNow)));
    }
    log.trace("scanned code is {}", code);
    log.trace("true code    is {}", ticket.ticketCode(event.getPrivateKey()));
    if (!code.equals(ticket.ticketCode(event.getPrivateKey()))) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(INVALID_TICKET_CODE, "Ticket qr code does not match"));
    }
    final TicketStatus ticketStatus = ticket.getStatus();
    if (ticketStatus == TicketStatus.TO_BE_PAID) {
        return new TicketAndCheckInResult(ticket, new OnSitePaymentResult(MUST_PAY, "Must pay for ticket", MonetaryUtil.centsToUnit(ticket.getFinalPriceCts()), event.getCurrency()));
    }
    if (ticketStatus == TicketStatus.CHECKED_IN) {
        return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(ALREADY_CHECK_IN, "Error: already checked in"));
    }
    if (ticket.getStatus() != TicketStatus.ACQUIRED) {
        return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(INVALID_TICKET_STATE, "Invalid ticket state, expected ACQUIRED state, received " + ticket.getStatus()));
    }
    return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(OK_READY_TO_BE_CHECKED_IN, "Ready to be checked in"));
}
Also used : OnSitePaymentResult(alfio.manager.support.OnSitePaymentResult) TicketAndCheckInResult(alfio.manager.support.TicketAndCheckInResult) ZonedDateTime(java.time.ZonedDateTime) StringUtils(org.apache.commons.lang3.StringUtils) TicketStatus(alfio.model.Ticket.TicketStatus) DefaultCheckInResult(alfio.manager.support.DefaultCheckInResult) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

DefaultCheckInResult (alfio.manager.support.DefaultCheckInResult)3 TicketAndCheckInResult (alfio.manager.support.TicketAndCheckInResult)3 ZonedDateTime (java.time.ZonedDateTime)2 OnSitePaymentResult (alfio.manager.support.OnSitePaymentResult)1 Event (alfio.model.Event)1 Ticket (alfio.model.Ticket)1 TicketStatus (alfio.model.Ticket.TicketStatus)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 StringUtils (org.apache.commons.lang3.StringUtils)1