File tree Expand file tree Collapse file tree
apps/commerce-api/src/main/java/com/loopers/application Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .loopers .application .coupon ;
22
3+ import com .loopers .application .event .FailedEventStore ;
34import com .loopers .application .payment .PaymentEvent .PaymentCompletedEvent ;
45import com .loopers .domain .coupon .CouponService ;
56import lombok .RequiredArgsConstructor ;
7+ import org .springframework .orm .ObjectOptimisticLockingFailureException ;
68import org .springframework .stereotype .Component ;
79import org .springframework .transaction .annotation .Transactional ;
810import org .springframework .transaction .event .TransactionPhase ;
1214@ RequiredArgsConstructor
1315public class CouponUsageEventListener {
1416 private final CouponService couponService ;
17+ private final FailedEventStore failedEventStore ;
1518
1619 @ TransactionalEventListener (phase = TransactionPhase .AFTER_COMMIT )
1720 @ Transactional
1821 public void handlePaymentCompletedEvent (PaymentCompletedEvent event ) {
1922
20- if (event .couponId () != null ) {
23+ if (event .couponId () == null ) return ;
24+
25+ try {
2126 couponService .confirmCouponUsage (event .couponId ());
27+
28+ } catch (ObjectOptimisticLockingFailureException e ) {
29+ failedEventStore .scheduleRetry (event , "Coupon Lock Conflict on Confirmation" );
30+
31+ } catch (Exception e ) {
32+ failedEventStore .scheduleRetry (event , "Coupon confirmation error: " + e .getMessage ());
2233 }
2334 }
2435}
Original file line number Diff line number Diff line change 11package com .loopers .application .payment ;
22
3+ import com .loopers .domain .event .DomainEvent ;
4+
35public class PaymentEvent {
46 public record PaymentRequestedEvent (
57 Long orderId ,
@@ -12,7 +14,7 @@ public record PaymentCompletedEvent(
1214 Long paymentId ,
1315 boolean isSuccess ,
1416 Long couponId
15- ) {}
17+ ) implements DomainEvent {}
1618
1719 public record PaymentRequestFailedEvent (
1820 Long orderId ,
You can’t perform that action at this time.
0 commit comments