import { ISubscriptionRepository } from '../repositories/ISubscriptionRepository.js'; import { ICustomerRepository } from '../repositories/ICustomerRepository.js'; import { IPlanRepository } from '../repositories/IPlanRepository.js'; import { IBillingCycleRepository } from '../repositories/IBillingCycleRepository.js'; import { Subscription } from '../../domain/entities/Subscription.js'; import { default as Stripe } from 'stripe'; import { HookDispatcher } from '../hooks/HookDispatcher.js'; export declare class StripeIntegrationService { private readonly subscriptionRepository; private readonly customerRepository; private readonly planRepository; private readonly billingCycleRepository; private readonly config?; private readonly hooks; constructor(subscriptionRepository: ISubscriptionRepository, customerRepository: ICustomerRepository, planRepository: IPlanRepository, billingCycleRepository: IBillingCycleRepository, config?: { stripe?: { secretKey?: string; webhookSecret?: string; }; } | undefined, hooks?: HookDispatcher); private emitCustomerBefore; private emitCustomerAfter; private toSubscriptionDto; private emitSubscriptionBefore; private emitSubscriptionAfter; private saveSubscriptionWithHooks; private saveCustomerWithHooks; /** * Process a verified Stripe event * NOTE: Signature verification MUST be done by implementor before calling this */ processStripeEvent(event: Stripe.Event): Promise; private handleSubscriptionCreated; private handleSubscriptionUpdated; private handleSubscriptionDeleted; private getInvoiceSubscriptionId; private getInvoiceLinePriceId; private handlePaymentSucceeded; /** * Find billing cycle by Stripe price ID (stored in externalProductId) */ private findBillingCycleByStripePriceId; /** * Creating Stripe subscriptions from Subscrio is not supported. * Use `createCheckoutSession` or `processStripeEvent` instead. * @deprecated Use processStripeEvent or createCheckoutSession instead. */ createStripeSubscription(_customerKey: string, _planKey: string, _billingCycleKey: string, _stripePriceId: string): Promise; /** * Verify a Stripe webhook signature and construct an Event. * Requires `config.stripe.webhookSecret` (`whsec_...`). */ constructStripeEvent(payload: string | Buffer, signatureHeader: string): Stripe.Event; private resolveCustomer; private getMetadataValue; private extractCustomerId; private extractStripeEventRefs; private extractOptionalCustomerId; private resolvePlanFromSubscription; /** * Find the subscription item that matches the billing cycle's Stripe price ID * and extract period dates from it */ private getPeriodDatesFromStripeSubscription; private applyStripeSubscriptionFields; private mapStripeStatus; private toDateOrUndefined; private toDateOrDefault; /** * Merge Stripe schedule ID into subscription metadata * If schedule is present, adds it to metadata as 'stripeScheduleId' * If schedule is null/undefined, removes it from metadata */ private mergeScheduleIntoMetadata; private handleCustomerUpsert; private handleCustomerDeleted; /** * Find subscription by metadata (subscription key) * Verifies the subscription belongs to the specified customer */ private findSubscriptionByMetadata; /** * Get Stripe client instance * Uses provided secret key or falls back to config */ private getStripeClient; /** * Create a Stripe Checkout Session URL for subscription purchase * * This helper method: * - Ensures the customer exists in Stripe (creates if needed) * - Sets proper metadata for webhook linking * - Supports linking to existing Subscrio subscriptions * - Provides full access to Stripe Checkout options */ createCheckoutSession(params: { customerKey: string; billingCycleKey: string; subscriptionKey?: string; stripeSecretKey?: string; successUrl: string; cancelUrl: string; quantity?: number; customerEmail?: string; customerName?: string; allowPromotionCodes?: boolean; billingAddressCollection?: 'auto' | 'required'; paymentMethodTypes?: Stripe.Checkout.SessionCreateParams.PaymentMethodType[]; trialPeriodDays?: number; metadata?: Record; stripeOptions?: Partial; }): Promise<{ url: string; sessionId: string; }>; } //# sourceMappingURL=StripeIntegrationService.d.ts.map