4141import com .mongodb .client .model .Filters ;
4242import com .mongodb .client .model .Updates ;
4343import com .stripe .model .Event ;
44- import com .stripe .model .StripeObject ;
4544import com .stripe .model .Charge ;
4645import com .stripe .model .Dispute ;
4746import com .stripe .model .checkout .Session ;
@@ -108,7 +107,7 @@ public void handle(Event event, StripeEventContext ctx) throws Exception {
108107 // ── Handlers ─────────────────────────────────────────────────────────────
109108
110109 private void handleSessionCompleted (Event event , StripeEventContext ctx , ProductsConfig products ) {
111- var session = deserialize (event , Session .class );
110+ var session = EventPayloads . deserialize (event , Session .class );
112111 if (session != null ) {
113112 if (!"paid" .equals (session .getPaymentStatus ())) {
114113 LOGGER .info ("[stripe] checkout.session.completed with status '{}' — leaving as pending_payment" ,
@@ -138,7 +137,7 @@ private void handleSessionCompleted(Event event, StripeEventContext ctx, Product
138137
139138 private void handleAsyncPaymentSucceeded (Event event , StripeEventContext ctx , ProductsConfig products ) {
140139 LOGGER .info ("[stripe] handleAsyncPaymentSucceeded: starting" );
141- var session = deserialize (event , Session .class );
140+ var session = EventPayloads . deserialize (event , Session .class );
142141 if (session == null ) {
143142 LOGGER .info ("[stripe] handleAsyncPaymentSucceeded: session is null, trying fallback extraction" );
144143 // Fallback: extract directly from JSON when SDK deserialization fails (API version mismatch)
@@ -158,7 +157,7 @@ private void handleAsyncPaymentSucceeded(Event event, StripeEventContext ctx, Pr
158157 }
159158
160159 private void handleAsyncPaymentFailed (Event event , StripeEventContext ctx , ProductsConfig products ) {
161- var session = deserialize (event , Session .class );
160+ var session = EventPayloads . deserialize (event , Session .class );
162161 String sessionId ;
163162 if (session != null ) {
164163 sessionId = session .getId ();
@@ -186,7 +185,7 @@ private void handleAsyncPaymentFailed(Event event, StripeEventContext ctx, Produ
186185 }
187186
188187 private void handleSessionExpired (Event event , StripeEventContext ctx , ProductsConfig products ) {
189- var session = deserialize (event , Session .class );
188+ var session = EventPayloads . deserialize (event , Session .class );
190189 String sessionId ;
191190 if (session != null ) {
192191 sessionId = session .getId ();
@@ -214,7 +213,7 @@ private void handleSessionExpired(Event event, StripeEventContext ctx, ProductsC
214213 }
215214
216215 private void handleChargeRefunded (Event event , StripeEventContext ctx , ProductsConfig products ) {
217- var charge = deserialize (event , Charge .class );
216+ var charge = EventPayloads . deserialize (event , Charge .class );
218217 String paymentIntentId ;
219218 Long refundAmount ;
220219 String currency ;
@@ -270,7 +269,7 @@ private void handleChargeRefunded(Event event, StripeEventContext ctx, ProductsC
270269 }
271270
272271 private void handleDisputeCreated (Event event , StripeEventContext ctx , ProductsConfig products ) {
273- var dispute = deserialize (event , Dispute .class );
272+ var dispute = EventPayloads . deserialize (event , Dispute .class );
274273 String paymentIntentId ;
275274 Long disputeAmount ;
276275 String currency ;
@@ -546,16 +545,6 @@ private MongoCollection<BsonDocument> transactionsCollection(StripeEventContext
546545 .getCollection (products .transactionsCollection (), BsonDocument .class );
547546 }
548547
549- @ SuppressWarnings ("unchecked" )
550- private static <T extends StripeObject > T deserialize (Event event , Class <T > type ) {
551- var obj = event .getDataObjectDeserializer ().getObject ();
552- if (obj .isEmpty () || !type .isInstance (obj .get ())) {
553- LOGGER .warn ("[stripe] could not deserialize {} payload as {} (API version mismatch?)" ,
554- event .getType (), type .getSimpleName ());
555- return null ;
556- }
557- return (T ) obj .get ();
558- }
559548
560549 // ── Notifications ────────────────────────────────────────────────────────
561550
0 commit comments