* 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>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { PaymentServiceMap } from "@calcom/app-store/payment.services.generated";
|
|
import type { Payment, Prisma, AppCategories } from "@calcom/prisma/client";
|
|
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
|
|
|
|
const deletePayment = async (
|
|
paymentId: Payment["id"],
|
|
paymentAppCredentials: {
|
|
key: Prisma.JsonValue;
|
|
appId: string | null;
|
|
app: {
|
|
dirName: string;
|
|
categories: AppCategories[];
|
|
} | null;
|
|
}
|
|
): Promise<boolean> => {
|
|
const key = paymentAppCredentials?.app?.dirName;
|
|
const paymentAppImportFn = PaymentServiceMap[key as keyof typeof PaymentServiceMap];
|
|
if (!paymentAppImportFn) {
|
|
console.warn(`payment app not implemented for key: ${key}`);
|
|
return false;
|
|
}
|
|
|
|
const paymentAppModule = await paymentAppImportFn;
|
|
if (!paymentAppModule?.PaymentService) {
|
|
console.warn(`payment App service not found for key: ${key}`);
|
|
return false;
|
|
}
|
|
const PaymentService = paymentAppModule.PaymentService;
|
|
const paymentInstance = new PaymentService(paymentAppCredentials) as IAbstractPaymentService;
|
|
const deleted = await paymentInstance.deletePayment(paymentId);
|
|
return deleted;
|
|
};
|
|
|
|
export { deletePayment };
|