Skip to content

Commit

Permalink
#464 re-enable paypal
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Jul 2, 2018
1 parent 4bbe045 commit cec1c53
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 61 deletions.
64 changes: 28 additions & 36 deletions src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,6 @@ public class ReservationController {
@RequestMapping(value = "/event/{eventName}/reservation/{reservationId}/book", method = RequestMethod.GET)
public String showBookingPage(@PathVariable("eventName") String eventName,
@PathVariable("reservationId") String reservationId,
//paypal related parameters
@RequestParam(value = "paymentId", required = false) String paypalPaymentId,
@RequestParam(value = "PayerID", required = false) String paypalPayerID,
@RequestParam(value = "paypal-success", required = false) Boolean isPaypalSuccess,
@RequestParam(value = "paypal-error", required = false) Boolean isPaypalError,
@RequestParam(value = "fullName", required = false) String fullName,
@RequestParam(value = "firstName", required = false) String firstName,
@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,
Model model,
Locale locale) {

Expand All @@ -119,31 +105,21 @@ public String showBookingPage(@PathVariable("eventName") String eventName,
return redirectReservation(Optional.of(reservation), eventName, reservationId);
}

TicketReservationAdditionalInfo additionalInfo = ticketReservationRepository.getAdditionalInfo(reservationId);
if (additionalInfo.hasBeenValidated()) {
return "redirect:/event/" + eventName + "/reservation/" + reservationId + "/overview";
}

Function<ConfigurationKeys, Configuration.ConfigurationPathKey> partialConfig = Configuration.from(event.getOrganizationId(), event.getId());

Configuration.ConfigurationPathKey forceAssignmentKey = partialConfig.apply(FORCE_TICKET_OWNER_ASSIGNMENT_AT_RESERVATION);
boolean forceAssignment = configurationManager.getBooleanConfigValue(forceAssignmentKey, false);

List<Ticket> ticketsInReservation = ticketReservationManager.findTicketsInReservation(reservationId);
if (Boolean.TRUE.equals(isPaypalSuccess) && paypalPayerID != null && paypalPaymentId != null) {
model.addAttribute("paypalPaymentId", paypalPaymentId)
.addAttribute("paypalPayerID", paypalPayerID)
.addAttribute("paypalCheckoutConfirmation", true)
.addAttribute("fullName", fullName)
.addAttribute("firstName", firstName)
.addAttribute("lastName", lastName)
.addAttribute("email", email)
.addAttribute("billingAddress", billingAddress)
.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)
.addAttribute("postponeAssignment", false)
.addAttribute("showPostpone", !forceAssignment && ticketsInReservation.size() > 1);
}

model.addAttribute("postponeAssignment", false)
.addAttribute("showPostpone", !forceAssignment && ticketsInReservation.size() > 1);


try {
model.addAttribute("delayForOfflinePayment", Math.max(1, TicketReservationManager.getOfflinePaymentWaitingPeriod(event, configurationManager)));
Expand Down Expand Up @@ -330,7 +306,14 @@ public String validateToOverview(@PathVariable("eventName") String eventName, @P
}

@RequestMapping(value = "/event/{eventName}/reservation/{reservationId}/overview", method = RequestMethod.GET)
public String showOverview(@PathVariable("eventName") String eventName, @PathVariable("reservationId") String reservationId, Locale locale, Model model) {
public String showOverview(@PathVariable("eventName") String eventName, @PathVariable("reservationId") String reservationId,
//paypal
@RequestParam(value = "paymentId", required = false) String paypalPaymentId,
@RequestParam(value = "PayerID", required = false) String paypalPayerID,
@RequestParam(value = "paypal-success", required = false) Boolean isPaypalSuccess,
@RequestParam(value = "paypal-error", required = false) Boolean isPaypalError,
//
Locale locale, Model model) {
return eventRepository.findOptionalByShortName(eventName)
.map(event -> ticketReservationManager.findById(reservationId)
.map(reservation -> {
Expand All @@ -342,6 +325,14 @@ public String showOverview(@PathVariable("eventName") String eventName, @PathVar
return "redirect:/event/" + eventName + "/reservation/" + reservationId + "/book";
}

if (Boolean.TRUE.equals(isPaypalSuccess) && paypalPayerID != null && paypalPaymentId != null) {
model.addAttribute("paypalPaymentId", paypalPaymentId)
.addAttribute("paypalPayerID", paypalPayerID)
.addAttribute("paypalCheckoutConfirmation", true);
} else {
model.addAttribute("paypalCheckoutConfirmation", false);
}


OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event, locale);

Expand Down Expand Up @@ -493,7 +484,8 @@ private String redirectReservation(Optional<TicketReservation> ticketReservation

switch(reservation.getStatus()) {
case PENDING:
return baseUrl + "/book";
TicketReservationAdditionalInfo additionalInfo = ticketReservationRepository.getAdditionalInfo(reservationId);
return additionalInfo.hasBeenValidated() ? baseUrl + "/overview" : baseUrl + "/book";
case COMPLETE:
return baseUrl + "/success";
case OFFLINE_PAYMENT:
Expand Down Expand Up @@ -720,7 +712,7 @@ private Optional<String> checkReservation(boolean backFromOverview, boolean canc
}

if (cancelReservation) {
ticketReservationManager.cancelPendingReservation(reservationId, false); //FIXME
ticketReservationManager.cancelPendingReservation(reservationId, false); //FIXME
SessionUtil.removeSpecialPriceData(request);
return Optional.of("redirect:/event/" + eventName + "/");
}
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/alfio/manager/PaypalManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,9 @@ public String createCheckoutRequest(Event event, String reservationId, OrderSumm
RedirectUrls redirectUrls = new RedirectUrls();

String baseUrl = StringUtils.removeEnd(configurationManager.getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.BASE_URL)), "/");
String bookUrl = baseUrl+"/event/" + eventName + "/reservation/" + reservationId + "/book";
String bookUrl = baseUrl+"/event/" + eventName + "/reservation/" + reservationId + "/overview";

UriComponentsBuilder bookUrlBuilder = UriComponentsBuilder.fromUriString(bookUrl)
.queryParam("fullName", customerName.getFullName())
.queryParam("firstName", customerName.getFirstName())
.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));
String finalUrl = bookUrlBuilder.toUriString();

Expand Down
14 changes: 14 additions & 0 deletions src/main/webapp/WEB-INF/templates/event/overview.ms
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@
</table>

<form action="{{request.contextPath}}/event/{{event.shortName}}/reservation/{{reservation.id}}" method="POST" id="payment-form">
{{#paypalCheckoutConfirmation}}
<input type="hidden" name="paymentMethod" value="PAYPAL">
<input type="hidden" name="paypalPaymentId" value="{{paypalPaymentId}}">
<input type="hidden" name="paypalPayerID" value="{{paypalPayerID}}">
<input type="hidden" name="termAndConditionsAccepted" value="true">
<div class="alert alert-success">
<h3><i class="fa fa-check"></i> {{#i18n}}reservation-page.paypal.confirm{{/i18n}}</h3>
</div>
{{/paypalCheckoutConfirmation}}
{{^paypalCheckoutConfirmation}}


{{^orderSummary.free}}
Expand Down Expand Up @@ -149,6 +159,8 @@
{{/orderSummary.free}}




{{#event.privacyPolicyLinkOrNull}}
<div class="checkbox wMarginTop wMarginBottom">
<label>
Expand All @@ -158,6 +170,8 @@
</div>
{{/event.privacyPolicyLinkOrNull}}

{{/paypalCheckoutConfirmation}}

<div class="checkbox wMarginTop wMarginBottom">
<label>
<input type="checkbox" required name="termAndConditionsAccepted" value="true">
Expand Down
21 changes: 5 additions & 16 deletions src/main/webapp/WEB-INF/templates/event/reservation-page.ms
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,11 @@
</label>
</div>

{{#orderSummary.free}}
<div class="row">
<div class="col-md-4 col-md-push-8 col-xs-12 wMarginBottom"><button type="submit" class="btn btn-success btn-block" id="continue-button">{{#i18n}}reservation-page.continue{{/i18n}}</button></div>
<div class="col-md-4 col-md-pull-4 col-xs-12"><button type="submit" class="btn btn-default btn-block" id="cancel-reservation">{{#i18n}}reservation-page.cancel{{/i18n}}</button></div>
</div>
{{/orderSummary.free}}
{{^orderSummary.free}}
<div class="row">
<div class="col-md-4 col-md-push-8 col-xs-12 wMarginBottom">
<button type="submit" class="btn btn-success btn-block" id="continue-button">
{{#i18n}}reservation-page.pay{{/i18n}} {{orderSummary.totalPrice}} {{event.currency}}
</button>
</div>
<div class="col-md-4 col-md-pull-4 col-xs-12"><button type="submit" class="btn btn-default btn-block" id="cancel-reservation">{{#i18n}}reservation-page.cancel{{/i18n}}</button></div>
</div>
{{/orderSummary.free}}
<div class="row">
<div class="col-md-4 col-md-push-8 col-xs-12 wMarginBottom"><button type="submit" class="btn btn-success btn-block" id="continue-button">{{#i18n}}reservation-page.continue{{/i18n}}</button></div>
<div class="col-md-4 col-md-pull-4 col-xs-12"><button type="submit" class="btn btn-default btn-block" id="cancel-reservation">{{#i18n}}reservation-page.cancel{{/i18n}}</button></div>
</div>



<input type="hidden" name="{{_csrf.parameterName}}" value="{{_csrf.token}}">
Expand Down

0 comments on commit cec1c53

Please sign in to comment.