Skip to content

Commit

Permalink
Merge pull request #1 from devoxx/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
cbellone committed May 31, 2018
2 parents 53b0efa + c9342a4 commit 44d2a8a
Show file tree
Hide file tree
Showing 40 changed files with 246 additions and 131 deletions.
12 changes: 8 additions & 4 deletions src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
@RequestParam(value = "lastName", required = false) String lastName,
@RequestParam(value = "email", required = false) String email,
@RequestParam(value = "billingAddress", required = false) String billingAddress,
@RequestParam(value = "customerReference", required = false) String customerReference,
@RequestParam(value = "hmac", required = false) String hmac,
@RequestParam(value = "postponeAssignment", required = false) Boolean postponeAssignment,
@RequestParam(value = "invoiceRequested", required = false) Boolean invoiceRequested,
Expand Down Expand Up @@ -129,6 +130,7 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
.addAttribute("hmac", hmac)
.addAttribute("postponeAssignment", Boolean.TRUE.equals(postponeAssignment))
.addAttribute("invoiceRequested", Boolean.TRUE.equals(invoiceRequested))
.addAttribute("customerReference", customerReference)
.addAttribute("showPostpone", !forceAssignment && Boolean.TRUE.equals(postponeAssignment));
} else {
model.addAttribute("paypalCheckoutConfirmation", false)
Expand Down Expand Up @@ -178,7 +180,8 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
.addAttribute("invoiceIsAllowed", invoiceAllowed)
.addAttribute("onlyInvoice", onlyInvoice)
.addAttribute("vatNrIsLinked", orderSummary.isVatExempt() || paymentForm.getHasVatCountryCode())
.addAttribute("billingAddressLabel", invoiceAllowed ? "reservation-page.billing-address" : "reservation-page.receipt-address");
.addAttribute("billingAddressLabel", invoiceAllowed ? "reservation-page.billing-address" : "reservation-page.receipt-address")
.addAttribute("customerReferenceEnabled", configurationManager.getBooleanConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ENABLE_CUSTOMER_REFERENCE), false));

