mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* getEnabledAppsFromCredentials * wip * wip * mv more * fix: update test mocking for PrismockClient in processPaymentRefund.test.ts - Replace prismaMock with prismock for proper PrismockClient usage - Update mock data structure to include required fields (id, userId, teamId, etc.) - Create app and credential records separately to handle PrismockClient limitations - Replace 'as any' type casting with vi.mocked() for proper type safety - Adjust test expectations to match PrismockClient's actual return structure - Add proper cleanup in beforeEach hook for both credential and app records Fixes failing unit tests after migration from packages/lib to packages/features/bookings/lib/payment Co-Authored-By: [email protected] <[email protected]> * publish platform libraries * fix import * bump version * fix apiv2 * publish platform-libraries --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import type { z } from "zod";
|
|
|
|
import type { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils";
|
|
|
|
export const shouldChargeNoShowCancellationFee = ({
|
|
eventTypeMetadata,
|
|
booking,
|
|
payment,
|
|
}: {
|
|
eventTypeMetadata: z.infer<typeof eventTypeMetaDataSchemaWithTypedApps>;
|
|
booking: {
|
|
startTime: Date;
|
|
};
|
|
payment: {
|
|
appId?: string | null;
|
|
};
|
|
}) => {
|
|
const paymentAppId = payment?.appId;
|
|
|
|
if (typeof paymentAppId !== "string") {
|
|
return false;
|
|
}
|
|
|
|
const cancellationFeeEnabled =
|
|
eventTypeMetadata?.apps?.[paymentAppId as keyof typeof eventTypeMetadata.apps]
|
|
?.autoChargeNoShowFeeIfCancelled;
|
|
const paymentOption =
|
|
eventTypeMetadata?.apps?.[paymentAppId as keyof typeof eventTypeMetadata.apps]?.paymentOption;
|
|
const timeValue =
|
|
eventTypeMetadata?.apps?.[paymentAppId as keyof typeof eventTypeMetadata.apps]
|
|
?.autoChargeNoShowFeeTimeValue;
|
|
const timeUnit =
|
|
eventTypeMetadata?.apps?.[paymentAppId as keyof typeof eventTypeMetadata.apps]
|
|
?.autoChargeNoShowFeeTimeUnit;
|
|
|
|
if (!cancellationFeeEnabled || paymentOption !== "HOLD" || !booking?.startTime) {
|
|
return false;
|
|
}
|
|
|
|
if (!timeValue || !timeUnit) {
|
|
return false;
|
|
}
|
|
|
|
const multiplier: { [key: string]: number } = {
|
|
minutes: 1,
|
|
hours: 60,
|
|
days: 1440,
|
|
};
|
|
const timeInMinutes = timeValue * multiplier[timeUnit];
|
|
|
|
const now = new Date();
|
|
const startTime = new Date(booking.startTime);
|
|
const threshold = new Date(startTime);
|
|
|
|
threshold.setMinutes(threshold.getMinutes() - timeInMinutes);
|
|
|
|
return now >= threshold;
|
|
};
|