fix: BOOKING_PAID webhook & workflow isn't triggering after payment successful (#26044)

* fix booking paid webhook

* Update handlePaymentSuccess to include updatedBooking status

* Fix videoCallUrl undefined error in BOOKING_PAID workflow trigger

- Import getVideoCallUrlFromCalEvent to properly compute meeting URL
- Use conditional metadata to avoid passing undefined videoCallUrl
- Matches original handleConfirmation.ts behavior

Co-Authored-By: [email protected] <[email protected]>

* Add missing schedulingType to calendarEventForWorkflow

- Added schedulingType field to match original handleConfirmation.ts behavior
- This field was present in the original implementation but missing in the refactor

Co-Authored-By: [email protected] <[email protected]>

* Fix paymentMetadata nullability to match original behavior

- Changed from ?? null to optional chaining (undefined) to match original handleConfirmation.ts
- This ensures webhook consumers using z.string().optional() schemas continue to work
- undefined values are omitted from JSON, while null values would be explicitly included

Co-Authored-By: [email protected] <[email protected]>

* Fix type errors: add schedulingType to getBooking and use null for metadata

- Added schedulingType to getBooking.ts eventType select to make it available
- Changed paymentMetadata to use ?? null instead of undefined for type compatibility
- The metadata type expects { [key: string]: string | number | boolean | null }

Co-Authored-By: [email protected] <[email protected]>

* await

* add tests

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-01-07 15:00:54 +00:00
1 parent f9635df629
commit 4585d7402d
4 files changed
+499 -100

No files matched your search

@@ -504,103 +504,6 @@ export async function handleConfirmation(args: {
);
await Promise.all(promises);
if (paid) {
let paymentExternalId: string | undefined;
const subscriberMeetingPaid = await getWebhooks({
userId,
eventTypeId: booking.eventTypeId,
triggerEvent: WebhookTriggerEvents.BOOKING_PAID,
teamId: eventType?.teamId,
orgId,
oAuthClientId: platformClientParams?.platformClientId,
});
const bookingWithPayment = await prisma.booking.findUnique({
where: {
id: bookingId,
},
select: {
payment: {
select: {
id: true,
success: true,
externalId: true,
},
},
},
});
const successPayment = bookingWithPayment?.payment?.find((item) => item.success);
if (successPayment) {
paymentExternalId = successPayment.externalId;
}
const paymentMetadata = {
identifier: "cal.com",
bookingId,
eventTypeId: eventType?.id,
bookerEmail: evt.attendees[0].email,
eventTitle: eventType?.title,
externalId: paymentExternalId,
};
payload.paymentId = bookingWithPayment?.payment?.[0].id;
payload.metadata = {
...(paid ? paymentMetadata : {}),
};
const bookingPaidSubscribers = subscriberMeetingPaid.map((sub) =>
sendPayload(
sub.secret,
WebhookTriggerEvents.BOOKING_PAID,
new Date().toISOString(),
sub,
payload
).catch((e) => {
tracingLogger.error(
`Error executing webhook for event: ${WebhookTriggerEvents.BOOKING_PAID}, URL: ${sub.subscriberUrl}, bookingId: ${evt.bookingId}, bookingUid: ${evt.uid}`,
safeStringify(e)
);
})
);
// I don't need to await for this
Promise.all(bookingPaidSubscribers);
try {
const calendarEventForWorkflow = {
...evt,
eventType: {
slug: updatedBookings[0].eventType?.slug || "",
schedulingType: updatedBookings[0].eventType?.schedulingType,
hosts:
updatedBookings[0].eventType?.hosts?.map((host) => ({
user: {
email: host.user.email,
destinationCalendar: host.user.destinationCalendar,
},
})) || [],
},
bookerUrl: bookerUrl,
metadata: { videoCallUrl: meetingUrl },
};
const creditService = new CreditService();
await WorkflowService.scheduleWorkflowsFilteredByTriggerEvent({
workflows,
smsReminderNumber: booking.smsReminderNumber,
calendarEvent: calendarEventForWorkflow,
hideBranding: !!updatedBookings[0].eventType?.owner?.hideBranding,
triggers: [WorkflowTriggerEvents.BOOKING_PAID],
creditCheckFn: creditService.hasAvailableCredits.bind(creditService),
});
} catch (error) {
tracingLogger.error(
"Error while scheduling workflow reminders for booking paid",
safeStringify(error)
);
}
}
} catch (error) {
// Silently fail
console.error(error);
@@ -72,6 +72,7 @@ export async function getBooking(bookingId: number) {
},
},
slug: true,
schedulingType: true,
workflows: {
select: {
workflow: {