Skip to content

Commit

Permalink
#22 - more user-friendly codes
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Dec 30, 2014
1 parent 76a4510 commit 0fcdcaa
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 32 deletions.
10 changes: 6 additions & 4 deletions src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ public String showWaitingPaymentPage(@PathVariable("eventName") String eventName
TicketReservationStatus status = reservation.map(TicketReservation::getStatus).orElse(TicketReservationStatus.PENDING);
if(reservation.isPresent() && status == TicketReservationStatus.OFFLINE_PAYMENT) {
Event ev = event.get();
TicketReservation ticketReservation = reservation.get();
OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, ev);
model.addAttribute("totalPrice", orderSummary.getTotalPrice());
model.addAttribute("emailAddress", organizationRepository.getById(ev.getOrganizationId()).getEmail());
model.addAttribute("reservation", reservation.get());
model.addAttribute("reservation", ticketReservation);
model.addAttribute("paymentReason", ticketReservationManager.getShortReservationID(reservationId));
model.addAttribute("pageTitle", "reservation-page-waiting.header.title");
model.addAttribute("bankAccount", configurationManager.getStringConfigValue(ConfigurationKeys.BANK_ACCOUNT_NR).orElse(""));
model.addAttribute("expires", ZonedDateTime.ofInstant(reservation.get().getValidity().toInstant(), ev.getZoneId()));
model.addAttribute("expires", ZonedDateTime.ofInstant(ticketReservation.getValidity().toInstant(), ev.getZoneId()));
model.addAttribute("event", ev);
return "/event/reservation-waiting-for-payment";
}
Expand Down Expand Up @@ -449,9 +451,9 @@ private void sendReservationCompleteEmail(HttpServletRequest request, Event even
Locale locale = RequestContextUtils.getLocale(request);
String reservationTxt = templateManager.renderClassPathResource("/alfio/templates/confirmation-email-txt.ms",
ticketReservationManager.prepareModelForReservationEmail(event, reservation), locale);

String shortReservationID = ticketReservationManager.getShortReservationID(reservation.getId());
mailer.send(reservation.getEmail(), messageSource.getMessage("reservation-email-subject",
new Object[] { event.getShortName() }, locale), reservationTxt,
new Object[] { shortReservationID, event.getShortName() }, locale), reservationTxt,
Optional.empty());
}

