feat: refund policies for payment apps (#18428)

* feat: refund policies for payment apps

* tests for payment refund

---------

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
Amit SharmaandPeer Richelsen authored and GitHub committed 2025-01-06 11:36:37 +00:00
1 parent e722e75a6f
commit c1dbb7cffd
23 files changed
+559 -85

No files matched your search

@@ -11,7 +11,7 @@ import "@calcom/dayjs/locales";
import ViewRecordingsDialog from "@calcom/features/ee/video/ViewRecordingsDialog";
import classNames from "@calcom/lib/classNames";
import { formatTime } from "@calcom/lib/date-fns";
import getPaymentAppData from "@calcom/lib/getPaymentAppData";
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
import { useCopy } from "@calcom/lib/hooks/useCopy";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useGetTheme } from "@calcom/lib/hooks/useTheme";
@@ -2737,6 +2737,12 @@
"month_to_date": "month to date",
"year_to_date": "year to date",
"custom_range": "custom range",
"refund_policy": "Refund Policy",
"always": "Always",
"never": "Never",
"payment_option": "Payment Option",
"if_cancelled": "If cancelled",
"before": "before",
"show_all_columns": "Show all columns",
"toggle_columns": "Toggle columns",
"no_columns_found": "No columns found",
@@ -24,7 +24,7 @@ import type {
WorkflowTriggerEvents,
WorkflowMethods,
} from "@calcom/prisma/client";
import type { SchedulingType, SMSLockState, TimeUnit } from "@calcom/prisma/enums";
import type { PaymentOption, SchedulingType, SMSLockState, TimeUnit } from "@calcom/prisma/enums";
import type { BookingStatus } from "@calcom/prisma/enums";
import type { teamMetadataSchema } from "@calcom/prisma/zod-utils";
import type { userMetadataType } from "@calcom/prisma/zod-utils";
@@ -74,6 +74,21 @@ type InputWorkflow = {
sendTo?: string;
};
type InputPayment = {
id?: number;
uid: string;
appId?: string | null;
bookingId: number;
amount: number;
fee: number;
currency: string;
success: boolean;
refunded: boolean;
data: Record<string, any>;
externalId: string;
paymentOption?: PaymentOption;
};
type InputWorkflowReminder = {
id?: number;
bookingUid: string;
@@ -108,6 +123,7 @@ export type ScenarioData = {
bookings?: InputBooking[];
webhooks?: InputWebhook[];
workflows?: InputWorkflow[];
payment?: InputPayment[];
};
type InputCredential = typeof TestData.credentials.google & {
@@ -535,6 +551,12 @@ async function addWebhooksToDb(webhooks: any[]) {
});
}
async function addPaymentToDb(payment: InputPayment[]) {
await prismock.payment.createMany({
data: payment,
});
}
async function addWebhooks(webhooks: InputWebhook[]) {
log.silly("TestData: Creating Webhooks", safeStringify(webhooks));
@@ -810,6 +832,7 @@ export async function createBookingScenario(data: ScenarioData) {
await addWebhooks(data.webhooks || []);
// addPaymentMock();
const workflows = await addWorkflows(data.workflows || []);
await addPaymentToDb(data.payment || []);
return {
eventTypes,
@@ -1304,6 +1327,7 @@ export function getScenarioData(
webhooks,
workflows,
bookings,
payment,
}: {
organizer?: ReturnType<typeof getOrganizer>;
eventTypes: ScenarioData["eventTypes"];
@@ -1313,6 +1337,7 @@ export function getScenarioData(
webhooks?: ScenarioData["webhooks"];
workflows?: ScenarioData["workflows"];
bookings?: ScenarioData["bookings"];
payment?: ScenarioData["payment"];
},
org?: { id: number | null } | undefined | null
) {
@@ -1373,6 +1398,7 @@ export function getScenarioData(
webhooks,
bookings: bookings || [],
workflows,
payment,
} satisfies ScenarioData;
}