fix: Handle payment flow webhooks in case of event requiring confirmation (#11458)

Co-authored-by: alannnc <[email protected]>
This commit is contained in:
Hariom Balharaandalannnc authored and GitHub committed 2023-09-30 10:22:32 +05:30
1 parent 0bb99fc667
commit 20898e1505
29 files changed
+3379 -1656

No files matched your search

+3
View File
@@ -260,6 +260,9 @@ export const createEvent = async (
return undefined;
})
: undefined;
if (!creationResult) {
logger.silly("createEvent failed", { success, uid, creationResult, originalEvent: calEvent, calError });
}
return {
appName: credential.appId || "",
+14 -3
View File
@@ -80,6 +80,7 @@ export default class EventManager {
* @param user
*/
constructor(user: EventManagerUser) {
logger.silly("Initializing EventManager", JSON.stringify({ user }));
const appCredentials = getApps(user.credentials, true).flatMap((app) =>
app.credentials.map((creds) => ({ ...creds, appName: app.name }))
);
@@ -312,7 +313,6 @@ export default class EventManager {
},
});
}
return {
results,
referencesToCreate: [...booking.references],
@@ -361,6 +361,7 @@ export default class EventManager {
[] as DestinationCalendar[]
);
for (const destination of destinationCalendars) {
logger.silly("Creating Calendar event", JSON.stringify({ destination }));
if (destination.credentialId) {
let credential = this.calendarCredentials.find((c) => c.id === destination.credentialId);
if (!credential) {
@@ -400,13 +401,21 @@ export default class EventManager {
}
}
} else {
logger.silly(
"No destination Calendar found, falling back to first connected calendar",
JSON.stringify({
calendarCredentials: this.calendarCredentials,
})
);
/**
* Not ideal but, if we don't find a destination calendar,
* fallback to the first connected calendar
* fallback to the first connected calendar - Shouldn't be a CRM calendar
*/
const [credential] = this.calendarCredentials.filter((cred) => cred.type === "calendar");
const [credential] = this.calendarCredentials.filter((cred) => !cred.type.endsWith("other_calendar"));
if (credential) {
const createdEvent = await createEvent(credential, event);
logger.silly("Created Calendar event", { createdEvent });
if (createdEvent) {
createdEvents.push(createdEvent);
}
@@ -503,6 +512,7 @@ export default class EventManager {
): Promise<Array<EventResult<NewCalendarEventType>>> {
let calendarReference: PartialReference[] | undefined = undefined,
credential;
logger.silly("updateAllCalendarEvents", JSON.stringify({ event, booking, newBookingId }));
try {
// If a newBookingId is given, update that calendar event
let newBooking;
@@ -564,6 +574,7 @@ export default class EventManager {
(credential) => credential.type === reference?.type
);
for (const credential of credentials) {
logger.silly("updateAllCalendarEvents-credential", JSON.stringify({ credentials }));
result.push(updateEvent(credential, event, bookingRefUid, calenderExternalId));
}
}
+17 -12
View File
@@ -24,6 +24,7 @@ const getVideoAdapters = async (withCredentials: CredentialPayload[]): Promise<V
for (const cred of withCredentials) {
const appName = cred.type.split("_").join(""); // Transform `zoom_video` to `zoomvideo`;
logger.silly("getVideoAdapters", JSON.stringify({ appName, cred }));
const appImportFn = appStore[appName as keyof typeof appStore];
// Static Link Video Apps don't exist in packages/app-store/index.ts(it's manually maintained at the moment) and they aren't needed there anyway.
@@ -38,6 +39,8 @@ const getVideoAdapters = async (withCredentials: CredentialPayload[]): Promise<V
const makeVideoApiAdapter = app.lib.VideoApiAdapter as VideoApiAdapterFactory;
const videoAdapter = makeVideoApiAdapter(cred);
videoAdapters.push(videoAdapter);
} else {
log.error(`App ${appName} doesn't have 'lib.VideoApiAdapter' defined`);
}
}
@@ -51,7 +54,7 @@ const getBusyVideoTimes = async (withCredentials: CredentialPayload[]) =>
const createMeeting = async (credential: CredentialPayload, calEvent: CalendarEvent) => {
const uid: string = getUid(calEvent);
log.silly("videoClient:createMeeting", JSON.stringify({ credential, uid, calEvent }));
if (!credential || !credential.appId) {
throw new Error(
"Credentials must be set! Video platforms are optional, so this method shouldn't even be called when no video credentials are set."
@@ -116,21 +119,23 @@ const updateMeeting = async (
bookingRef: PartialReference | null
): Promise<EventResult<VideoCallData>> => {
const uid = translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
let success = true;
const [firstVideoAdapter] = await getVideoAdapters([credential]);
const updatedMeeting =
credential && bookingRef
? await firstVideoAdapter?.updateMeeting(bookingRef, calEvent).catch(async (e) => {
await sendBrokenIntegrationEmail(calEvent, "video");
log.error("updateMeeting failed", e, calEvent);
success = false;
return undefined;
})
: undefined;
const canCallUpdateMeeting = !!(credential && bookingRef);
const updatedMeeting = canCallUpdateMeeting
? await firstVideoAdapter?.updateMeeting(bookingRef, calEvent).catch(async (e) => {
await sendBrokenIntegrationEmail(calEvent, "video");
log.error("updateMeeting failed", e, calEvent);
success = false;
return undefined;
})
: undefined;
if (!updatedMeeting) {
log.error(
"updateMeeting failed",
JSON.stringify({ bookingRef, canCallUpdateMeeting, calEvent, credential })
);
return {
appName: credential.appId || "",
type: credential.type,