Skip to content

Scheduling infrastructure for absolutely everyone.

Save currency to db (#3086)

Joe Au-Yeungb339736a6fc3
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json
index 8e5acbc1e0f..84e3b47d3b6 100644
--- a/apps/web/public/static/locales/en/common.json
+++ b/apps/web/public/static/locales/en/common.json
@@ -910,5 +910,6 @@
"add_exchange2013": "Connect Exchange 2013 Server",
"add_exchange2016": "Connect Exchange 2016 Server",
"specific_issue": "Have a specific issue",
- "browse_our_docs": "browse our docs"
+ "browse_our_docs": "browse our docs",
+ "attendee_name": "Attendee's name"
}
diff --git a/apps/web/server/routers/viewer/eventTypes.tsx b/apps/web/server/routers/viewer/eventTypes.tsx
index 2b4fbba90e6..bbc5374255e 100644
--- a/apps/web/server/routers/viewer/eventTypes.tsx
+++ b/apps/web/server/routers/viewer/eventTypes.tsx
@@ -6,6 +6,7 @@ import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
import { _DestinationCalendarModel, _EventTypeCustomInputModel, _EventTypeModel } from "@calcom/prisma/zod";
import { stringOrNumber } from "@calcom/prisma/zod-utils";
import { createEventTypeInput } from "@calcom/prisma/zod/custom/eventtype";
+import { stripeDataSchema } from "@calcom/stripe/server";
import { createProtectedRouter } from "@server/createRouter";
import { viewerRouter } from "@server/routers/viewer";
@@ -265,6 +266,7 @@ export const eventTypesRouter = createProtectedRouter()
users,
id,
hashedLink,
+ price,
...rest
} = input;
assertValidUrl(input.successRedirectUrl);
@@ -314,6 +316,26 @@ export const eventTypesRouter = createProtectedRouter()
};
}
+ if (price) {
+ const paymentCredential = await ctx.prisma.credential.findFirst({
+ where: {
+ userId: ctx.user.id,
+ type: {
+ contains: "_payment",
+ },
+ },
+ select: {
+ type: true,
+ key: true,
+ },
+ });
+
+ if (paymentCredential?.type === "stripe_payment") {
+ const { default_currency } = stripeDataSchema.parse(paymentCredential.key);
+ data.currency = default_currency;
+ }
+ }
+
const connectedLink = await ctx.prisma.hashedLink.findFirst({
where: {
eventTypeId: input.id,
diff --git a/packages/stripe/server.ts b/packages/stripe/server.ts
index ffb7a57ec4f..7194436a3e2 100644
--- a/packages/stripe/server.ts
+++ b/packages/stripe/server.ts
@@ -1,13 +1,26 @@
import Stripe from "stripe";
+import { z } from "zod";
export type PaymentData = Stripe.Response<Stripe.PaymentIntent> & {
stripe_publishable_key: string;
stripeAccount: string;
};
-export type StripeData = Stripe.OAuthToken & {
- default_currency: string;
-};
+export const stripeOAuthTokenSchema = z.object({
+ access_token: z.string().optional(),
+ scope: z.string().optional(),
+ livemode: z.boolean().optional(),
+ token_type: z.literal("bearer").optional(),
+ refresh_token: z.string().optional(),
+ stripe_user_id: z.string().optional(),
+ stripe_publishable_key: z.string().optional(),
+});
+
+export const stripeDataSchema = stripeOAuthTokenSchema.extend({
+ default_currency: z.string(),
+});
+
+export type StripeData = z.infer<typeof stripeDataSchema>;
const stripePrivateKey = process.env.STRIPE_PRIVATE_KEY!;