Skip to content

Commit b339736

Browse files
joeauyeungPeerRichzomarskodiakhq[bot]
authored
Save currency to db (#3086)
* Save currency to db * Add missing translation * Get currency from user credentials server side * Adds stripe data schema Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 89ef6c3 commit b339736

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

apps/web/public/static/locales/en/common.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -910,5 +910,6 @@
910910
"add_exchange2013": "Connect Exchange 2013 Server",
911911
"add_exchange2016": "Connect Exchange 2016 Server",
912912
"specific_issue": "Have a specific issue",
913-
"browse_our_docs": "browse our docs"
913+
"browse_our_docs": "browse our docs",
914+
"attendee_name": "Attendee's name"
914915
}

apps/web/server/routers/viewer/eventTypes.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
66
import { _DestinationCalendarModel, _EventTypeCustomInputModel, _EventTypeModel } from "@calcom/prisma/zod";
77
import { stringOrNumber } from "@calcom/prisma/zod-utils";
88
import { createEventTypeInput } from "@calcom/prisma/zod/custom/eventtype";
9+
import { stripeDataSchema } from "@calcom/stripe/server";
910

1011
import { createProtectedRouter } from "@server/createRouter";
1112
import { viewerRouter } from "@server/routers/viewer";
@@ -265,6 +266,7 @@ export const eventTypesRouter = createProtectedRouter()
265266
users,
266267
id,
267268
hashedLink,
269+
price,
268270
...rest
269271
} = input;
270272
assertValidUrl(input.successRedirectUrl);
@@ -314,6 +316,26 @@ export const eventTypesRouter = createProtectedRouter()
314316
};
315317
}
316318

319+
if (price) {
320+
const paymentCredential = await ctx.prisma.credential.findFirst({
321+
where: {
322+
userId: ctx.user.id,
323+
type: {
324+
contains: "_payment",
325+
},
326+
},
327+
select: {
328+
type: true,
329+
key: true,
330+
},
331+
});
332+
333+
if (paymentCredential?.type === "stripe_payment") {
334+
const { default_currency } = stripeDataSchema.parse(paymentCredential.key);
335+
data.currency = default_currency;
336+
}
337+
}
338+
317339
const connectedLink = await ctx.prisma.hashedLink.findFirst({
318340
where: {
319341
eventTypeId: input.id,

packages/stripe/server.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
import Stripe from "stripe";
2+
import { z } from "zod";
23

34
export type PaymentData = Stripe.Response<Stripe.PaymentIntent> & {
45
stripe_publishable_key: string;
56
stripeAccount: string;
67
};
78

8-
export type StripeData = Stripe.OAuthToken & {
9-
default_currency: string;
10-
};
9+
export const stripeOAuthTokenSchema = z.object({
10+
access_token: z.string().optional(),
11+
scope: z.string().optional(),
12+
livemode: z.boolean().optional(),
13+
token_type: z.literal("bearer").optional(),
14+
refresh_token: z.string().optional(),
15+
stripe_user_id: z.string().optional(),
16+
stripe_publishable_key: z.string().optional(),
17+
});
18+
19+
export const stripeDataSchema = stripeOAuthTokenSchema.extend({
20+
default_currency: z.string(),
21+
});
22+
23+
export type StripeData = z.infer<typeof stripeDataSchema>;
1124

1225
const stripePrivateKey = process.env.STRIPE_PRIVATE_KEY!;
1326

0 commit comments

Comments
 (0)