17
17
package alfio .controller ;
18
18
19
19
import alfio .controller .api .support .TicketHelper ;
20
+ import alfio .controller .form .ContactAndTicketsForm ;
20
21
import alfio .controller .form .PaymentForm ;
21
22
import alfio .controller .form .UpdateTicketOwnerForm ;
22
23
import alfio .controller .support .SessionUtil ;
@@ -85,9 +86,7 @@ public class ReservationController {
85
86
private final TicketHelper ticketHelper ;
86
87
private final TicketFieldRepository ticketFieldRepository ;
87
88
private final PaymentManager paymentManager ;
88
- private final TicketRepository ticketRepository ;
89
89
private final EuVatChecker vatChecker ;
90
- private final MollieManager mollieManager ;
91
90
private final RecaptchaService recaptchaService ;
92
91
private final TicketReservationRepository ticketReservationRepository ;
93
92
@@ -146,7 +145,7 @@ public String showBookingPage(@PathVariable("eventName") String eventName,
146
145
147
146
boolean invoiceAllowed = configurationManager .hasAllConfigurationsForInvoice (event ) || vatChecker .isVatCheckingEnabledFor (event .getOrganizationId ());
148
147
boolean onlyInvoice = invoiceAllowed && configurationManager .getBooleanConfigValue (partialConfig .apply (ConfigurationKeys .GENERATE_ONLY_INVOICE ), false );
149
- PaymentForm paymentForm = PaymentForm .fromExistingReservation (reservation );
148
+ ContactAndTicketsForm contactAndTicketsForm = ContactAndTicketsForm .fromExistingReservation (reservation );
150
149
model .addAttribute ("multiplePaymentMethods" , activePaymentMethods .size () > 1 )
151
150
.addAttribute ("orderSummary" , orderSummary )
152
151
.addAttribute ("reservationId" , reservationId )
@@ -162,13 +161,13 @@ public String showBookingPage(@PathVariable("eventName") String eventName,
162
161
.addAttribute ("euVatCheckingEnabled" , vatChecker .isVatCheckingEnabledFor (event .getOrganizationId ()))
163
162
.addAttribute ("invoiceIsAllowed" , invoiceAllowed )
164
163
.addAttribute ("onlyInvoice" , onlyInvoice )
165
- .addAttribute ("vatNrIsLinked" , orderSummary .isVatExempt () || paymentForm .getHasVatCountryCode ())
164
+ .addAttribute ("vatNrIsLinked" , orderSummary .isVatExempt () || contactAndTicketsForm .getHasVatCountryCode ())
166
165
.addAttribute ("attendeeAutocompleteEnabled" , ticketsInReservation .size () == 1 && configurationManager .getBooleanConfigValue (partialConfig .apply (ENABLE_ATTENDEE_AUTOCOMPLETE ), true ))
167
166
.addAttribute ("billingAddressLabel" , invoiceAllowed ? "reservation-page.billing-address" : "reservation-page.receipt-address" )
168
167
.addAttribute ("customerReferenceEnabled" , configurationManager .getBooleanConfigValue (partialConfig .apply (ENABLE_CUSTOMER_REFERENCE ), false ));
169
168
170
169
Map <String , Object > modelMap = model .asMap ();
171
- modelMap .putIfAbsent ("paymentForm" , paymentForm );
170
+ modelMap .putIfAbsent ("paymentForm" , contactAndTicketsForm );
172
171
modelMap .putIfAbsent ("hasErrors" , false );
173
172
174
173
boolean hasPaidSupplement = ticketReservationManager .hasPaidSupplements (reservationId );
@@ -246,11 +245,11 @@ public String showConfirmationPage(@PathVariable("eventName") String eventName,
246
245
247
246
@ RequestMapping (value = "/event/{eventName}/reservation/{reservationId}/validate-to-overview" , method = RequestMethod .POST )
248
247
public String validateToOverview (@ PathVariable ("eventName" ) String eventName , @ PathVariable ("reservationId" ) String reservationId ,
249
- PaymentForm paymentForm , BindingResult bindingResult ,
248
+ ContactAndTicketsForm contactAndTicketsForm , BindingResult bindingResult ,
250
249
Model model , HttpServletRequest request , Locale locale , RedirectAttributes redirectAttributes ) {
251
250
252
251
Optional <Event > eventOptional = eventRepository .findOptionalByShortName (eventName );
253
- Optional <String > redirectForFailure = checkReservation (paymentForm .isBackFromOverview (), paymentForm .shouldCancelReservation (), eventName , reservationId , request , eventOptional );
252
+ Optional <String > redirectForFailure = checkReservation (contactAndTicketsForm .isBackFromOverview (), contactAndTicketsForm .shouldCancelReservation (), eventName , reservationId , request , eventOptional );
254
253
if (redirectForFailure .isPresent ()) { //ugly
255
254
return redirectForFailure .get ();
256
255
}
@@ -263,32 +262,32 @@ public String validateToOverview(@PathVariable("eventName") String eventName, @P
263
262
Configuration .ConfigurationPathKey forceAssignmentKey = Configuration .from (event .getOrganizationId (), event .getId (), ConfigurationKeys .FORCE_TICKET_OWNER_ASSIGNMENT_AT_RESERVATION );
264
263
boolean forceAssignment = configurationManager .getBooleanConfigValue (forceAssignmentKey , false );
265
264
if (forceAssignment ) {
266
- paymentForm .setPostponeAssignment (false );
265
+ contactAndTicketsForm .setPostponeAssignment (false );
267
266
}
268
267
269
268
Configuration .ConfigurationPathKey invoiceOnlyKey = Configuration .from (event .getOrganizationId (), event .getId (), ConfigurationKeys .GENERATE_ONLY_INVOICE );
270
269
boolean invoiceOnly = configurationManager .getBooleanConfigValue (invoiceOnlyKey , false );
271
270
272
- final boolean companyVatChecked = invoiceOnly ? paymentForm .isAddCompanyBillingDetails () : paymentForm .isInvoiceRequested ();
271
+ final boolean companyVatChecked = invoiceOnly ? contactAndTicketsForm .isAddCompanyBillingDetails () : contactAndTicketsForm .isInvoiceRequested ();
273
272
274
273
if (invoiceOnly && reservationCost .getPriceWithVAT () > 0 ) {
275
274
//override, that's why we save it
276
- paymentForm .setInvoiceRequested (true );
275
+ contactAndTicketsForm .setInvoiceRequested (true );
277
276
}
278
277
279
- CustomerName customerName = new CustomerName (paymentForm .getFullName (), paymentForm .getFirstName (), paymentForm .getLastName (), event , false );
278
+ CustomerName customerName = new CustomerName (contactAndTicketsForm .getFullName (), contactAndTicketsForm .getFirstName (), contactAndTicketsForm .getLastName (), event , false );
280
279
281
280
//persist data
282
- ticketReservationManager .updateReservation (reservationId , customerName , paymentForm .getEmail (),
283
- paymentForm .getBillingAddressCompany (), paymentForm .getBillingAddressLine1 (), paymentForm .getBillingAddressLine2 (),
284
- paymentForm .getBillingAddressZip (), paymentForm .getBillingAddressCity (), paymentForm .getVatCountryCode (),
285
- paymentForm .getCustomerReference (), paymentForm .getVatNr (), paymentForm .isInvoiceRequested (),
286
- paymentForm .isAddCompanyBillingDetails (), false );
287
- assignTickets (event .getShortName (), reservationId , paymentForm , bindingResult , request , true , true );
281
+ ticketReservationManager .updateReservation (reservationId , customerName , contactAndTicketsForm .getEmail (),
282
+ contactAndTicketsForm .getBillingAddressCompany (), contactAndTicketsForm .getBillingAddressLine1 (), contactAndTicketsForm .getBillingAddressLine2 (),
283
+ contactAndTicketsForm .getBillingAddressZip (), contactAndTicketsForm .getBillingAddressCity (), contactAndTicketsForm .getVatCountryCode (),
284
+ contactAndTicketsForm .getCustomerReference (), contactAndTicketsForm .getVatNr (), contactAndTicketsForm .isInvoiceRequested (),
285
+ contactAndTicketsForm .isAddCompanyBillingDetails (), false );
286
+ assignTickets (event .getShortName (), reservationId , contactAndTicketsForm , bindingResult , request , true , true );
288
287
//
289
288
290
289
//
291
- paymentForm .validate (bindingResult , event , ticketFieldRepository .findAdditionalFieldsForEvent (event .getId ()), new SameCountryValidator (vatChecker , event .getOrganizationId (), event .getId (), reservationId ));
290
+ contactAndTicketsForm .validate (bindingResult , event , ticketFieldRepository .findAdditionalFieldsForEvent (event .getId ()), new SameCountryValidator (vatChecker , event .getOrganizationId (), event .getId (), reservationId ));
292
291
//
293
292
294
293
if (bindingResult .hasErrors ()) {
@@ -499,8 +498,8 @@ private String redirectReservation(Optional<TicketReservation> ticketReservation
499
498
500
499
@ RequestMapping (value = "/event/{eventName}/reservation/{reservationId}" , method = RequestMethod .POST )
501
500
public String handleReservation (@ PathVariable ("eventName" ) String eventName ,
502
- @ PathVariable ("reservationId" ) String reservationId , PaymentForm paymentForm , BindingResult bindingResult ,
503
- Model model , HttpServletRequest request , Locale locale , RedirectAttributes redirectAttributes ) {
501
+ @ PathVariable ("reservationId" ) String reservationId , PaymentForm paymentForm , BindingResult bindingResult ,
502
+ Model model , HttpServletRequest request , Locale locale , RedirectAttributes redirectAttributes ) {
504
503
505
504
Optional <Event > eventOptional = eventRepository .findOptionalByShortName (eventName );
506
505
Optional <String > redirectForFailure = checkReservation (paymentForm .isBackFromOverview (), paymentForm .shouldCancelReservation (), eventName , reservationId , request , eventOptional );
@@ -525,28 +524,19 @@ public String handleReservation(@PathVariable("eventName") String eventName,
525
524
final TicketReservation ticketReservation = optionalReservation .get ();
526
525
527
526
final TotalPrice reservationCost = ticketReservationManager .totalReservationCostWithVAT (reservationId );
528
- if (isCaptchaInvalid (reservationCost .getPriceWithVAT (), paymentForm .getPaymentMethod (), request , event )) {
529
- log .debug ("captcha validation failed." );
530
- bindingResult .reject (ErrorsCode .STEP_2_CAPTCHA_VALIDATION_FAILED );
531
- }
532
527
533
- Configuration . ConfigurationPathKey forceAssignmentKey = Configuration . from ( event . getOrganizationId () , event . getId (), ConfigurationKeys . FORCE_TICKET_OWNER_ASSIGNMENT_AT_RESERVATION );
534
- boolean forceAssignment = configurationManager . getBooleanConfigValue ( forceAssignmentKey , false );
535
- if ( forceAssignment ) {
536
- paymentForm . setPostponeAssignment ( false );
528
+ paymentForm . validate ( bindingResult , event , reservationCost );
529
+ if ( bindingResult . hasErrors ()) {
530
+ SessionUtil . addToFlash ( bindingResult , redirectAttributes );
531
+ return redirectReservation ( optionalReservation , eventName , reservationId );
537
532
}
538
533
539
- Configuration .ConfigurationPathKey invoiceOnlyKey = Configuration .from (event .getOrganizationId (), event .getId (), ConfigurationKeys .GENERATE_ONLY_INVOICE );
540
- boolean invoiceOnly = configurationManager .getBooleanConfigValue (invoiceOnlyKey , false );
541
- if (invoiceOnly && reservationCost .getPriceWithVAT () > 0 ) {
542
- paymentForm .setInvoiceRequested (true );
534
+ if (isCaptchaInvalid (reservationCost .getPriceWithVAT (), paymentForm .getPaymentMethod (), request , event )) {
535
+ log .debug ("captcha validation failed." );
536
+ bindingResult .reject (ErrorsCode .STEP_2_CAPTCHA_VALIDATION_FAILED );
543
537
}
544
538
545
539
if (paymentForm .getPaymentMethod () != PaymentProxy .PAYPAL || !paymentForm .hasPaypalTokens ()) {
546
- //if(!paymentForm.isPostponeAssignment() && !ticketRepository.checkTicketUUIDs(reservationId, paymentForm.getTickets().keySet())) {
547
- //bindingResult.reject(ErrorsCode.STEP_2_MISSING_ATTENDEE_DATA);
548
- //}
549
- //paymentForm.validate(bindingResult, reservationCost, event, ticketFieldRepository.findAdditionalFieldsForEvent(event.getId()), new SameCountryValidator(vatChecker, event.getOrganizationId(), event.getId(), reservationId));
550
540
if (bindingResult .hasErrors ()) {
551
541
SessionUtil .addToFlash (bindingResult , redirectAttributes );
552
542
return redirectReservation (Optional .of (ticketReservation ), eventName , reservationId );
@@ -561,28 +551,7 @@ public String handleReservation(@PathVariable("eventName") String eventName,
561
551
OrderSummary orderSummary = ticketReservationManager .orderSummaryForReservationId (reservationId , event , locale );
562
552
try {
563
553
String checkoutUrl = paymentManager .createPayPalCheckoutRequest (event , reservationId , orderSummary , customerName ,
564
- paymentForm .getEmail (), paymentForm .getBillingAddress (), paymentForm .getCustomerReference (), locale , paymentForm .isPostponeAssignment (),
565
- paymentForm .isInvoiceRequested ());
566
- //assignTickets(eventName, reservationId, paymentForm, bindingResult, request, true, false);
567
- return "redirect:" + checkoutUrl ;
568
- } catch (Exception e ) {
569
- bindingResult .reject (ErrorsCode .STEP_2_PAYMENT_REQUEST_CREATION );
570
- SessionUtil .addToFlash (bindingResult , redirectAttributes );
571
- return redirectReservation (optionalReservation , eventName , reservationId );
572
- }
573
- }
574
-
575
- //handle mollie redirect
576
- if (paymentForm .getPaymentMethod () == PaymentProxy .MOLLIE ) {
577
- OrderSummary orderSummary = ticketReservationManager .orderSummaryForReservationId (reservationId , event , locale );
578
- try {
579
- String checkoutUrl = mollieManager .createCheckoutRequest (event , reservationId , orderSummary , customerName ,
580
- paymentForm .getEmail (), paymentForm .getBillingAddress (), locale ,
581
- paymentForm .isInvoiceRequested (),
582
- paymentForm .getVatCountryCode (),
583
- paymentForm .getVatNr (),
584
- optionalReservation .get ().getVatStatus ());
585
- //assignTickets(eventName, reservationId, paymentForm, bindingResult, request, true, false);
554
+ ticketReservation .getEmail (), ticketReservation .getBillingAddress (), ticketReservation .getCustomerReference (), locale );
586
555
return "redirect:" + checkoutUrl ;
587
556
} catch (Exception e ) {
588
557
bindingResult .reject (ErrorsCode .STEP_2_PAYMENT_REQUEST_CREATION );
@@ -620,9 +589,9 @@ private boolean isCaptchaInvalid(int cost, PaymentProxy paymentMethod, HttpServl
620
589
&& !recaptchaService .checkRecaptcha (request );
621
590
}
622
591
623
- private void assignTickets (String eventName , String reservationId , PaymentForm paymentForm , BindingResult bindingResult , HttpServletRequest request , boolean preAssign , boolean skipValidation ) {
624
- if (!paymentForm .isPostponeAssignment ()) {
625
- paymentForm .getTickets ().forEach ((ticketId , owner ) -> {
592
+ private void assignTickets (String eventName , String reservationId , ContactAndTicketsForm contactAndTicketsForm , BindingResult bindingResult , HttpServletRequest request , boolean preAssign , boolean skipValidation ) {
593
+ if (!contactAndTicketsForm .isPostponeAssignment ()) {
594
+ contactAndTicketsForm .getTickets ().forEach ((ticketId , owner ) -> {
626
595
if (preAssign ) {
627
596
Optional <Errors > bindingResultOptional = skipValidation ? Optional .empty () : Optional .of (bindingResult );
628
597
ticketHelper .preAssignTicket (eventName , reservationId , ticketId , owner , bindingResultOptional , request , (tr ) -> {
0 commit comments