Skip to content

Commit

Permalink
#77 remove hardcoded values
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Jul 11, 2016
1 parent c5b18b8 commit 9ce15aa
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 21 deletions.
27 changes: 19 additions & 8 deletions src/main/java/alfio/manager/PaypalManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;

Expand All @@ -40,10 +41,12 @@
public class PaypalManager {

private final ConfigurationManager configurationManager;
private final MessageSource messageSource;

@Autowired
public PaypalManager(ConfigurationManager configurationManager) {
public PaypalManager(ConfigurationManager configurationManager, MessageSource messageSource) {
this.configurationManager = configurationManager;
this.messageSource = messageSource;
}

private APIContext getApiContext(Event event) {
Expand All @@ -54,23 +57,25 @@ private APIContext getApiContext(Event event) {
return new APIContext(clientId, clientSecret, isLive ? "live" : "sandbox");
}

private List<Transaction> buildPaymentDetails(Event event, OrderSummary orderSummary) {
private List<Transaction> buildPaymentDetails(Event event, OrderSummary orderSummary, String reservationId, Locale locale) {


Amount amount = new Amount();
amount.setCurrency(event.getCurrency());
amount.setTotal(orderSummary.getTotalPrice());

Transaction transaction = new Transaction();
//FIXME hardcoded text
transaction.setDescription("creating a payment");
String description = messageSource.getMessage("reservation-email-subject", new Object[] {configurationManager.getShortReservationID(event, reservationId), event.getDisplayName()}, locale);
transaction.setDescription(description);
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());
List<Item> items = orderSummary.getSummary().stream()
.map(summaryRow -> fromSummaryRow(summaryRow, event))
.collect(Collectors.toList());

if(!event.isVatIncluded()) {
//FIXME hardcoded text -> translate (and show %)
items.add(new Item("VAT", "1", orderSummary.getTotalVAT(), event.getCurrency()));
String vatMsg = messageSource.getMessage("reservation-page.vat", new Object[] {event.getVat()}, locale);
items.add(new Item(vatMsg, "1", orderSummary.getTotalVAT(), event.getCurrency()));
}

transaction.setItemList(new ItemList().setItems(items));
Expand All @@ -82,9 +87,15 @@ private List<Transaction> buildPaymentDetails(Event event, OrderSummary orderSum
return transactions;
}

private static Item fromSummaryRow(SummaryRow summaryRow, Event event) {
String quantity = Integer.toString(summaryRow.getAmount());
String price = summaryRow.getType() == SummaryRow.SummaryType.PROMOTION_CODE ? summaryRow.getSubTotal() : summaryRow.getPrice();
return new Item(summaryRow.getName(), quantity, price, event.getCurrency());
}

public String createCheckoutRequest(Event event, String reservationId, OrderSummary orderSummary, String fullName, String email, String billingAddress, Locale locale) throws Exception {

List<Transaction> transactions = buildPaymentDetails(event, orderSummary);
List<Transaction> transactions = buildPaymentDetails(event, orderSummary, reservationId, locale);
String eventName = event.getShortName();


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ public TicketReservation findByPartialID(String reservationId) {
}

public String getShortReservationID(Event event, String reservationId) {
return StringUtils.substring(reservationId, 0, configurationManager.getIntConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), PARTIAL_RESERVATION_ID_LENGTH), 8)).toUpperCase();
return configurationManager.getShortReservationID(event, reservationId);
}

public int countAvailableTickets(Event event, TicketCategory category) {
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/alfio/manager/system/ConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.stream.Collector;
import java.util.stream.Collectors;

import static alfio.model.system.ConfigurationKeys.PARTIAL_RESERVATION_ID_LENGTH;
import static alfio.model.system.ConfigurationPathLevel.EVENT;
import static alfio.model.system.ConfigurationPathLevel.ORGANIZATION;
import static alfio.model.system.ConfigurationPathLevel.SYSTEM;
Expand Down Expand Up @@ -155,7 +156,7 @@ public void saveAllOrganizationConfiguration(int organizationId, List<Configurat
.forEach(c -> {
Optional<String> value = evaluateValue(c.getKey(), c.getValue());
Optional<Configuration> existing = configurationRepository.findByKeyAtOrganizationLevel(organizationId, c.getKey());
if(!value.isPresent()) {
if (!value.isPresent()) {
configurationRepository.deleteOrganizationLevelByKey(c.getKey(), organizationId);
} else if (existing.isPresent()) {
configurationRepository.updateOrganizationLevel(organizationId, c.getKey(), value.get());
Expand Down Expand Up @@ -294,11 +295,12 @@ static Map<ConfigurationKeys.SettingCategory, List<Configuration>> union(Configu
.flatMap(l -> ConfigurationKeys.byPathLevel(l).stream().map(mapEmptyKeys(l)))
.sorted((c1, c2) -> new CompareToBuilder().append(c2.getConfigurationPathLevel(), c1.getConfigurationPathLevel()).append(c1.getConfigurationKey(), c2.getConfigurationKey()).toComparison())
.collect(LinkedList::new, (List<Configuration> list, Configuration conf) -> {
int existing = (int)list.stream().filter(c -> c.getConfigurationKey() == conf.getConfigurationKey()).count();
if(existing == 0) {
int existing = (int) list.stream().filter(c -> c.getConfigurationKey() == conf.getConfigurationKey()).count();
if (existing == 0) {
list.add(conf);
}
}, (l1, l2) -> {});
}, (l1, l2) -> {
});
return configurations.stream().collect(groupByCategory());
}

Expand Down Expand Up @@ -384,4 +386,8 @@ private static Map<ConfigurationKeys.SettingCategory, List<Configuration>> colle
.sorted()
.collect(groupByCategory());
}

public String getShortReservationID(Event event, String reservationId) {
return StringUtils.substring(reservationId, 0, getIntConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), PARTIAL_RESERVATION_ID_LENGTH), 8)).toUpperCase();
}
}
4 changes: 3 additions & 1 deletion src/main/resources/alfio/i18n/public.properties
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ reservation-page.payment=Payment
reservation-page.credit-card=Credit Card
reservation-page.credit-card.description=Fast and secure. You''ll be charged for the cost of your tickets without any additional fees. The confirmation is immediate.
reservation-page.paypal=Paypal
reservation-page.paypal.description=Pay with paypal.com.
reservation-page.paypal.confirm-button=Confirm paypal payment
reservation-page.paypal.confirm=Confirm to continue.
reservation-page.paypal.description=Pay with your paypal account. You will be redirected to paypal.com.
reservation-page.on-site=On-site cash payment
reservation-page.on-site.description=You''ll receive a ticket but in order to access the event you will have to pay at the entrance desk.
reservation-page.offline=Bank Transfer
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/alfio/i18n/public_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ reservation-page.payment=Zahlungsart
reservation-page.credit-card=Kreditkarte
reservation-page.credit-card.description=Schnell und sicher. Es werden f\u00FCr die gesamten Kosten keine zus\u00E4tzlichen Geb\u00FChren erhoben. Die Teilnahmebest\u00E4tigung erfolgt unmittelbar nach Zahlungseingang.
reservation-page.paypal=DE-Paypal
reservation-page.paypal.description=DE-Pay with paypal.com.
reservation-page.paypal.confirm-button=DE-Confirm paypal payment
reservation-page.paypal.confirm=DE-Confirm to continue.
reservation-page.paypal.description=DE-Pay with your paypal account. You will be redirected to paypal.com.
reservation-page.on-site=Bezahlung vor Ort
reservation-page.on-site.description=Reserviere dir dein Ticket und bezahle es sp\u00E4ter vor Ort
reservation-page.offline=Bank\u00FCberweisung
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/alfio/i18n/public_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ reservation-page.payment=Pagamento
reservation-page.credit-card=Carta di credito
reservation-page.credit-card.description=Veloce e sicuro. Ti verr\u00E0 addebitato il costo totale della prenotazione senza spese aggiuntive. La conferma \u00E8 immediata.
reservation-page.paypal=IT-Paypal
reservation-page.paypal.description=IT-Pay with paypal.com.
reservation-page.paypal.confirm-button=IT-Confirm paypal payment
reservation-page.paypal.confirm=IT-Confirm to continue.
reservation-page.paypal.description=IT-Pay with your paypal account. You will be redirected to paypal.com.
reservation-page.on-site=Paga all''ingresso
reservation-page.on-site.description=Riceverai un biglietto ma non potrai accedere all''evento finch\u00E9 non avrai pagato l''importo dovuto alla cassa.
reservation-page.offline=Bonifico bancario
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/alfio/i18n/public_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ reservation-page.payment=Betaling
reservation-page.credit-card=Creditkaart
reservation-page.credit-card.description=Snel en veilig. Je betaald geen extra kosten en de bevestiging is onmiddellijk.
reservation-page.paypal=NL-Paypal
reservation-page.paypal.description=NL-Pay with paypal.com.
reservation-page.paypal.confirm-button=NL-Confirm paypal payment
reservation-page.paypal.confirm=NL-Confirm to continue.
reservation-page.paypal.description=NL-Pay with your paypal account. You will be redirected to paypal.com.
reservation-page.on-site=Ter plaatse cash betalen
reservation-page.on-site.description=U krijgt een ticket, maar om toegang te krijgen moet u bij de ingang betalen.
reservation-page.offline=Bank Overschrijving
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/templates/event/payment/paypal.ms
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FIXME PAYPAL SPECIFIC PAGE (instructions)!
<div class="wMarginBottom wMarginTop text-muted">{{#i18n}}reservation-page.paypal.description{{/i18n}}</div>
12 changes: 9 additions & 3 deletions src/main/webapp/WEB-INF/templates/event/reservation-page.ms
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@
<input type="hidden" name="paypalPaymentId" value="{{paypalPaymentId}}">
<input type="hidden" name="paypalPayerID" value="{{paypalPayerID}}">
<input type="hidden" name="termAndConditionsAccepted" value="true">

FIXME: CONFIRM PAYPAL PAYMENT
{{#i18n}}reservation-page.paypal.confirm{{/i18n}}
{{/paypalCheckoutConfirmation}}
{{^paypalCheckoutConfirmation}}

Expand Down Expand Up @@ -191,7 +190,14 @@
{{/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-push-8 col-xs-12 wMarginBottom"><button type="submit" class="btn btn-success btn-block" id="continue-button">
{{#paypalCheckoutConfirmation}}
{{#i18n}}reservation-page.paypal.confirm-button{{/i18n}}
{{/paypalCheckoutConfirmation}}
{{^paypalCheckoutConfirmation}}
{{#i18n}}reservation-page.pay{{/i18n}} {{orderSummary.totalPrice}} {{event.currency}}
{{/paypalCheckoutConfirmation}}
</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}}
Expand Down

0 comments on commit 9ce15aa

Please sign in to comment.