cal/packages/lib/payment/deletePayment.ts
Efraín Rochín d6fb0df64f
perf: tRPC procedures and middleware refactor (#8419)
* trpc procedures an middleware refactor

* allow use sessionMiddleware without a req object

* sync with the new tRPC structure

* tRPC refactor on routing form app

* import Prisma from @prisma/client

* Lazy load apps from appstore

* remove unrelated changes

* Add types for PaymentService

* type fixes

* Merge branch 'main' into roae85/cal-1514-set-the-user-session-only-on-the

* fix typo

* remove console.log

* remove explicit types from apstore object

* linter fixes

---------

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
2023-05-09 19:27:05 +00:00

31 lines
1.1 KiB
TypeScript

import type { Payment, Prisma } from "@prisma/client";
import appStore from "@calcom/app-store";
import type { AppCategories } from "@calcom/prisma/enums";
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 paymentApp = await appStore[paymentAppCredentials?.app?.dirName as keyof typeof appStore]();
if (!(paymentApp && "lib" in paymentApp && "PaymentService" in paymentApp.lib)) {
console.warn(`payment App service of type ${paymentApp} is not implemented`);
return false;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const PaymentService = paymentApp.lib.PaymentService as any;
const paymentInstance = new PaymentService(paymentAppCredentials) as IAbstractPaymentService;
const deleted = await paymentInstance.deletePayment(paymentId);
return deleted;
};
export { deletePayment };