Ensures json fields on each call (#2893)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>pull/2894/head^2
parent
9710c6faa6
commit
24a3bfdf78
|
@ -1,6 +1,7 @@
|
||||||
import { PaymentType, Prisma } from "@prisma/client";
|
import { PaymentType, Prisma } from "@prisma/client";
|
||||||
import Stripe from "stripe";
|
import Stripe from "stripe";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
|
import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
|
||||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||||
|
@ -17,8 +18,15 @@ export type PaymentInfo = {
|
||||||
id?: string | null;
|
id?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
let paymentFeePercentage: number | undefined;
|
const stripeKeysSchema = z.object({
|
||||||
let paymentFeeFixed: number | undefined;
|
payment_fee_fixed: z.number(),
|
||||||
|
payment_fee_percentage: z.number(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const stripeCredentialSchema = z.object({
|
||||||
|
stripe_user_id: z.string(),
|
||||||
|
stripe_publishable_key: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
export async function handlePayment(
|
export async function handlePayment(
|
||||||
evt: CalendarEvent,
|
evt: CalendarEvent,
|
||||||
|
@ -35,13 +43,10 @@ export async function handlePayment(
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const appKeys = await getAppKeysFromSlug("stripe");
|
const appKeys = await getAppKeysFromSlug("stripe");
|
||||||
if (typeof appKeys.payment_fee_fixed === "number") paymentFeePercentage = appKeys.payment_fee_fixed;
|
const { payment_fee_fixed, payment_fee_percentage } = stripeKeysSchema.parse(appKeys);
|
||||||
if (typeof appKeys.payment_fee_percentage === "number") paymentFeeFixed = appKeys.payment_fee_percentage;
|
|
||||||
|
|
||||||
const paymentFee = Math.round(
|
const paymentFee = Math.round(selectedEventType.price * payment_fee_percentage + payment_fee_fixed);
|
||||||
selectedEventType.price * parseFloat(`${paymentFeePercentage}`) + parseInt(`${paymentFeeFixed}`)
|
const { stripe_user_id, stripe_publishable_key } = stripeCredentialSchema.parse(stripeCredential.key);
|
||||||
);
|
|
||||||
const { stripe_user_id, stripe_publishable_key } = stripeCredential.key as Stripe.OAuthToken;
|
|
||||||
|
|
||||||
const params: Stripe.PaymentIntentCreateParams = {
|
const params: Stripe.PaymentIntentCreateParams = {
|
||||||
amount: selectedEventType.price,
|
amount: selectedEventType.price,
|
||||||
|
|
Loading…
Reference in New Issue