diff --git a/packages/features/credentials/handleDeleteCredential.integration-test.ts b/packages/features/credentials/handleDeleteCredential.integration-test.ts index 5290da5f9f..fa3322c29b 100644 --- a/packages/features/credentials/handleDeleteCredential.integration-test.ts +++ b/packages/features/credentials/handleDeleteCredential.integration-test.ts @@ -132,6 +132,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet }, ], }, + payment: { + create: { + uid: "payment-uid-123", + appId: "stripe", + amount: 1000, + fee: 0, + currency: "usd", + success: false, + refunded: false, + data: {}, + externalId: "ext-payment-123", + }, + }, }, }); createdBookingIds.push(unpaidBooking.id); @@ -212,6 +225,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet }, ], }, + payment: { + create: { + uid: "payment-uid-456", + appId: "stripe", + amount: 1000, + fee: 0, + currency: "usd", + success: false, + refunded: false, + data: {}, + externalId: "ext-payment-456", + }, + }, }, }); createdBookingIds.push(unpaidBooking.id); @@ -270,6 +296,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet }, ], }, + payment: { + create: { + uid: "payment-uid-b1", + appId: "stripe", + amount: 1000, + fee: 0, + currency: "usd", + success: false, + refunded: false, + data: {}, + externalId: "ext-payment-b1", + }, + }, }, }); createdBookingIds.push(booking1.id); @@ -293,6 +332,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet }, ], }, + payment: { + create: { + uid: "payment-uid-b2", + appId: "stripe", + amount: 1000, + fee: 0, + currency: "usd", + success: false, + refunded: false, + data: {}, + externalId: "ext-payment-b2", + }, + }, }, }); createdBookingIds.push(booking2.id); @@ -423,6 +475,19 @@ describe("handleDeleteCredential Integration Tests - BookingReference Soft Delet }, ], }, + payment: { + create: { + uid: "payment-uid-query-test", + appId: "stripe", + amount: 1000, + fee: 0, + currency: "usd", + success: false, + refunded: false, + data: {}, + externalId: "ext-payment-query-test", + }, + }, }, }); createdBookingIds.push(unpaidBooking.id); diff --git a/packages/features/credentials/handleDeleteCredential.ts b/packages/features/credentials/handleDeleteCredential.ts index c60a3b7219..56f5030aed 100644 --- a/packages/features/credentials/handleDeleteCredential.ts +++ b/packages/features/credentials/handleDeleteCredential.ts @@ -209,15 +209,21 @@ const handleDeleteCredential = async ({ }, }); - // Assuming that all bookings under this eventType need to be paid + // Only cancel unpaid pending bookings that: + // 1. Are in the future (startTime > now) - don't cancel old bookings + // 2. Have failed payments associated with the payment app being deleted const unpaidBookings = await prisma.booking.findMany({ where: { userId: userId, eventTypeId: eventType.id, status: "PENDING", paid: false, + startTime: { + gt: new Date(), + }, payment: { - every: { + some: { + appId: credential.appId, success: false, }, },