Scheduling infrastructure for absolutely everyone.
import type z from "zod";
import type { eventTypeAppMetadataOptionalSchema } from "@calcom/app-store/zod-utils";
import type { appDataSchemas } from "../../apps.schemas.generated";
/**
*
* @param metadata The event type metadata
* @param inclusive Determines if multiple includes the case of 1
* @returns boolean
*/
const checkForMultiplePaymentApps = (
metadata:
| {
apps?: z.infer<typeof eventTypeAppMetadataOptionalSchema>;
}
| null
| undefined,
inclusive = false
) => {
let enabledPaymentApps = 0;
for (const appKey in metadata?.apps) {
const app = metadata?.apps[appKey as keyof typeof appDataSchemas];
if (!app) continue;
if ("appCategories" in app && app.appCategories) {
const isPaymentApp = app.appCategories.includes("payment");
if (isPaymentApp && "enabled" in app && app.enabled) {
enabledPaymentApps++;
}
} else if ("price" in app && "enabled" in app && app.enabled) {
enabledPaymentApps++;
}
}
return inclusive ? enabledPaymentApps >= 1 : enabledPaymentApps > 1;
};
export default checkForMultiplePaymentApps;