-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #464 import initial model changes * #464 import stubs for new flow * #464 make the free flow work: still WIP * #464 add text/breadcrumb * #464 handle back, fix test * #464 remove payment form from the reservation-page.ms * #464 enable stripe, refactor * #464 re-enable paypal * #464 remove term and condition links from reservation-page + handle them correctly after paypal redirect * #464 fix test * #464 re enable validation for step2, highlight errors * #464 select label * #464 reset form before cancel * #464 split PaymentForm * #464 initial work for mandatory invoice ui/ux * #464 hide billing fields for _not_ invoice only mode * #464 invoice available mode: show checkbox * #464 invoice available mode: invoice details section, initial work * #464 invoice details form * #464 translations * #464 translations * #464 add vat nr input, wire up select country to vat nr label * #464 initial billing validation
- Loading branch information
Showing
28 changed files
with
1,445 additions
and
719 deletions.
There are no files selected for viewing
301 changes: 196 additions & 105 deletions
301
src/main/java/alfio/controller/ReservationController.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
src/main/java/alfio/controller/form/ContactAndTicketsForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/** | ||
* This file is part of alf.io. | ||
* | ||
* alf.io is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* alf.io is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with alf.io. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package alfio.controller.form; | ||
|
||
import alfio.manager.EuVatChecker; | ||
import alfio.model.*; | ||
import alfio.model.result.ValidationResult; | ||
import alfio.util.ErrorsCode; | ||
import alfio.util.Validator; | ||
import lombok.Data; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.ValidationUtils; | ||
|
||
import java.io.Serializable; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
import static alfio.util.ErrorsCode.STEP_2_INVALID_VAT; | ||
import static alfio.util.ErrorsCode.STEP_2_MISSING_ATTENDEE_DATA; | ||
|
||
// step 2 : contact/claim tickets | ||
// | ||
@Data | ||
public class ContactAndTicketsForm implements Serializable { | ||
|
||
private String email; | ||
private String fullName; | ||
private String firstName; | ||
private String lastName; | ||
private String billingAddress; | ||
private String customerReference; | ||
private Boolean cancelReservation; | ||
|
||
private Boolean expressCheckoutRequested; | ||
private boolean postponeAssignment = false; | ||
private String vatCountryCode; | ||
private String vatNr; | ||
private boolean invoiceRequested = false; | ||
private Map<String, UpdateTicketOwnerForm> tickets = new HashMap<>(); | ||
// | ||
private String billingAddressCompany; | ||
private String billingAddressLine1; | ||
private String billingAddressLine2; | ||
private String billingAddressZip; | ||
private String billingAddressCity; | ||
|
||
private boolean addCompanyBillingDetails = false; | ||
private Boolean backFromOverview; | ||
|
||
private static void rejectIfOverLength(BindingResult bindingResult, String field, String errorCode, | ||
String value, int maxLength) { | ||
if (value != null && value.length() > maxLength) { | ||
bindingResult.rejectValue(field, errorCode); | ||
} | ||
} | ||
|
||
|
||
|
||
public void validate(BindingResult bindingResult, Event event, List<TicketFieldConfiguration> fieldConf, EuVatChecker.SameCountryValidator vatValidator) { | ||
|
||
|
||
|
||
email = StringUtils.trim(email); | ||
|
||
fullName = StringUtils.trim(fullName); | ||
firstName = StringUtils.trim(firstName); | ||
lastName = StringUtils.trim(lastName); | ||
|
||
billingAddress = StringUtils.trim(billingAddress); | ||
|
||
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "email", ErrorsCode.STEP_2_EMPTY_EMAIL); | ||
rejectIfOverLength(bindingResult, "email", ErrorsCode.STEP_2_MAX_LENGTH_EMAIL, email, 255); | ||
|
||
if(event.mustUseFirstAndLastName()) { | ||
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "firstName", ErrorsCode.STEP_2_EMPTY_FIRSTNAME); | ||
rejectIfOverLength(bindingResult, "firstName", ErrorsCode.STEP_2_MAX_LENGTH_FIRSTNAME, fullName, 255); | ||
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "lastName", ErrorsCode.STEP_2_EMPTY_LASTNAME); | ||
rejectIfOverLength(bindingResult, "lastName", ErrorsCode.STEP_2_MAX_LENGTH_LASTNAME, fullName, 255); | ||
} else { | ||
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "fullName", ErrorsCode.STEP_2_EMPTY_FULLNAME); | ||
rejectIfOverLength(bindingResult, "fullName", ErrorsCode.STEP_2_MAX_LENGTH_FULLNAME, fullName, 255); | ||
} | ||
|
||
|
||
|
||
if(invoiceRequested) { | ||
/*if(companyVatChecked) { | ||
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "billingAddressCompany", "error.emptyField"); | ||
rejectIfOverLength(bindingResult, "billingAddressCompany", "error.tooLong", billingAddressCompany, 256); | ||
}*/ | ||
|
||
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "billingAddressLine1", "error.emptyField"); | ||
rejectIfOverLength(bindingResult, "billingAddressLine1", "error.tooLong", billingAddressLine1, 256); | ||
|
||
rejectIfOverLength(bindingResult, "billingAddressLine2", "error.tooLong", billingAddressLine2, 256); | ||
|
||
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "billingAddressZip", "error.emptyField"); | ||
rejectIfOverLength(bindingResult, "billingAddressZip", "error.tooLong", billingAddressZip, 51); | ||
|
||
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "billingAddressCity", "error.emptyField"); | ||
rejectIfOverLength(bindingResult, "billingAddressCity", "error.tooLong", billingAddressCity, 256); | ||
} | ||
|
||
if (email != null && !email.contains("@") && !bindingResult.hasFieldErrors("email")) { | ||
bindingResult.rejectValue("email", ErrorsCode.STEP_2_INVALID_EMAIL); | ||
} | ||
|
||
if(!postponeAssignment) { | ||
Optional<List<ValidationResult>> validationResults = Optional.ofNullable(tickets) | ||
.filter(m -> !m.isEmpty()) | ||
.map(m -> m.entrySet().stream().map(e -> Validator.validateTicketAssignment(e.getValue(), | ||
fieldConf, Optional.of(bindingResult), event, "tickets[" + e.getKey() + "]", vatValidator))) | ||
.map(s -> s.collect(Collectors.toList())); | ||
|
||
boolean success = validationResults | ||
.filter(l -> l.stream().allMatch(ValidationResult::isSuccess)) | ||
.isPresent(); | ||
if(!success) { | ||
String errorCode = validationResults.filter(this::containsVatValidationError).isPresent() ? STEP_2_INVALID_VAT : STEP_2_MISSING_ATTENDEE_DATA; | ||
bindingResult.reject(errorCode); | ||
} | ||
} | ||
} | ||
|
||
private boolean containsVatValidationError(List<ValidationResult> l) { | ||
return l.stream().anyMatch(v -> !v.isSuccess() && v.getErrorDescriptors().stream().anyMatch(ed -> ed.getCode().equals(STEP_2_INVALID_VAT))); | ||
} | ||
|
||
public Boolean shouldCancelReservation() { | ||
return Optional.ofNullable(cancelReservation).orElse(false); | ||
} | ||
|
||
public static ContactAndTicketsForm fromExistingReservation(TicketReservation reservation, TicketReservationAdditionalInfo additionalInfo) { | ||
ContactAndTicketsForm form = new ContactAndTicketsForm(); | ||
form.setFirstName(reservation.getFirstName()); | ||
form.setLastName(reservation.getLastName()); | ||
form.setBillingAddress(reservation.getBillingAddress()); | ||
form.setEmail(reservation.getEmail()); | ||
form.setFullName(reservation.getFullName()); | ||
form.setVatCountryCode(reservation.getVatCountryCode()); | ||
form.setVatNr(reservation.getVatNr()); | ||
form.setInvoiceRequested(reservation.isInvoiceRequested()); | ||
form.setCustomerReference(reservation.getCustomerReference()); | ||
|
||
|
||
form.setBillingAddressCompany(additionalInfo.getBillingAddressCompany()); | ||
form.setBillingAddressLine1(additionalInfo.getBillingAddressLine1()); | ||
form.setBillingAddressLine2(additionalInfo.getBillingAddressLine2()); | ||
form.setBillingAddressZip(additionalInfo.getBillingAddressZip()); | ||
form.setBillingAddressCity(additionalInfo.getBillingAddressCity()); | ||
return form; | ||
} | ||
|
||
public boolean getHasVatCountryCode() { | ||
return !StringUtils.isEmpty(vatCountryCode); | ||
} | ||
|
||
public boolean isBackFromOverview() { | ||
return Optional.ofNullable(backFromOverview).orElse(false); | ||
} | ||
} |
Oops, something went wrong.