Template base para proyectos SaaS multi-tenant. Estructura inicial: - apps/backend (NestJS API) - apps/frontend (React/Vite) - apps/database (PostgreSQL DDL) - docs/ (Documentación) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
54 lines
2.6 KiB
TypeScript
54 lines
2.6 KiB
TypeScript
import { Repository } from 'typeorm';
|
|
import { Subscription, SubscriptionStatus } from '../entities/subscription.entity';
|
|
import { Invoice } from '../entities/invoice.entity';
|
|
import { PaymentMethod } from '../entities/payment-method.entity';
|
|
import { CreateSubscriptionDto } from '../dto/create-subscription.dto';
|
|
import { UpdateSubscriptionDto, CancelSubscriptionDto } from '../dto/update-subscription.dto';
|
|
import { CreatePaymentMethodDto } from '../dto/create-payment-method.dto';
|
|
export declare class BillingService {
|
|
private readonly subscriptionRepo;
|
|
private readonly invoiceRepo;
|
|
private readonly paymentMethodRepo;
|
|
constructor(subscriptionRepo: Repository<Subscription>, invoiceRepo: Repository<Invoice>, paymentMethodRepo: Repository<PaymentMethod>);
|
|
createSubscription(dto: CreateSubscriptionDto): Promise<Subscription>;
|
|
getSubscription(tenantId: string): Promise<Subscription | null>;
|
|
updateSubscription(tenantId: string, dto: UpdateSubscriptionDto): Promise<Subscription>;
|
|
cancelSubscription(tenantId: string, dto: CancelSubscriptionDto): Promise<Subscription>;
|
|
changePlan(tenantId: string, newPlanId: string): Promise<Subscription>;
|
|
renewSubscription(tenantId: string): Promise<Subscription>;
|
|
createInvoice(tenantId: string, subscriptionId: string, lineItems: Array<{
|
|
description: string;
|
|
quantity: number;
|
|
unit_price: number;
|
|
}>): Promise<Invoice>;
|
|
getInvoices(tenantId: string, options?: {
|
|
page?: number;
|
|
limit?: number;
|
|
}): Promise<{
|
|
data: Invoice[];
|
|
total: number;
|
|
page: number;
|
|
limit: number;
|
|
}>;
|
|
getInvoice(invoiceId: string, tenantId: string): Promise<Invoice>;
|
|
markInvoicePaid(invoiceId: string, tenantId: string): Promise<Invoice>;
|
|
voidInvoice(invoiceId: string, tenantId: string): Promise<Invoice>;
|
|
private generateInvoiceNumber;
|
|
addPaymentMethod(tenantId: string, dto: CreatePaymentMethodDto): Promise<PaymentMethod>;
|
|
getPaymentMethods(tenantId: string): Promise<PaymentMethod[]>;
|
|
getDefaultPaymentMethod(tenantId: string): Promise<PaymentMethod | null>;
|
|
setDefaultPaymentMethod(paymentMethodId: string, tenantId: string): Promise<PaymentMethod>;
|
|
removePaymentMethod(paymentMethodId: string, tenantId: string): Promise<void>;
|
|
getBillingSummary(tenantId: string): Promise<{
|
|
subscription: Subscription | null;
|
|
defaultPaymentMethod: PaymentMethod | null;
|
|
pendingInvoices: number;
|
|
totalDue: number;
|
|
}>;
|
|
checkSubscriptionStatus(tenantId: string): Promise<{
|
|
isActive: boolean;
|
|
daysRemaining: number;
|
|
status: SubscriptionStatus;
|
|
}>;
|
|
}
|