mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* add eslint config * migrate autoLock to features * migrate teamService to features * migrate userCreationService * migrate insights services to features * migrate ProfileRepository * update imports * migrate filter segmen tests * migrate filter segment repository * migrate getBusyTimes * migrate getLocaleFromRequest * refactor csvUtils * make filename clearer * migrate getLuckyUser integration test * migrate autoLock test to features * wip * refactors * migrate useBookerUrl * migrate more * wip * Migrate eventTypeRepository * membership repository * update imports * update imports * migrate * move organization repository * update imports * update imports * wip * wip * wip * wip * wip * wip * wip * wip * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix tests * fix type checks * fix * fix * migrate * update imports * fix tests * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix
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/features/bookings/repositories/BookingRepository";
|
|
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}`,
|
|
});
|
|
}
|
|
};
|