Skip to content

Commit

Permalink
#77 remove hardcoded redirect baseurl
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Jul 8, 2016
1 parent abb27c4 commit 4d6c6f8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/alfio/manager/PaypalManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.paypal.base.rest.PayPalRESTException;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -60,12 +61,14 @@ private List<Transaction> buildPaymentDetails(Event event, OrderSummary orderSum
amount.setTotal(orderSummary.getTotalPrice());

Transaction transaction = new Transaction();
//FIXME hardcoded text
transaction.setDescription("creating a payment");
transaction.setAmount(amount);

List<Item> items = orderSummary.getSummary().stream().map(summaryRow -> new Item(summaryRow.getName(), Integer.toString(summaryRow.getAmount()), summaryRow.getType() == SummaryRow.SummaryType.PROMOTION_CODE ? summaryRow.getSubTotal() : summaryRow.getPrice(), event.getCurrency())).collect(Collectors.toList());

if(!event.isVatIncluded()) {
//FIXME hardcoded text -> translate (and show %)
items.add(new Item("VAT", "1", orderSummary.getTotalVAT(), event.getCurrency()));
}

Expand All @@ -92,8 +95,12 @@ public String createCheckoutRequest(Event event, String reservationId, OrderSumm
payment.setPayer(payer);
payment.setTransactions(transactions);
RedirectUrls redirectUrls = new RedirectUrls();
redirectUrls.setCancelUrl("http://localhost:8080/event/" + eventName + "/reservation/" + reservationId + "/book?paypal-cancel=true");
redirectUrls.setReturnUrl("http://localhost:8080/event/" + eventName + "/reservation/" + reservationId + "/book?paypal-success=true");

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

redirectUrls.setCancelUrl(bookUrl + "?paypal-cancel=true");
redirectUrls.setReturnUrl(bookUrl + "?paypal-success=true");
payment.setRedirectUrls(redirectUrls);

Payment createdPayment = payment.create(getApiContext(event));
Expand All @@ -112,7 +119,7 @@ public String commitPayment(String token, String payerId, Event event) throws E
Payment result = payment.execute(getApiContext(event), paymentExecute);

//return result.getTransactions().get(0).getRelatedResources().get(0).getSale().getId();
//FIXME
//FIXME fetch correct id
return result.getId();
}

Expand Down

0 comments on commit 4d6c6f8

Please sign in to comment.