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 <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2022-06-20 19:09:22 +00:00
1 parent 89ef6c3f13
commit b339736a6f
3 files changed
+40 -4

No files matched your search

@@ -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"
}
@@ -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,