fix: Update Event Type Pricing For Multiple Installed Payment Apps (#12272)
* Prevent two payment apps from being enabled * Find the enabled payment app to update the event type * Add string * Add tests * Type fix * Abstract check for multiple payment app logic * Type check * Address feedback * chore: Enable One Payment App Per Event Type (#12414) Co-authored-by: Morgan <[email protected]> Co-authored-by: Morgan Vernay <[email protected]> * Fix bug * Fix test * Clean up * Fix test * Fix test --------- Co-authored-by: Morgan <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Omar López <[email protected]> Co-authored-by: Morgan Vernay <[email protected]> Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
15 files changed
+273
-53
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import type { NextApiResponse, GetServerSidePropsContext } from "next";
|
||||
|
||||
import type { appDataSchemas } from "@calcom/app-store/apps.schemas.generated";
|
||||
import updateChildrenEventTypes from "@calcom/features/ee/managed-event-types/lib/handleChildrenEventTypes";
|
||||
import { validateIntervalLimitOrder } from "@calcom/lib";
|
||||
import logger from "@calcom/lib/logger";
|
||||
@@ -240,31 +241,14 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Since you can have multiple payment apps we will honor the first one to save in eventType
|
||||
* but the real detail will be inside app metadata, so with this you can have different prices in different apps
|
||||
* So the price and currency inside eventType will be deprecated soon or just keep as reference.
|
||||
*/
|
||||
if (
|
||||
input.metadata?.apps?.alby?.price ||
|
||||
input?.metadata?.apps?.paypal?.price ||
|
||||
input?.metadata?.apps?.stripe?.price
|
||||
) {
|
||||
data.price =
|
||||
input.metadata?.apps?.alby?.price ||
|
||||
input.metadata.apps.paypal?.price ||
|
||||
input.metadata.apps.stripe?.price;
|
||||
}
|
||||
|
||||
if (
|
||||
input.metadata?.apps?.alby?.currency ||
|
||||
input?.metadata?.apps?.paypal?.currency ||
|
||||
input?.metadata?.apps?.stripe?.currency
|
||||
) {
|
||||
data.currency =
|
||||
input.metadata?.apps?.alby?.currency ||
|
||||
input.metadata.apps.paypal?.currency ||
|
||||
input.metadata.apps.stripe?.currency;
|
||||
for (const appKey in input.metadata?.apps) {
|
||||
const app = input.metadata?.apps[appKey as keyof typeof appDataSchemas];
|
||||
// There should only be one enabled payment app in the metadata
|
||||
if (app.enabled && app.price && app.currency) {
|
||||
data.price = app.price;
|
||||
data.currency = app.currency;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const connectedLink = await ctx.prisma.hashedLink.findFirst({
|
||||
|
||||
Reference in new issue
Block a user