Files
cal.diy/packages/features/ee/billing/billing-service.ts
T
sean-brydon 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

66 lines
2.1 KiB
TypeScript

import type Stripe from "stripe";
export interface BillingService {
checkoutSessionIsPaid(paymentId: string): Promise<boolean>;
handleSubscriptionCancel(subscriptionId: string): Promise<void>;
handleSubscriptionCreation(subscriptionId: string): Promise<void>;
handleSubscriptionUpdate(args: {
subscriptionId: string;
subscriptionItemId: string;
membershipCount: number;
}): Promise<void>;
// Customer management
createCustomer(args: {
email: string;
metadata?: Record<string, string>;
}): Promise<{ stripeCustomerId: string }>;
createPaymentIntent(args: {
customerId: string;
amount: number;
metadata?: Record<string, string | number>;
}): Promise<{ id: string; client_secret: string | null }>;
// Subscription management
createSubscriptionCheckout(args: {
customerId: string;
successUrl: string;
cancelUrl: string;
priceId: string;
quantity: number;
metadata?: Record<string, string | number>;
mode?: "subscription" | "setup" | "payment";
allowPromotionCodes?: boolean;
customerUpdate?: {
address?: "auto" | "never";
};
automaticTax?: {
enabled: boolean;
};
discounts?: Array<{
coupon: string;
}>;
subscriptionData?: {
metadata?: Record<string, string | number>;
trial_period_days?: number;
};
}): Promise<{ checkoutUrl: string | null; sessionId: string }>;
// Price management
createPrice(args: {
amount: number;
currency: string;
interval: "month" | "year";
nickname?: string;
productId: string;
metadata?: Record<string, string | number>;
}): Promise<{ priceId: string }>;
getPrice(priceId: string): Promise<Stripe.Price | null>;
getSubscriptionStatus(subscriptionId: string): Promise<Stripe.Subscription.Status | null>;
getCheckoutSession(checkoutSessionId: string): Promise<Stripe.Checkout.Session | null>;
getCustomer(customerId: string): Promise<Stripe.Customer | Stripe.DeletedCustomer | null>;
getSubscriptions(customerId: string): Promise<Stripe.Subscription[] | null>;
updateCustomer(args: { customerId: string; email: string; userId?: number }): Promise<void>;
}