onSuccess
Fired when a booking completes. The payload shape depends on the system type.
Not currently invoked by the booking widget
init() accepts onSuccess, but the current bundle never calls it. The
handler is passed down to the booking component and then dropped, and the
booking-completion code only updates internal state — it doesn't notify the
host page. Don't build a redirect, confirmation email trigger, or analytics
event on it yet. Confirm with the platform team before you rely on it. The
shapes below describe the intended payload.
onSuccess is intended to fire once per successful booking, as your hook for
redirects, analytics events, CRM syncing, and confirmation messages beyond
what the widget shows.
Signature
interface MedosBookingConfig {
onSuccess?: (data?: any) => void;
}The payload shape depends on the booking system type — see below.
Payload shape by system type
SCHEDULED
{
appointmentId: number;
}Same shape whether the patient paid for a new appointment or redeemed an active session pack — pack usage is recorded server-side against the appointment.
QMS
interface QueueToken {
tokenNumber: string;
queuePosition: number;
estimatedWaitTime: number; // minutes
patientName: string;
appointmentDate: string; // YYYY-MM-DD
appointmentTime?: string; // HH:MM (approximate, if provided)
doctorName?: string;
locationName?: string;
bookingType: "TODAY" | "FUTURE";
}Modal auto-close
The auto-close lives inside the same success handler that never runs, so the
modal does not close itself after a booking today. The patient dismisses it,
or you call MedosBooking.close().
Once onSuccess is live, the intended behaviour is a 3 second delay after
it fires — long enough to read the confirmation — followed by onClose, exactly
as if the patient had dismissed the modal.
Common patterns
Redirect on success
MedosBooking.init({
apiKey: "mk_...",
onSuccess: (data) => {
window.location.href = `/booked?id=${data.appointmentId}`;
},
});Track a conversion event
MedosBooking.init({
apiKey: "mk_...",
onSuccess: (data) => {
window.dataLayer?.push({
event: "medos_booking_success",
appointmentId: data.appointmentId,
});
},
});See Analytics recipes for GA4, GTM, and Mixpanel patterns.
Handle both scheduled and QMS
MedosBooking.init({
apiKey: "mk_...",
onSuccess: (data) => {
if (data.tokenNumber) {
// QMS
alert(`Your token: ${data.tokenNumber}`);
} else {
// scheduled
alert(`Appointment booked: #${data.appointmentId}`);
}
},
});