Skip to content

Commit

Permalink
cleanup paypal manager: remove unused code #657
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Jul 1, 2019
1 parent 382eec5 commit 72a2512
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 79 deletions.
39 changes: 7 additions & 32 deletions src/main/java/alfio/manager/payment/PayPalManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import alfio.model.*;
import alfio.model.system.ConfigurationKeys;
import alfio.model.transaction.*;
import alfio.model.transaction.capabilities.ExternalProcessing;
import alfio.model.transaction.capabilities.PaymentInfo;
import alfio.model.transaction.capabilities.RefundRequest;
import alfio.model.transaction.token.PayPalToken;
import alfio.repository.TicketRepository;
import alfio.repository.TicketReservationRepository;
import alfio.repository.TransactionRepository;
import alfio.util.ErrorsCode;
import alfio.util.LocaleUtil;
import alfio.util.MonetaryUtil;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
Expand All @@ -58,7 +56,6 @@
import java.time.ZonedDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;

import static alfio.model.system.ConfigurationKeys.PAYPAL_ENABLED;
Expand All @@ -67,7 +64,7 @@
@Component
@Log4j2
@AllArgsConstructor
public class PayPalManager implements PaymentProvider, ExternalProcessing, RefundRequest, PaymentInfo {
public class PayPalManager implements PaymentProvider, RefundRequest, PaymentInfo {

private final ConfigurationManager configurationManager;
private final MessageSource messageSource;
Expand Down Expand Up @@ -212,10 +209,6 @@ private static Optional<String> mappedException(PayPalRESTException e) {
}
}

private boolean hasTokens(Map<String, List<String>> params) {
return params.containsKey("payerId") && params.containsKey("paypalPaymentId");
}

private Pair<String, String> commitPayment(String reservationId, PayPalToken payPalToken, EventAndOrganizationId event) throws PayPalRESTException {

Payment payment = new Payment().setId(payPalToken.getPaymentId());
Expand Down Expand Up @@ -322,32 +315,14 @@ public boolean refund(alfio.model.transaction.Transaction transaction, Event eve

@Override
public boolean accept(PaymentMethod paymentMethod, PaymentContext context) {
return paymentMethod == PaymentMethod.PAYPAL &&
configurationManager.getBooleanConfigValue(context.narrow(PAYPAL_ENABLED), false )
&& configurationManager.getStringConfigValue(context.narrow(ConfigurationKeys.PAYPAL_CLIENT_ID)).isPresent()
&& configurationManager.getStringConfigValue(context.narrow(ConfigurationKeys.PAYPAL_CLIENT_SECRET)).isPresent();
}

@Override
public Function<Map<String, List<String>>, PaymentSpecification> getSpecificationFromRequest(Event event,
TicketReservation reservation,
TotalPrice reservationCost,
OrderSummary orderSummary) {
return map -> {
if(hasTokens(map) && hasExactlyOneElementFor(map, "paypalPaymentId", "payerId", "hmac")) {
PayPalToken token = new PayPalToken(map.get("payerId").get(0), map.get("paypalPaymentId").get(0), map.get("hmac").get(0));
return new PaymentSpecification(reservation.getId(), token, reservationCost.getPriceWithVAT(),
event, reservation.getEmail(), new CustomerName(reservation.getFullName(), reservation.getFirstName(), reservation.getLastName(), event.mustUseFirstAndLastName()),
reservation.getBillingAddress(), reservation.getCustomerReference(), LocaleUtil.forLanguageTag(reservation.getUserLanguage()),
reservation.isInvoiceRequested(), !reservation.isDirectAssignmentRequested(), orderSummary, reservation.getVatCountryCode(),
reservation.getVatNr(), reservation.getVatStatus(), map.containsKey("termAndConditionsAccepted"), map.containsKey("privacyPolicyAccepted"));
}
return null;
};
}
var paypalConf = configurationManager.getFor(context.getEvent(),
Set.of(PAYPAL_ENABLED, ConfigurationKeys.PAYPAL_CLIENT_ID, ConfigurationKeys.PAYPAL_CLIENT_SECRET));

private static boolean hasExactlyOneElementFor(Map<String, List<String>> map, String... keys) {
return Arrays.stream(keys).allMatch(k -> map.containsKey(k) && map.getOrDefault(k, Collections.emptyList()).size() == 1);
return paymentMethod == PaymentMethod.PAYPAL &&
paypalConf.get(PAYPAL_ENABLED).getValueAsBooleanOrDefault(false)
&& paypalConf.get(ConfigurationKeys.PAYPAL_CLIENT_ID).isPresent()
&& paypalConf.get(ConfigurationKeys.PAYPAL_CLIENT_SECRET).isPresent();
}

@Override
Expand Down

This file was deleted.

0 comments on commit 72a2512

Please sign in to comment.