refactor: use WebhookService in payments router (#16108)
This commit is contained in:
@@ -3,10 +3,9 @@ import { z } from "zod";
|
||||
import appStore from "@calcom/app-store";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { sendNoShowFeeChargedEmail } from "@calcom/emails";
|
||||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
import { WebhookService } from "@calcom/features/webhooks/lib/WebhookService";
|
||||
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import sendPayload from "@calcom/lib/server/webhooks/sendPayload";
|
||||
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
@@ -128,27 +127,20 @@ export const paymentsRouter = router({
|
||||
|
||||
const userId = ctx.user.id || 0;
|
||||
const orgId = await getOrgIdFromMemberOrTeamId({ memberId: userId });
|
||||
|
||||
const subscriberOptions = {
|
||||
const eventTypeId = booking.eventTypeId || 0;
|
||||
const webhooks = await new WebhookService({
|
||||
userId,
|
||||
eventTypeId: booking.eventTypeId || 0,
|
||||
eventTypeId,
|
||||
triggerEvent: WebhookTriggerEvents.BOOKING_PAID,
|
||||
orgId,
|
||||
};
|
||||
|
||||
const subscribers = await getWebhooks(subscriberOptions);
|
||||
|
||||
await Promise.all(
|
||||
subscribers.map(async (subscriber) => {
|
||||
sendPayload(subscriber.secret, WebhookTriggerEvents.BOOKING_PAID, {
|
||||
...evt,
|
||||
bookingId: booking.id,
|
||||
paymentId: payment.id,
|
||||
paymentData,
|
||||
eventTypeId: subscriberOptions.eventTypeId,
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
await webhooks.sendPayload({
|
||||
...evt,
|
||||
bookingId: booking.id,
|
||||
paymentId: payment.id,
|
||||
paymentData,
|
||||
eventTypeId,
|
||||
});
|
||||
|
||||
await sendNoShowFeeChargedEmail(
|
||||
attendeesListPromises[0],
|
||||
|
||||
Reference in New Issue
Block a user