Files
calendar/packages/app-store/stripepayment/lib/getCustomerAndCheckoutSession.ts
T
sean-brydonandGitHub 5cd2ba1362 perf: move stripe to billing service out of app store (#20376)
* add more methods to billingService

* update profile handler

* stripe customer handler

* verify email

* move imports + move generic methods to billing service

* move to strip ebilling service class

* push changes to mocks

* fix enum

* fix typo

* correctly update customer metadata

* fix userId type to number

* fix types on billing services

* fix type errors due to return methods differing

* fix return types
2025-03-31 09:20:27 +00:00

26 lines
940 B
TypeScript

import { StripeBillingService } from "@calcom/features/ee/billing/stripe-billling-service";
export async function getCustomerAndCheckoutSession(checkoutSessionId: string) {
const billingService = new StripeBillingService();
const checkoutSession = await billingService.getCheckoutSession(checkoutSessionId);
const customerOrCustomerId = checkoutSession.customer;
let customerId = null;
if (!customerOrCustomerId) {
return { checkoutSession, stripeCustomer: null };
}
if (typeof customerOrCustomerId === "string") {
customerId = customerOrCustomerId;
} else if (customerOrCustomerId.deleted) {
return { checkoutSession, stripeCustomer: null };
} else {
customerId = customerOrCustomerId.id;
}
const stripeCustomer = await billingService.getCustomer(customerId);
if (stripeCustomer.deleted) {
return { checkoutSession, stripeCustomer: null };
}
return { stripeCustomer, checkoutSession };
}