22
22
import alfio .model .TicketReservation ;
23
23
import alfio .model .transaction .token .PayPalToken ;
24
24
import alfio .repository .EventRepository ;
25
+ import alfio .repository .TransactionRepository ;
25
26
import lombok .RequiredArgsConstructor ;
26
27
import org .springframework .stereotype .Controller ;
27
28
import org .springframework .web .bind .annotation .GetMapping ;
28
29
import org .springframework .web .bind .annotation .PathVariable ;
29
30
import org .springframework .web .bind .annotation .RequestMapping ;
30
31
import org .springframework .web .bind .annotation .RequestParam ;
31
- import org .springframework .web .servlet .mvc .support .RedirectAttributes ;
32
32
33
33
import javax .servlet .http .HttpSession ;
34
34
import java .util .Optional ;
@@ -42,14 +42,14 @@ public class PayPalCallbackController {
42
42
43
43
private final EventRepository eventRepository ;
44
44
private final TicketReservationManager ticketReservationManager ;
45
+ private final TransactionRepository transactionRepository ;
45
46
46
47
@ GetMapping ("/confirm" )
47
48
public String payPalSuccess (@ PathVariable ("eventName" ) String eventName ,
48
49
@ PathVariable ("reservationId" ) String reservationId ,
49
50
@ RequestParam (value = "paymentId" , required = false ) String payPalPaymentId ,
50
51
@ RequestParam (value = "PayerID" , required = false ) String payPalPayerID ,
51
52
@ RequestParam (value = "hmac" ) String hmac ,
52
- RedirectAttributes redirectAttributes ,
53
53
HttpSession session ) {
54
54
55
55
Optional <Event > optionalEvent = eventRepository .findOptionalByShortName (eventName );
@@ -63,27 +63,23 @@ public String payPalSuccess(@PathVariable("eventName") String eventName,
63
63
return "redirect:/event/" +eventName ;
64
64
}
65
65
66
+ var res = optionalReservation .get ();
67
+ var ev = optionalEvent .get ();
68
+
66
69
if (isNotBlank (payPalPayerID ) && isNotBlank (payPalPaymentId )) {
67
- redirectAttributes .addFlashAttribute ("paypalCheckoutConfirmation" , true )
68
- .addFlashAttribute ("tokenAcquired" , true );
69
70
session .setAttribute (PaymentManager .PAYMENT_TOKEN , new PayPalToken (payPalPayerID , payPalPaymentId , hmac ));
71
+ return "redirect:/event/" +ev .getShortName ()+"/reservation/" +res .getId ()+"/overview" ;
70
72
} else {
71
- return payPalCancel (eventName , reservationId , redirectAttributes , session );
73
+ return payPalCancel (ev . getShortName (), res . getId () , session );
72
74
}
73
-
74
- return "redirect:/event/" +eventName +"/reservation/" +reservationId +"/overview" ;
75
75
}
76
76
77
77
@ GetMapping ("/cancel" )
78
78
public String payPalCancel (@ PathVariable ("eventName" ) String eventName ,
79
79
@ PathVariable ("reservationId" ) String reservationId ,
80
- RedirectAttributes redirectAttributes ,
81
80
HttpSession session ) {
82
81
83
82
session .removeAttribute (PaymentManager .PAYMENT_TOKEN );
84
-
85
- redirectAttributes .addFlashAttribute ("tokenAcquired" , false )
86
- .addFlashAttribute ("payPalCancelled" , true );
87
83
return "redirect:/event/" +eventName +"/reservation/" +reservationId +"/overview" ;
88
84
}
89
85
}
0 commit comments