use of alfio.model.support.UserIdAndOrganizationId in project alf.io by alfio-event.
the class TicketReservationManager method completeReservation.
/**
* Set the tickets attached to the reservation to the ACQUIRED state and the ticket reservation to the COMPLETE state. Additionally it will save email/fullName/billingaddress/userLanguage.
*/
void completeReservation(PaymentSpecification spec, PaymentProxy paymentProxy, boolean sendReservationConfirmationEmail, boolean sendTickets, String username) {
String reservationId = spec.getReservationId();
var purchaseContext = spec.getPurchaseContext();
final TicketReservation reservation = ticketReservationRepository.findReservationById(reservationId);
// retrieve reservation owner if username is null
Integer userId;
if (username != null) {
userId = userRepository.getByUsername(username).getId();
} else {
userId = ticketReservationRepository.getReservationOwnerAndOrganizationId(reservationId).map(UserIdAndOrganizationId::getUserId).orElse(null);
}
Locale locale = LocaleUtil.forLanguageTag(reservation.getUserLanguage());
List<Ticket> tickets = null;
if (paymentProxy != PaymentProxy.OFFLINE) {
tickets = acquireItems(paymentProxy, reservationId, spec.getEmail(), spec.getCustomerName(), spec.getLocale().getLanguage(), spec.getBillingAddress(), spec.getCustomerReference(), spec.getPurchaseContext(), sendTickets);
extensionManager.handleReservationConfirmation(reservation, ticketReservationRepository.getBillingDetailsForReservation(reservationId), spec.getPurchaseContext());
}
Date eventTime = new Date();
auditingRepository.insert(reservationId, userId, purchaseContext, Audit.EventType.RESERVATION_COMPLETE, eventTime, Audit.EntityType.RESERVATION, reservationId);
ticketReservationRepository.updateRegistrationTimestamp(reservationId, ZonedDateTime.now(clockProvider.withZone(spec.getPurchaseContext().getZoneId())));
if (spec.isTcAccepted()) {
auditingRepository.insert(reservationId, userId, purchaseContext, Audit.EventType.TERMS_CONDITION_ACCEPTED, eventTime, Audit.EntityType.RESERVATION, reservationId, singletonList(singletonMap("termsAndConditionsUrl", spec.getPurchaseContext().getTermsAndConditionsUrl())));
}
if (eventHasPrivacyPolicy(spec.getPurchaseContext()) && spec.isPrivacyAccepted()) {
auditingRepository.insert(reservationId, userId, purchaseContext, Audit.EventType.PRIVACY_POLICY_ACCEPTED, eventTime, Audit.EntityType.RESERVATION, reservationId, singletonList(singletonMap("privacyPolicyUrl", spec.getPurchaseContext().getPrivacyPolicyUrl())));
}
if (sendReservationConfirmationEmail) {
TicketReservation updatedReservation = ticketReservationRepository.findReservationById(reservationId);
sendConfirmationEmailIfNecessary(updatedReservation, tickets, purchaseContext, locale, username);
sendReservationCompleteEmailToOrganizer(spec.getPurchaseContext(), updatedReservation, locale, username);
}
}
Aggregations