* 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
26 lines
940 B
TypeScript
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 };
|
|
}
|