Files
cal.diy/packages/features/ee/billing/service/billingProvider/IBillingProviderService.ts
T
sean-brydonandClaude Opus 4.5 ea76df47d2 feat: add invoice URL to proration and test seed scripts (#27297)
* feat: add invoice URL to proration and test seed scripts

- Add invoiceUrl field to MonthlyProration schema
- Update billing service to return hosted_invoice_url after finalizing
- Save invoice URL when creating proration invoices
- Add seed script for testing proration with real Stripe data
- Add cleanup script for test data removal

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* add invoice url

* add invoice URL to tests

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
2026-01-28 09:42:57 +00:00

127 lines
3.9 KiB
TypeScript

import type Stripe from "stripe";
import type { SubscriptionStatus } from "../../repository/billing/IBillingRepository";
export interface IBillingProviderService {
checkoutSessionIsPaid(paymentId: string): Promise<boolean>;
handleSubscriptionCancel(subscriptionId: string): Promise<void>;
handleSubscriptionCreation(subscriptionId: string): Promise<void>;
handleSubscriptionUpdate(args: {
subscriptionId: string;
subscriptionItemId: string;
membershipCount: number;
prorationBehavior?: "none" | "create_prorations" | "always_invoice";
}): Promise<void>;
handleEndTrial(subscriptionId: string): 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<SubscriptionStatus | 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>;
// Invoice management
createInvoiceItem(args: {
customerId: string;
amount: number;
currency: string;
description: string;
subscriptionId?: string;
invoiceId?: string;
metadata?: Record<string, string>;
}): Promise<{ invoiceItemId: string }>;
deleteInvoiceItem(invoiceItemId: string): Promise<void>;
createInvoice(args: {
customerId: string;
autoAdvance: boolean;
collectionMethod?: "charge_automatically" | "send_invoice";
daysUntilDue?: number;
pendingInvoiceItemsBehavior?: "exclude" | "include";
subscriptionId?: string;
metadata?: Record<string, string>;
}): Promise<{ invoiceId: string }>;
finalizeInvoice(invoiceId: string): Promise<{ invoiceUrl: string | null }>;
voidInvoice(invoiceId: string): Promise<void>;
getPaymentIntentFailureReason(paymentIntentId: string): Promise<string | null>;
hasDefaultPaymentMethod(args: { customerId: string; subscriptionId?: string }): Promise<boolean>;
// Usage-based billing
createSubscriptionUsageRecord(args: {
subscriptionId: string;
action: "increment" | "set";
quantity: number;
}): Promise<void>;
// Subscription queries
getSubscription(subscriptionId: string): Promise<{
items: Array<{
id: string;
quantity: number;
price: {
unit_amount: number | null;
recurring: {
interval: string;
} | null;
};
}>;
customer: string;
status: string;
current_period_start: number;
current_period_end: number;
trial_end: number | null;
} | null>;
}