Skip to content

Commit

Permalink
#197 validate payment methods exsit for non-free events , update warn…
Browse files Browse the repository at this point in the history
…ing message
  • Loading branch information
Praitheesh committed Apr 8, 2017
1 parent bcb60a3 commit f5145ca
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/main/java/alfio/controller/EventController.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public String showEvent(@PathVariable("eventName") String eventName,
List<SaleableTicketCategory> validCategories = ticketCategories.stream().filter(tc -> !tc.getExpired()).collect(Collectors.toList());
List<SaleableAdditionalService> additionalServices = additionalServiceRepository.loadAllForEvent(event.getId()).stream().map((as) -> getSaleableAdditionalService(event, locale, as, promoCodeDiscount.orElse(null))).collect(Collectors.toList());
Predicate<SaleableTicketCategory> waitingQueueTargetCategory = tc -> !tc.getExpired() && !tc.isBounded();
boolean inValidOfflinePayment = event.getAllowedPaymentProxies().size() == 1 && event.getAllowedPaymentProxies().contains(PaymentProxy.OFFLINE) && !TicketReservationManager.hasValidOfflinePaymentWaitingPeriod(event, configurationManager);
boolean validPaymentConfigured = isEventHasValidPaymentConfigurations(event, configurationManager);
model.addAttribute("event", eventDescriptor)//
.addAttribute("organization", organizationRepository.getById(event.getOrganizationId()))
.addAttribute("ticketCategories", validCategories)//
Expand All @@ -242,9 +242,9 @@ public String showEvent(@PathVariable("eventName") String eventName,
.addAttribute("showAdditionalServices", !additionalServices.isEmpty())
.addAttribute("enabledAdditionalServices", additionalServices.stream().filter(SaleableAdditionalService::isNotExpired).collect(Collectors.toList()))
.addAttribute("disabledAdditionalServices", additionalServices.stream().filter(SaleableAdditionalService::isExpired).collect(Collectors.toList()))
.addAttribute("forwardButtonDisabled", (ticketCategories.stream().noneMatch(SaleableTicketCategory::getSaleable)) || inValidOfflinePayment)
.addAttribute("forwardButtonDisabled", (ticketCategories.stream().noneMatch(SaleableTicketCategory::getSaleable)) || !validPaymentConfigured)
.addAttribute("useFirstAndLastName", event.mustUseFirstAndLastName())
.addAttribute("validPaymentMethodAvailable", !inValidOfflinePayment);
.addAttribute("validPaymentMethodAvailable", validPaymentConfigured);

model.asMap().putIfAbsent("hasErrors", false);//
return "/event/show-event";
Expand Down Expand Up @@ -337,4 +337,15 @@ private static boolean shouldApplyDiscount(PromoCodeDiscount promoCodeDiscount,
return promoCodeDiscount.getCategories().isEmpty() || promoCodeDiscount.getCategories().contains(ticketCategory.getId());
}

private boolean isEventHasValidPaymentConfigurations(Event event, ConfigurationManager configurationManager) {
if (event.isFreeOfCharge()) {
return true;
} else if (event.getAllowedPaymentProxies().size() == 0) {
return false;
} else {
//Check whether event already started and it has only PaymentProxy.OFFLINE as payment method
return !(event.getAllowedPaymentProxies().size() == 1 && event.getAllowedPaymentProxies().contains(PaymentProxy.OFFLINE) && !TicketReservationManager.hasValidOfflinePaymentWaitingPeriod(event, configurationManager));
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event, locale);
List<PaymentProxy> activePaymentMethods = paymentManager.getPaymentMethods(event.getOrganizationId())
.stream()
.filter(p -> p.isActive() && event.getAllowedPaymentProxies().contains(p.getPaymentProxy()) && !p.getPaymentProxy().equals(PaymentProxy.OFFLINE) || (p.getPaymentProxy().equals(PaymentProxy.OFFLINE) && p.isActive() && event.getAllowedPaymentProxies().contains(p.getPaymentProxy()) && TicketReservationManager.hasValidOfflinePaymentWaitingPeriod(event, configurationManager)))
.filter(p -> TicketReservationManager.isValidPaymentMethod(p, event, configurationManager))
.map(PaymentManager.PaymentMethod::getPaymentProxy)
.collect(toList());
model.addAttribute("multiplePaymentMethods" , activePaymentMethods.size() > 1 );
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,19 @@ public static boolean hasValidOfflinePaymentWaitingPeriod(Event event, Configura
}
}


/**
* ValidPaymentMethod should be configured in organisation and event. And if even already started then event should not have PaymentProxy.OFFLINE as only payment method
*
* @param paymentMethod
* @param event
* @param configurationManager
* @return
*/
public static boolean isValidPaymentMethod(PaymentManager.PaymentMethod paymentMethod, Event event, ConfigurationManager configurationManager) {
return paymentMethod.isActive() && event.getAllowedPaymentProxies().contains(paymentMethod.getPaymentProxy()) && (!paymentMethod.getPaymentProxy().equals(PaymentProxy.OFFLINE) || hasValidOfflinePaymentWaitingPeriod(event, configurationManager));
}

private void reTransitionToPending(String reservationId) {
int updatedReservation = ticketReservationRepository.updateTicketStatus(reservationId, TicketReservationStatus.PENDING.toString());
Validate.isTrue(updatedReservation == 1, "expected exactly one updated reservation, got "+updatedReservation);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/alfio/i18n/public.properties
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ show-event.sold-out.message=Subscribe to the waiting queue and we''ll inform you
show-event.sold-out.subscribe=subscribe
show-event.sold-out.subscription-complete=Thank you for joining the waiting queue. We''ll keep you posted!
show-event.sold-out.subscription-error=Something went wrong, please retry in few minutes. Thank you!
show-event.offline-payment-not-available=We''re sorry, Cannot confirm an offline reservation after event start.
show-event.offline-payment-not-available=Due to a wrong configuration, it''s not possible to sell tickets right now. Please contact the organizers.

email-waiting-queue.subscribed.subject=You joined the waiting queue for {0}
email-waiting-queue.subscribed.text=As requested, you joined the waiting queue for the event {0}. We''ll keep you posted if something comes up\!
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/alfio/i18n/public_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ show-event.sold-out.message=Registrieren dich auf der Warteliste, sobald ein Pla
show-event.sold-out.subscribe=abonnieren
show-event.sold-out.subscription-complete=Vielen Dank f\u00FCr die Teilnahme an unserer Warteliste. Wir halten dich auf dem Laufenden!
show-event.sold-out.subscription-error=Etwas ist schief gelaufen, bitte versuche es in einigen Minuten erneut. Vielen Dank!
show-event.offline-payment-not-available=DE-Due to a wrong configuration, it''s not possible to sell tickets right now. Please contact the organizers.

email-waiting-queue.subscribed.subject=Du bist der Warteliste beigetreten {0}
email-waiting-queue.subscribed.text=Wie gew\u00FCnscht, haben wir dich der Warteliste f\u00FCr die Veranstaltung {0} hinzugef\u00FCgt. \u00DCber Neuigkeiten halten wir dich auf dem Laufenden!
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/alfio/i18n/public_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ show-event.sold-out.message=Iscriviti alla lista d''attesa e verrai avvisato non
show-event.sold-out.subscribe=iscriviti
show-event.sold-out.subscription-complete=Grazie per esserti iscritto alla lista d''attesa. Ti terremo informato\!
show-event.sold-out.subscription-error=Iscrizione non riuscita. Per favore riprova tra qualche minuto, grazie\!
show-event.offline-payment-not-available=IT-Due to a wrong configuration, it''s not possible to sell tickets right now. Please contact the organizers.

email-waiting-queue.subscribed.subject=Conferma iscrizione alla lista d''attesa per {0}
email-waiting-queue.subscribed.admin.text=Qualcuno si \u00E8 aggiunto alla lista d''attesa ({0}) per {1}. Maggiori informazioni nell''admin area
email-waiting-queue.subscribed.text=Come richiesto, abbiamo aggiunto il tuo nome alla lista d''attesa per {0}. Ti faremo sapere non appena ci saranno novit\u00E0\!
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/alfio/i18n/public_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ show-event.sold-out.message=Abonneer op de wachtrij en wij zullen u een bericht
show-event.sold-out.subscribe=Abonneer
show-event.sold-out.subscription-complete=Dankuwel voor het abonneren op de wachtrij. We houden contact\!
show-event.sold-out.subscription-error=Er ging iets fout, probeer het opnieuw in een paar minuten.
show-event.offline-payment-not-available=NL-Due to a wrong configuration, it''s not possible to sell tickets right now. Please contact the organizers.

email-waiting-queue.subscribed.subject=U heeft zich geabonneerd op de wachtrij voor {0}
email-waiting-queue.subscribed.text=U heeft zich geabonneerd op de wachtrij voor {0}. We houden u op de hoogte\!
Expand Down

0 comments on commit f5145ca

Please sign in to comment.