Skip to content

Commit

Permalink
fix #404: generate invoice also for PayPal payments
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Mar 16, 2018
1 parent ab15661 commit 0f380d6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
@RequestParam(value = "billingAddress", required = false) String billingAddress,
@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 @@ -124,6 +125,7 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
.addAttribute("billingAddress", billingAddress)
.addAttribute("hmac", hmac)
.addAttribute("postponeAssignment", Boolean.TRUE.equals(postponeAssignment))
.addAttribute("invoiceRequested", Boolean.TRUE.equals(invoiceRequested))
.addAttribute("showPostpone", Boolean.TRUE.equals(postponeAssignment));
} else {
model.addAttribute("paypalCheckoutConfirmation", false)
Expand Down Expand Up @@ -435,8 +437,9 @@ public String handleReservation(@PathVariable("eventName") String eventName,
if(paymentForm.getPaymentMethod() == PaymentProxy.PAYPAL && !paymentForm.hasPaypalTokens()) {
OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event, locale);
try {
String checkoutUrl = paymentManager.createPaypalCheckoutRequest(event, reservationId, orderSummary, customerName,
paymentForm.getEmail(), paymentForm.getBillingAddress(), locale, paymentForm.isPostponeAssignment());
String checkoutUrl = paymentManager.createPayPalCheckoutRequest(event, reservationId, orderSummary, customerName,
paymentForm.getEmail(), paymentForm.getBillingAddress(), locale, paymentForm.isPostponeAssignment(),
paymentForm.isInvoiceRequested());
assignTickets(eventName, reservationId, paymentForm, bindingResult, request, true);
return "redirect:" + checkoutUrl;
} catch (Exception e) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/alfio/manager/PaymentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ public String getStripePublicKey(Event event) {
return stripeManager.getPublicKey(event);
}

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

public boolean refund(TicketReservation reservation, Event event, Optional<Integer> amount, String username) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/alfio/manager/PaypalManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ private List<Transaction> buildPaymentDetails(Event event, OrderSummary orderSum
return transactions;
}

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


APIContext apiContext = getApiContext(event);
Expand Down Expand Up @@ -156,6 +157,7 @@ public String createCheckoutRequest(Event event, String reservationId, OrderSumm
.queryParam("email", email)
.queryParam("billingAddress", billingAddress)
.queryParam("postponeAssignment", postponeAssignment)
.queryParam("invoiceRequested", invoiceRequested)
.queryParam("hmac", computeHMAC(customerName, email, billingAddress, event));
String finalUrl = bookUrlBuilder.toUriString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<input type="hidden" name="paypalPaymentId" value="{{paypalPaymentId}}">
<input type="hidden" name="paypalPayerID" value="{{paypalPayerID}}">
<input type="hidden" name="termAndConditionsAccepted" value="true">
<input type="hidden" name="invoiceRequested" value="{{invoiceRequested}}">
<div class="alert alert-success">
<h3><i class="fa fa-check"></i> {{#i18n}}reservation-page.paypal.confirm{{/i18n}}</h3>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void reservationFlowTest() throws Exception{


// check that the payment page is shown
String reservationPage = reservationController.showPaymentPage(eventName, reservationIdentifier, null, null, null, null, null, null, null, null, null, null, null, new BindingAwareModelMap(), Locale.ENGLISH);
String reservationPage = reservationController.showPaymentPage(eventName, reservationIdentifier, null, null, null, null, null, null, null, null, null, null, null, null, new BindingAwareModelMap(), Locale.ENGLISH);
assertEquals("/event/reservation-page", reservationPage);
//

Expand Down

0 comments on commit 0f380d6

Please sign in to comment.