Expand Down
17 changes: 0 additions & 17 deletions src/main/java/alfio/controller/support/TemplateProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import alfio.manager.support.PDFTemplateGenerator;
import alfio.manager.support.PartialTicketPDFGenerator;
import alfio.manager.support.PartialTicketTextGenerator;
import alfio.manager.support.TextTemplateGenerator;
import alfio.model.Event;
import alfio.model.Ticket;
import alfio.model.TicketCategory;
Expand All @@ -46,22 +45,6 @@ public final class TemplateProcessor {

private TemplateProcessor() {}

public static TextTemplateGenerator buildEmail(Event event,
OrganizationRepository organizationRepository,
TicketReservation ticketReservation,
Ticket ticket,
TemplateManager templateManager,
HttpServletRequest request) {
return (() -> {
Map<String, Object> model = new HashMap<>();
model.put("organization", organizationRepository.getById(event.getOrganizationId()));
model.put("event", event);
model.put("ticketReservation", ticketReservation);
model.put("ticket", ticket);
return templateManager.renderClassPathResource("/alfio/templates/ticket-email-txt.ms", model, RequestContextUtils.getLocale(request));
});
}

public static PartialTicketTextGenerator buildPartialEmail(Event event,
OrganizationRepository organizationRepository,
TicketReservation ticketReservation,
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/alfio/manager/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,12 @@ public void confirmPayment(String eventName, String reservationId, BigDecimal pa
Optional<Event> eventOptional = optionally(() -> getSingleEvent(eventName, username));
Validate.isTrue(eventOptional.isPresent(), "Event not found");
Event event = eventOptional.get();
Optional<OrderSummary> optionalOrderSummary = optionally(() -> ticketReservationManager.orderSummaryForReservationId(reservationId, event));
TicketReservation reservation = ticketReservationManager.findByPartialID(reservationId);
Optional<OrderSummary> optionalOrderSummary = optionally(() -> ticketReservationManager.orderSummaryForReservationId(reservation.getId(), event));
Validate.isTrue(optionalOrderSummary.isPresent(), "Reservation not found");
OrderSummary orderSummary = optionalOrderSummary.get();
Validate.isTrue(MonetaryUtil.centsToUnit(orderSummary.getOriginalTotalPrice().getPriceWithVAT()).compareTo(paidAmount) == 0, "paid price differs from due price");
ticketReservationManager.confirmOfflinePayment(event, reservationId);
ticketReservationManager.confirmOfflinePayment(event, reservation.getId());
}

public void deletePendingOfflinePayment(String eventName, String reservationId, String username) {
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@

import static alfio.model.TicketReservation.TicketReservationStatus.IN_PAYMENT;
import static alfio.model.TicketReservation.TicketReservationStatus.OFFLINE_PAYMENT;
import static alfio.model.system.ConfigurationKeys.OFFLINE_PAYMENT_DAYS;
import static alfio.model.system.ConfigurationKeys.OFFLINE_REMINDER_HOURS;
import static alfio.model.system.ConfigurationKeys.*;
import static alfio.util.MonetaryUtil.formatCents;
import static alfio.util.OptionalWrapper.optionally;
import static org.apache.commons.lang3.time.DateUtils.addHours;
Expand Down Expand Up @@ -242,7 +241,7 @@ public void confirmOfflinePayment(Event event, String reservationId) {
acquireTickets(TicketStatus.ACQUIRED, PaymentProxy.OFFLINE, reservationId, ticketReservation.getEmail(), ticketReservation.getFullName(), ticketReservation.getBillingAddress());
Locale language = ticketRepository.findTicketsInReservation(reservationId).stream().findFirst().map(t -> Locale.forLanguageTag(t.getUserLanguage())).orElse(Locale.ENGLISH);
notificationManager.sendSimpleEmail(ticketReservation.getEmail(), messageSource.getMessage("reservation-email-subject",
new Object[]{event.getShortName()}, language), () -> templateManager.renderClassPathResource("/alfio/templates/confirmation-email-txt.ms", prepareModelForReservationEmail(event, ticketReservation), language));
new Object[]{ getShortReservationID(reservationId), event.getShortName()}, language), () -> templateManager.renderClassPathResource("/alfio/templates/confirmation-email-txt.ms", prepareModelForReservationEmail(event, ticketReservation), language));
}

public void deleteOfflinePayment(Event singleEvent, String reservationId) {
Expand Down Expand Up @@ -592,7 +591,20 @@ public void sendReminderForOfflinePayments() {
model.put("expirationDate", ZonedDateTime.ofInstant(reservation.getValidity().toInstant(), event.getZoneId()));
Locale locale = p.getRight();
ticketReservationRepository.flagAsReminderSent(reservation.getId());
notificationManager.sendSimpleEmail(reservation.getEmail(), messageSource.getMessage("reservation.reminder.mail.subject", null, locale), () -> templateManager.renderClassPathResource("/alfio/templates/reminder-email-txt.ms", model, locale));
notificationManager.sendSimpleEmail(reservation.getEmail(), messageSource.getMessage("reservation.reminder.mail.subject", new Object[]{ getShortReservationID(reservation.getId()) }, locale), () -> templateManager.renderClassPathResource("/alfio/templates/reminder-email-txt.ms", model, locale));
});
}

public TicketReservation findByPartialID(String reservationId) {
Validate.notBlank(reservationId, "invalid reservationId");
Validate.matchesPattern(reservationId, "^[^%]*$", "invalid character found");
List<TicketReservation> results = ticketReservationRepository.findByPartialID(StringUtils.trimToEmpty(reservationId).toLowerCase() + "%");
Validate.isTrue(results.size() > 0, "reservation not found");
Validate.isTrue(results.size() == 1, "multiple results found. Try handling this reservation manually.");
return results.get(0);
}