boolean includeStripe = !orderSummary.getFree() && activePaymentMethods.contains(PaymentProxy.STRIPE);
model.addAttribute("includeStripe", includeStripe);
Expand Down Expand Up @@ -456,7 +459,7 @@ public String handleReservation(@PathVariable("eventName") String eventName,
OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event, locale);
try {
String checkoutUrl = paymentManager.createPayPalCheckoutRequest(event, reservationId, orderSummary, customerName,
paymentForm.getEmail(), paymentForm.getBillingAddress(), locale, paymentForm.isPostponeAssignment(),
paymentForm.getEmail(), paymentForm.getBillingAddress(), paymentForm.getCustomerReference(), locale, paymentForm.isPostponeAssignment(),
paymentForm.isInvoiceRequested());
assignTickets(eventName, reservationId, paymentForm, bindingResult, request, true);
return "redirect:" + checkoutUrl;
Expand Down Expand Up @@ -488,8 +491,9 @@ public String handleReservation(@PathVariable("eventName") String eventName,
//

final PaymentResult status = ticketReservationManager.confirm(paymentForm.getToken(), paymentForm.getPaypalPayerID(), event, reservationId, paymentForm.getEmail(),
customerName, locale, paymentForm.getBillingAddress(), reservationCost, SessionUtil.retrieveSpecialPriceSessionId(request),
Optional.ofNullable(paymentForm.getPaymentMethod()), paymentForm.isInvoiceRequested(), paymentForm.getVatCountryCode(), paymentForm.getVatNr(), ticketReservation.get().getVatStatus());
customerName, locale, paymentForm.getBillingAddress(), paymentForm.getCustomerReference(), reservationCost, SessionUtil.retrieveSpecialPriceSessionId(request),
Optional.ofNullable(paymentForm.getPaymentMethod()), paymentForm.isInvoiceRequested(), paymentForm.getVatCountryCode(),
paymentForm.getVatNr(), ticketReservation.get().getVatStatus());

if(!status.isSuccessful()) {
String errorMessageCode = status.getErrorCode().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public ResponseEntity<VatDetail> validateEUVat(@PathVariable("eventName") String
ticketReservationRepository.addReservationInvoiceOrReceiptModel(reservationId, Json.toJson(orderSummary));
ticketReservationRepository.updateTicketReservation(reservationId, t.getMiddle().getStatus().name(), paymentForm.getEmail(),
paymentForm.getFullName(), paymentForm.getFirstName(), paymentForm.getLastName(), locale.getLanguage(), billingAddress, null,
Optional.ofNullable(paymentForm.getPaymentMethod()).map(PaymentProxy::name).orElse(null));
Optional.ofNullable(paymentForm.getPaymentMethod()).map(PaymentProxy::name).orElse(null), paymentForm.getCustomerReference());
paymentForm.getTickets().forEach((ticketId, owner) -> {
if(isNotEmpty(owner.getEmail()) && ((isNotEmpty(owner.getFirstName()) && isNotEmpty(owner.getLastName())) || isNotEmpty(owner.getFullName()))) {
ticketHelper.preAssignTicket(eventName, reservationId, ticketId, owner, Optional.empty(), request, (tr) -> {}, Optional.empty());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/alfio/controller/form/PaymentForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class PaymentForm implements Serializable {
private String firstName;
private String lastName;
private String billingAddress;
private String customerReference;
private String hmac;
private Boolean cancelReservation;
private Boolean termAndConditionsAccepted;
Expand Down Expand Up @@ -157,6 +158,7 @@ public static PaymentForm fromExistingReservation(TicketReservation reservation)
form.setVatCountryCode(reservation.getVatCountryCode());
form.setVatNr(reservation.getVatNr());
form.setInvoiceRequested(reservation.isInvoiceRequested());
form.setCustomerReference(reservation.getCustomerReference());
return form;
}

Expand Down
15 changes: 10 additions & 5 deletions src/main/java/alfio/manager/AdminReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ private Result<Boolean> performUpdate(String reservationId, Event event, TicketR
ticketReservationRepository.updateValidity(reservationId, Date.from(arm.getExpiration().toZonedDateTime(event.getZoneId()).toInstant()));
if(arm.isUpdateContactData()) {
AdminReservationModification.CustomerData customerData = arm.getCustomerData();
ticketReservationRepository.updateTicketReservation(reservationId, r.getStatus().name(), customerData.getEmailAddress(), customerData.getFullName(),
customerData.getFirstName(), customerData.getLastName(), customerData.getUserLanguage(), customerData.getBillingAddress(), r.getConfirmationTimestamp(), Optional.ofNullable(r.getPaymentMethod()).map(PaymentProxy::name).orElse(null));
ticketReservationRepository.updateTicketReservation(reservationId, r.getStatus().name(), customerData.getEmailAddress(),
customerData.getFullName(), customerData.getFirstName(), customerData.getLastName(), customerData.getUserLanguage(),
customerData.getBillingAddress(), r.getConfirmationTimestamp(),
Optional.ofNullable(r.getPaymentMethod()).map(PaymentProxy::name).orElse(null), customerData.getCustomerReference());
}
arm.getTicketsInfo().stream()
.filter(TicketsInfo::isUpdateAttendees)
Expand Down Expand Up @@ -240,7 +242,7 @@ private Result<Triple<TicketReservation, List<Ticket>, Event>> loadReservation(S
private Result<Triple<TicketReservation, List<Ticket>, Event>> performConfirmation(String reservationId, Event event, TicketReservation original) {
try {
ticketReservationManager.completeReservation(event.getId(), reservationId, original.getEmail(), new CustomerName(original.getFullName(), original.getFirstName(), original.getLastName(), event),
Locale.forLanguageTag(original.getUserLanguage()), original.getBillingAddress(), Optional.empty(), PaymentProxy.ADMIN);
Locale.forLanguageTag(original.getUserLanguage()), original.getBillingAddress(), Optional.empty(), PaymentProxy.ADMIN, original.getCustomerReference());
return loadReservation(reservationId);
} catch(Exception e) {
return Result.error(ErrorCode.ReservationError.UPDATE_FAILED);
Expand Down Expand Up @@ -299,9 +301,12 @@ private Result<Pair<TicketReservation, List<Ticket>>> createReservation(Result<L
String reservationId = UUID.randomUUID().toString();
String specialPriceSessionId = UUID.randomUUID().toString();
Date validity = Date.from(arm.getExpiration().toZonedDateTime(event.getZoneId()).toInstant());
ticketReservationRepository.createNewReservation(reservationId, ZonedDateTime.now(event.getZoneId()), validity, null, arm.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded());
ticketReservationRepository.createNewReservation(reservationId, ZonedDateTime.now(event.getZoneId()), validity, null,
arm.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded());
AdminReservationModification.CustomerData customerData = arm.getCustomerData();
ticketReservationRepository.updateTicketReservation(reservationId, TicketReservationStatus.PENDING.name(), customerData.getEmailAddress(), customerData.getFullName(), customerData.getFirstName(), customerData.getLastName(), arm.getLanguage(), null, null, null);
ticketReservationRepository.updateTicketReservation(reservationId, TicketReservationStatus.PENDING.name(), customerData.getEmailAddress(),
customerData.getFullName(), customerData.getFirstName(), customerData.getLastName(), arm.getLanguage(),
customerData.getBillingAddress(), null, null, customerData.getCustomerReference());

Result<List<Ticket>> result = flattenTicketsInfo(event, empty, t)
.map(pair -> reserveForTicketsInfo(event, arm, reservationId, specialPriceSessionId, pair))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private Stream<AdminReservationModification> spread(AdminReservationModification
.map(p -> {
AdminReservationModification.Attendee attendee = p.getLeft();
String language = StringUtils.defaultIfBlank(attendee.getLanguage(), src.getLanguage());
CustomerData cd = new CustomerData(attendee.getFirstName(), attendee.getLastName(), attendee.getEmailAddress(), null, language);
CustomerData cd = new CustomerData(attendee.getFirstName(), attendee.getLastName(), attendee.getEmailAddress(), null, language, null);
return new AdminReservationModification(src.getExpiration(), cd, singletonList(p.getRight()), language, src.isUpdateContactData(), src.getNotification());
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/alfio/manager/ExtensionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,15 @@ private void handleReservationRemoval(Event event, Collection<String> reservatio
}

public Optional<InvoiceGeneration> handleInvoiceGeneration(Event event, String reservationId, String email, CustomerName customerName, Locale userLanguage,
String billingAddress, TotalPrice reservationCost, boolean invoiceRequested,
String billingAddress, String customerReference, TotalPrice reservationCost, boolean invoiceRequested,
String vatCountryCode, String vatNr, PriceContainer.VatStatus vatStatus) {
Map<String, Object> payload = new HashMap<>();
payload.put("reservationId", reservationId);
payload.put("email", email);
payload.put("customerName", customerName);
payload.put("userLanguage", userLanguage);
payload.put("billingAddress", billingAddress);
payload.put("customerReference", customerReference);
payload.put("reservationCost", reservationCost);
payload.put("invoiceRequested", invoiceRequested);
payload.put("vatCountryCode", vatCountryCode);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/alfio/manager/PaymentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ public String getStripePublicKey(Event event) {
}

public String createPayPalCheckoutRequest(Event event, String reservationId, OrderSummary orderSummary,
CustomerName customerName, String email, String billingAddress,
CustomerName customerName, String email, String billingAddress, String customerReference,
Locale locale, boolean postponeAssignment, boolean invoiceRequested) throws Exception {
return paypalManager.createCheckoutRequest(event, reservationId, orderSummary, customerName, email,
billingAddress, locale, postponeAssignment, invoiceRequested);
billingAddress, customerReference, locale, postponeAssignment, invoiceRequested);
}

public boolean refund(TicketReservation reservation, Event event, Optional<Integer> amount, String username) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/alfio/manager/PaypalManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private List<Transaction> buildPaymentDetails(Event event, OrderSummary orderSum
}

public String createCheckoutRequest(Event event, String reservationId, OrderSummary orderSummary,
CustomerName customerName, String email, String billingAddress,
CustomerName customerName, String email, String billingAddress, String customerReference,
Locale locale, boolean postponeAssignment, boolean invoiceRequested) throws Exception {


Expand Down Expand Up @@ -156,6 +156,7 @@ public String createCheckoutRequest(Event event, String reservationId, OrderSumm
.queryParam("lastName", customerName.getLastName())
.queryParam("email", email)
.queryParam("billingAddress", billingAddress)
.queryParam("customerReference", customerReference)
.queryParam("postponeAssignment", postponeAssignment)
.queryParam("invoiceRequested", invoiceRequested)
.queryParam("hmac", computeHMAC(customerName, email, billingAddress, event));
Expand Down
Loading

0 comments on commit 44d2a8a

Please sign in to comment.