Skip to content

Commit 0e4c673

Browse files
committed
initial work for removing the paypal token from the session #657
1 parent a44dac9 commit 0e4c673

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/main/java/alfio/controller/payment/PayPalCallbackController.java

+7-11
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import alfio.model.TicketReservation;
2323
import alfio.model.transaction.token.PayPalToken;
2424
import alfio.repository.EventRepository;
25+
import alfio.repository.TransactionRepository;
2526
import lombok.RequiredArgsConstructor;
2627
import org.springframework.stereotype.Controller;
2728
import org.springframework.web.bind.annotation.GetMapping;
2829
import org.springframework.web.bind.annotation.PathVariable;
2930
import org.springframework.web.bind.annotation.RequestMapping;
3031
import org.springframework.web.bind.annotation.RequestParam;
31-
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
3232

3333
import javax.servlet.http.HttpSession;
3434
import java.util.Optional;
@@ -42,14 +42,14 @@ public class PayPalCallbackController {
4242

4343
private final EventRepository eventRepository;
4444
private final TicketReservationManager ticketReservationManager;
45+
private final TransactionRepository transactionRepository;
4546

4647
@GetMapping("/confirm")
4748
public String payPalSuccess(@PathVariable("eventName") String eventName,
4849
@PathVariable("reservationId") String reservationId,
4950
@RequestParam(value = "paymentId", required = false) String payPalPaymentId,
5051
@RequestParam(value = "PayerID", required = false) String payPalPayerID,
5152
@RequestParam(value = "hmac") String hmac,
52-
RedirectAttributes redirectAttributes,
5353
HttpSession session) {
5454

5555
Optional<Event> optionalEvent = eventRepository.findOptionalByShortName(eventName);
@@ -63,27 +63,23 @@ public String payPalSuccess(@PathVariable("eventName") String eventName,
6363
return "redirect:/event/"+eventName;
6464
}
6565

66+
var res = optionalReservation.get();
67+
var ev = optionalEvent.get();
68+
6669
if (isNotBlank(payPalPayerID) && isNotBlank(payPalPaymentId)) {
67-
redirectAttributes.addFlashAttribute("paypalCheckoutConfirmation", true)
68-
.addFlashAttribute("tokenAcquired", true);
6970
session.setAttribute(PaymentManager.PAYMENT_TOKEN, new PayPalToken(payPalPayerID, payPalPaymentId, hmac));
71+
return "redirect:/event/"+ev.getShortName()+"/reservation/"+res.getId()+"/overview";
7072
} else {
71-
return payPalCancel(eventName, reservationId, redirectAttributes, session);
73+
return payPalCancel(ev.getShortName(), res.getId(), session);
7274
}
73-
74-
return "redirect:/event/"+eventName+"/reservation/"+reservationId+"/overview";
7575
}
7676

7777
@GetMapping("/cancel")
7878
public String payPalCancel(@PathVariable("eventName") String eventName,
7979
@PathVariable("reservationId") String reservationId,
80-
RedirectAttributes redirectAttributes,
8180
HttpSession session) {
8281

8382
session.removeAttribute(PaymentManager.PAYMENT_TOKEN);
84-
85-
redirectAttributes.addFlashAttribute("tokenAcquired", false)
86-
.addFlashAttribute("payPalCancelled", true);
8783
return "redirect:/event/"+eventName+"/reservation/"+reservationId+"/overview";
8884
}
8985
}

src/main/java/alfio/manager/payment/PayPalManager.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import alfio.manager.system.ConfigurationManager;
2222
import alfio.model.Event;
2323
import alfio.model.*;
24-
import alfio.model.system.Configuration;
2524
import alfio.model.system.ConfigurationKeys;
2625
import alfio.model.transaction.*;
2726
import alfio.model.transaction.capabilities.ExternalProcessing;
@@ -78,10 +77,13 @@ public class PayPalManager implements PaymentProvider, ExternalProcessing, Refun
7877
private final TransactionRepository transactionRepository;
7978

