feat: Add auto payment methods for paid booking on Stripe (#18513)
This commit is contained in:
@@ -88,6 +88,9 @@ export class PaymentService implements IAbstractPaymentService {
|
||||
amount: payment.amount,
|
||||
currency: payment.currency,
|
||||
customer: customer.id,
|
||||
automatic_payment_methods: {
|
||||
enabled: true,
|
||||
},
|
||||
metadata: {
|
||||
identifier: "cal.com",
|
||||
bookingId,
|
||||
@@ -259,7 +262,7 @@ export class PaymentService implements IAbstractPaymentService {
|
||||
throw new Error(`Stripe paymentMethod does not exist for setupIntent ${setupIntent.id}`);
|
||||
}
|
||||
|
||||
const params = {
|
||||
const params: Stripe.PaymentIntentCreateParams = {
|
||||
amount: payment.amount,
|
||||
currency: payment.currency,
|
||||
application_fee_amount: paymentFee,
|
||||
|
||||
@@ -7,6 +7,17 @@ import { eventTypeAppMetadataOptionalSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { IAbstractPaymentService, PaymentApp } from "@calcom/types/PaymentService";
|
||||
|
||||
const isPaymentApp = (x: unknown): x is PaymentApp =>
|
||||
!!x &&
|
||||
typeof x === "object" &&
|
||||
"lib" in x &&
|
||||
typeof x.lib === "object" &&
|
||||
!!x.lib &&
|
||||
"PaymentService" in x.lib;
|
||||
|
||||
const isKeyOf = <T extends object>(obj: T, key: unknown): key is keyof T =>
|
||||
typeof key === "string" && key in obj;
|
||||
|
||||
const handlePayment = async ({
|
||||
evt,
|
||||
selectedEventType,
|
||||
@@ -40,16 +51,17 @@ const handlePayment = async ({
|
||||
isDryRun?: boolean;
|
||||
}) => {
|
||||
if (isDryRun) return null;
|
||||
const paymentApp = (await appStore[
|
||||
paymentAppCredentials?.app?.dirName as keyof typeof appStore
|
||||
]?.()) as PaymentApp;
|
||||
if (!paymentApp?.lib?.PaymentService) {
|
||||
const key = paymentAppCredentials?.app?.dirName;
|
||||
if (!isKeyOf(appStore, key)) {
|
||||
console.warn(`key: ${key} is not a valid key in appStore`);
|
||||
return null;
|
||||
}
|
||||
const paymentApp = await appStore[key]?.();
|
||||
if (!isPaymentApp(paymentApp)) {
|
||||
console.warn(`payment App service of type ${paymentApp} is not implemented`);
|
||||
return null;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const PaymentService = paymentApp.lib.PaymentService as any;
|
||||
|
||||
const PaymentService = paymentApp.lib.PaymentService;
|
||||
const paymentInstance = new PaymentService(paymentAppCredentials) as IAbstractPaymentService;
|
||||
|
||||
const apps = eventTypeAppMetadataOptionalSchema.parse(selectedEventType?.metadata?.apps);
|
||||
|
||||
Reference in New Issue
Block a user