* 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: benny@cal.com <sldisek783@gmail.com> * 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>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { handleNoShowFee } from "@calcom/features/bookings/lib/payment/handleNoShowFee";
|
|
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
|
import type { PrismaClient } from "@calcom/prisma";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TrpcSessionUser } from "../../../types";
|
|
import type { TChargeCardInputSchema } from "./chargeCard.schema";
|
|
|
|
interface ChargeCardHandlerOptions {
|
|
ctx: { user: NonNullable<TrpcSessionUser>; prisma: PrismaClient };
|
|
input: TChargeCardInputSchema;
|
|
}
|
|
export const chargeCardHandler = async ({ ctx, input }: ChargeCardHandlerOptions) => {
|
|
const { prisma } = ctx;
|
|
const bookingRepository = new BookingRepository(prisma);
|
|
|
|
const booking = await bookingRepository.getBookingForPaymentProcessing(input.bookingId);
|
|
|
|
if (!booking) {
|
|
throw new Error("Booking not found");
|
|
}
|
|
|
|
if (booking.payment[0].success) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: `The no show fee for ${booking.id} has already been charged.`,
|
|
});
|
|
}
|
|
|
|
try {
|
|
await handleNoShowFee({
|
|
booking,
|
|
payment: booking.payment[0],
|
|
});
|
|
} catch (error) {
|
|
console.error(error);
|
|
throw new TRPCError({
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
message: `Failed to charge no show fee for ${booking.id}`,
|
|
});
|
|
}
|
|
};
|