Skip to content

Commit e46c1bb

Browse files
authored
fix delete payment app (calcom#25801)
1 parent 758b820 commit e46c1bb

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

packages/features/credentials/handleDeleteCredential.integration-test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet
132132
},
133133
],
134134
},
135+
payment: {
136+
create: {
137+
uid: "payment-uid-123",
138+
appId: "stripe",
139+
amount: 1000,
140+
fee: 0,
141+
currency: "usd",
142+
success: false,
143+
refunded: false,
144+
data: {},
145+
externalId: "ext-payment-123",
146+
},
147+
},
135148
},
136149
});
137150
createdBookingIds.push(unpaidBooking.id);
@@ -212,6 +225,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet
212225
},
213226
],
214227
},
228+
payment: {
229+
create: {
230+
uid: "payment-uid-456",
231+
appId: "stripe",
232+
amount: 1000,
233+
fee: 0,
234+
currency: "usd",
235+
success: false,
236+
refunded: false,
237+
data: {},
238+
externalId: "ext-payment-456",
239+
},
240+
},
215241
},
216242
});
217243
createdBookingIds.push(unpaidBooking.id);
@@ -270,6 +296,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet
270296
},
271297
],
272298
},
299+
payment: {
300+
create: {
301+
uid: "payment-uid-b1",
302+
appId: "stripe",
303+
amount: 1000,
304+
fee: 0,
305+
currency: "usd",
306+
success: false,
307+
refunded: false,
308+
data: {},
309+
externalId: "ext-payment-b1",
310+
},
311+
},
273312
},
274313
});
275314
createdBookingIds.push(booking1.id);
@@ -293,6 +332,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet
293332
},
294333
],
295334
},
335+
payment: {
336+
create: {
337+
uid: "payment-uid-b2",
338+
appId: "stripe",
339+
amount: 1000,
340+
fee: 0,
341+
currency: "usd",
342+
success: false,
343+
refunded: false,
344+
data: {},
345+
externalId: "ext-payment-b2",
346+
},
347+
},
296348
},
297349
});
298350
createdBookingIds.push(booking2.id);
@@ -423,6 +475,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet
423475
},
424476
],
425477
},
478+
payment: {
479+
create: {
480+
uid: "payment-uid-query-test",
481+
appId: "stripe",
482+
amount: 1000,
483+
fee: 0,
484+
currency: "usd",
485+
success: false,
486+
refunded: false,
487+
data: {},
488+
externalId: "ext-payment-query-test",
489+
},
490+
},
426491
},
427492
});
428493
createdBookingIds.push(unpaidBooking.id);

packages/features/credentials/handleDeleteCredential.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,21 @@ const handleDeleteCredential = async ({
209209
},
210210
});
211211

212-
// Assuming that all bookings under this eventType need to be paid
212+
// Only cancel unpaid pending bookings that:
213+
// 1. Are in the future (startTime > now) - don't cancel old bookings
214+
// 2. Have failed payments associated with the payment app being deleted
213215
const unpaidBookings = await prisma.booking.findMany({
214216
where: {
215217
userId: userId,
216218
eventTypeId: eventType.id,
217219
status: "PENDING",
218220
paid: false,
221+
startTime: {
222+
gt: new Date(),
223+
},
219224
payment: {
220-
every: {
225+
some: {
226+
appId: credential.appId,
221227
success: false,
222228
},
223229
},

0 commit comments

Comments
 (0)