import { AppLoggingService } from "../../../core/logging"; import { CompanyRepository } from "../../company/repositories/company.repository"; import { CompanyService } from "../../company/services/company.service"; import { StripePriceRepository } from "../../stripe-price/repositories/stripe-price.repository"; import { StripeSubscriptionRepository } from "../repositories/stripe-subscription.repository"; export interface TokenAllocationResult { success: boolean; companyId?: string; tokensAllocated?: number; previousTokens?: number; reason?: string; } export declare class TokenAllocationService { private readonly subscriptionRepository; private readonly companyRepository; private readonly companyService; private readonly stripePriceRepository; private readonly logger; constructor(subscriptionRepository: StripeSubscriptionRepository, companyRepository: CompanyRepository, companyService: CompanyService, stripePriceRepository: StripePriceRepository, logger: AppLoggingService); /** * Allocate full tokens on subscription payment (new or renewal) * * Called when invoice.paid webhook is received. Resets company tokens * to full plan amount. Previous unused tokens are lost (no rollover). * * @param params - Allocation parameters * @param params.stripeSubscriptionId - Stripe subscription ID (sub_xxx) * @returns Result indicating success/failure and tokens allocated */ allocateTokensOnPayment(params: { stripeSubscriptionId: string; }): Promise; /** * Allocate pro-rated tokens on mid-cycle plan change * * Called when customer.subscription.updated webhook is received with a price change. * Calculates tokens based on remaining days in billing cycle. * * Formula: floor(newPlanTokens * (remainingDays / totalDays)) * * @param params - Allocation parameters * @param params.stripeSubscriptionId - Stripe subscription ID (sub_xxx) * @param params.newPriceId - Internal price ID (not Stripe price_xxx) * @returns Result indicating success/failure and tokens allocated */ allocateProratedTokensOnPlanChange(params: { stripeSubscriptionId: string; newPriceId: string; }): Promise; /** * Allocate extra tokens for one-time purchases * * Unlike recurring subscriptions which reset monthly tokens, * one-time purchases ADD credits to availableExtraCredits. * * Called when payment_intent.succeeded webhook is received for a one-time purchase. * * @param params - Allocation parameters * @param params.paymentIntentId - Stripe PaymentIntent ID (stored as stripeSubscriptionId for one-time purchases) * @returns Result indicating success/failure and tokens allocated */ allocateExtraTokensOnOneTimePurchase(params: { paymentIntentId: string; }): Promise; /** * Helper to find company from subscription's customer */ private findCompanyBySubscription; } //# sourceMappingURL=token-allocation.service.d.ts.map