8079
private APIContext getApiContext(EventAndOrganizationId event) {
81-
int orgId = event.getOrganizationId();
82-
boolean isLive = configurationManager.getBooleanConfigValue(Configuration.from(orgId, ConfigurationKeys.PAYPAL_LIVE_MODE), false);
83-
String clientId = configurationManager.getRequiredValue(Configuration.from(orgId, ConfigurationKeys.PAYPAL_CLIENT_ID));
84-
String clientSecret = configurationManager.getRequiredValue(Configuration.from(orgId, ConfigurationKeys.PAYPAL_CLIENT_SECRET));
80+
81+
var paypalConf = configurationManager.getFor(event,
82+
Set.of(ConfigurationKeys.PAYPAL_LIVE_MODE, ConfigurationKeys.PAYPAL_CLIENT_ID, ConfigurationKeys.PAYPAL_CLIENT_SECRET));
83+
84+
boolean isLive = paypalConf.get(ConfigurationKeys.PAYPAL_LIVE_MODE).getValueAsBooleanOrDefault(false);
85+
String clientId = paypalConf.get(ConfigurationKeys.PAYPAL_CLIENT_ID).getRequiredValue();
86+
String clientSecret = paypalConf.get(ConfigurationKeys.PAYPAL_CLIENT_SECRET).getRequiredValue();
8587
return new APIContext(clientId, clientSecret, isLive ? "live" : "sandbox");
8688
}
8789

@@ -380,7 +382,7 @@ public PaymentResult doPayment(PaymentSpecification spec) {
380382
Long gatewayFee = Optional.ofNullable(i.getFee()).map(Long::parseLong).orElse(0L);
381383
return Pair.of(platformFee, gatewayFee);
382384
}).orElseGet(() -> Pair.of(0L, 0L));
383-
transactionRepository.invalidateForReservation(spec.getReservationId());
385+
PaymentManagerUtils.invalidateExistingTransactions(spec.getReservationId(), transactionRepository);
384386
transactionRepository.insert(captureId, paymentId, spec.getReservationId(),
385387
ZonedDateTime.now(), spec.getPriceWithVAT(), spec.getEvent().getCurrency(), "Paypal confirmation", PaymentProxy.PAYPAL.name(),
386388
fees.getLeft(), fees.getRight(), alfio.model.transaction.Transaction.Status.COMPLETE, Map.of());

src/main/java/alfio/manager/payment/StripeCreditCardManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public PaymentResult doPayment( PaymentSpecification spec ) {
129129
Optional.ofNullable( BaseStripeManager.getFeeAmount(feeDetails, "stripe_fee")).map(Long::parseLong).orElse(0L));
130130
}).orElse(null);
131131

132+
PaymentManagerUtils.invalidateExistingTransactions(spec.getReservationId(), transactionRepository);
132133
transactionRepository.insert(charge.getId(), null, spec.getReservationId(),
133134
ZonedDateTime.now(), spec.getPriceWithVAT(), spec.getEvent().getCurrency(), charge.getDescription(), PaymentProxy.STRIPE.name(),
134135
fees != null ? fees.getLeft() : 0L, fees != null ? fees.getRight() : 0L, Transaction.Status.COMPLETE, Map.of());

src/main/java/alfio/manager/payment/StripeWebhookPaymentManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ private StripeSCACreditCardToken createNewToken(PaymentSpecification paymentSpec
137137
var intent = PaymentIntent.create(paymentIntentParams, baseStripeManager.options(paymentSpecification.getEvent()).orElseThrow());
138138
var clientSecret = intent.getClientSecret();
139139
long platformFee = paymentIntentParams.containsKey("application_fee") ? (long) paymentIntentParams.get("application_fee") : 0L;
140+
PaymentManagerUtils.invalidateExistingTransactions(paymentSpecification.getReservationId(), transactionRepository);
140141
transactionRepository.insert(intent.getId(), intent.getId(),
141142
paymentSpecification.getReservationId(), ZonedDateTime.now(paymentSpecification.getEvent().getZoneId()),
142143
paymentSpecification.getPriceWithVAT(), paymentSpecification.getEvent().getCurrency(), "Payment Intent",

0 commit comments

Comments
 (0)