public String getShortReservationID(String reservationId) {
return StringUtils.substring(reservationId, 0, configurationManager.getIntConfigValue(PARTIAL_RESERVATION_ID_LENGTH, 8)).toUpperCase();
}
}
1 change: 1 addition & 0 deletions src/main/java/alfio/model/system/ConfigurationKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum ConfigurationKeys {
OFFLINE_PAYMENT_DAYS("Maximum number of days allowed to pay an offline ticket", false),
OFFLINE_REMINDER_HOURS("How many hours before expiration should be sent a reminder e-mail for offline payments?", false),
BANK_ACCOUNT_NR("Bank Account number", false),
PARTIAL_RESERVATION_ID_LENGTH("Partial reservationID length", false),
//

//mailgun configuration related info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ int postponePayment(@Bind("reservationId") String reservationId, @Bind("validity

@Query("delete from tickets_reservation where id in (:ids)")
int remove(@Bind("ids") List<String> ids);

@Query("select * from tickets_reservation where id like :partialID")
List<TicketReservation> findByPartialID(@Bind("partialID") String partialID);
}
4 changes: 2 additions & 2 deletions src/main/resources/alfio/i18n/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ email.ticket-email-sent=The ticket has been sent by email.

#email
ticket-email-subject=Your ticket for event {0}
reservation-email-subject=Your reservation for event {0}
reservation-email-subject=Your reservation n. {0} for event {1}
ticket-has-changed-owner-subject=Notice: your ticket for event {0} has changed email owner

#ticket-email-txt
Expand Down Expand Up @@ -210,5 +210,5 @@ reservation-page-waiting.required-steps.1=Transfer the amount of <strong>{0}</st
reservation-page-waiting.required-steps.2=Send us an e-mail (<a href="mailto\:{0}?subject={1}">{0}</a>) with the proof of payment
reservation-page-waiting.required-steps.3=That''s it! After that you''ll receive a confirmation e-mail.
reservation.not-yet-paid=WARNING: You must pay the amount of {0} in order to attend the event
reservation.reminder.mail.subject=Your reservation is about to expire
reservation.reminder.mail.subject=Your reservation {0} is about to expire
reservation.reminder.mail=Your Reservation for the Event {0} (ID {1}) will expire on {2}. In order to confirm it, please follow the payment instructions stated on {3}
4 changes: 2 additions & 2 deletions src/main/resources/alfio/i18n/application_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ email.ticket-email-sent=Il biglietto ti \u00E8 stato spedito via email.

#email
ticket-email-subject=Il tuo biglietto per l''evento {0}
reservation-email-subject=La tua prenotazione per l''evento {0}
reservation-email-subject=La tua prenotazione n. {0} per l''evento {1}
ticket-has-changed-owner-subject=Avviso\: l''email associata al tuo biglietto per l''evento {0} \u00E8 stata modificata

#ticket-email-txt
Expand Down Expand Up @@ -201,5 +201,5 @@ reservation-page-waiting.required-steps.1=Invia l''importo di <strong>{0}</stron
reservation-page-waiting.required-steps.2=Inviaci una e-mail all''indirizzo <a href="mailto\:{0}?subject={1}">{0}</a> con la prova di avvenuto trasferimento
reservation-page-waiting.required-steps.3=\u00C8 tutto! Dopo che il pagamento sar\u00E0 verificato, riceverai una e-mail di conferma e potrai scaricare i biglietti.
reservation.not-yet-paid=ATTENZIONE: Sei tenuto a saldare l''ammontare di {0} per partecipare all''evento!
reservation.reminder.mail.subject=La tua prenotazione sta per scadere
reservation.reminder.mail.subject=La tua prenotazione {0} sta per scadere
reservation.reminder.mail=La tua prenotazione per l''evento {0} (ID {1}) scadr\u00E0 il {2}. Per confermarla, per favore segui le istruzioni per il pagamento alla pagina {3}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="wMarginBottom wMarginTop center-block">
<h4>{{#i18n}}reservation-page-waiting.required-steps{{/i18n}}</h4>
<ol>
<li>{{#i18n}}reservation-page-waiting.required-steps.1 [{{event.currency}} {{totalPrice}}] [{{bankAccount}}] [{{reservation.id}}]{{/i18n}}</li>
<li>{{#i18n}}reservation-page-waiting.required-steps.1 [{{event.currency}} {{totalPrice}}] [{{bankAccount}}] [{{paymentReason}}]{{/i18n}}</li>
<li>{{#i18n}}reservation-page-waiting.required-steps.2 [{{emailAddress}}] [{{reservation.id}}]{{/i18n}}</li>
<li>{{#i18n}}reservation-page-waiting.required-steps.3{{/i18n}}</li>
</ol>
Expand Down

0 comments on commit 0fcdcaa

Please sign in to comment.