/**
 * Stripe Payment Service
 *
 * Singleton service for Stripe API interactions. Handles checkout sessions,
 * subscriptions, customer portal sessions, and webhook event processing.
 * Syncs subscription lifecycle events to the Supabase `subscriptions` table.
 *
 * Requires STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET environment variables.
 * Requires CREWLY_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY for webhook sync.
 * Returns { success: false, message: 'Stripe is not configured' } when keys
 * are missing, allowing the app to run without Stripe in development.
 *
 * @module services/payment/stripe
 */
import Stripe from 'stripe';
/** Result type for Stripe operations */
export interface StripeResult<T = unknown> {
    success: boolean;
    message?: string;
    data?: T;
}
/** Subscription info returned to clients */
export interface SubscriptionInfo {
    subscriptionId: string;
    status: Stripe.Subscription.Status;
    planId: string;
    cancelAt: string | null;
    cancelAtPeriodEnd: boolean;
}
/** Row shape for the Supabase subscriptions table */
export interface SubscriptionRow {
    user_id: string;
    stripe_customer_id: string;
    stripe_subscription_id: string;
    status: string;
    plan_id: string;
    current_period_start: string | null;
    current_period_end: string | null;
    cancel_at: string | null;
    cancel_at_period_end: boolean;
    updated_at: string;
}
/**
 * Stripe payment service singleton.
 *
 * Wraps all Stripe API calls with error handling and returns
 * standardized result objects.
 */
export declare class StripeService {
    private static instance;
    private stripe;
    private webhookSecret;
    private supabaseAdmin;
    private constructor();
    /**
     * Get or create the singleton instance.
     *
     * @returns The StripeService singleton
     */
    static getInstance(): StripeService;
    /**
     * Check if Stripe is configured with required environment variables.
     *
     * @returns True if STRIPE_SECRET_KEY is set and Stripe client initialized
     */
    isConfigured(): boolean;
    /**
     * Find a Stripe customer by userId stored in metadata.
     *
     * @param client - Stripe client (must be non-null)
     * @param userId - Internal user ID
     * @returns The first matching customer or null
     */
    private findCustomerByUserId;
    /**
     * Create a Stripe Checkout Session for a subscription plan.
     *
     * @param userId - User ID attached as metadata for post-checkout correlation
     * @param planId - Plan identifier (pro, enterprise)
     * @param interval - Billing interval (month, year)
     * @param successUrl - Redirect URL after successful checkout
     * @param cancelUrl - Redirect URL if user cancels
     * @returns Result with checkoutUrl and sessionId
     */
    createCheckoutSession(userId: string, planId: string, interval: string, successUrl: string, cancelUrl: string): Promise<StripeResult<{
        checkoutUrl: string;
        sessionId: string;
    }>>;
    /**
     * Process a Stripe webhook event.
     *
     * Verifies the signature, then dispatches the event to the appropriate handler.
     * Currently handles: checkout.session.completed, customer.subscription.updated,
     * customer.subscription.deleted, invoice.payment_failed.
     *
     * @param rawBody - Raw request body for signature verification
     * @param signature - Stripe-Signature header value
     * @returns Result indicating success or failure
     */
    handleWebhookEvent(rawBody: Buffer, signature: string): Promise<StripeResult<{
        eventType: string;
    }>>;
    /**
     * Get the current subscription for a user by their Stripe customer ID.
     *
     * @param userId - The user to look up (used as client_reference_id or metadata)
     * @returns Result with subscription data or null if no active subscription
     */
    getSubscription(userId: string): Promise<StripeResult<SubscriptionInfo | null>>;
    /**
     * Create a Stripe Customer Portal session for subscription management.
     *
     * @param userId - The user requesting access
     * @param returnUrl - URL to redirect after portal session
     * @returns Result with portalUrl
     */
    createPortalSession(userId: string, returnUrl: string): Promise<StripeResult<{
        portalUrl: string;
    }>>;
    /**
     * Upsert a subscription row in the Supabase subscriptions table.
     * Uses stripe_subscription_id as the conflict key.
     * Logs a warning and continues if Supabase is not configured.
     *
     * @param row - Partial subscription row (stripe_subscription_id required)
     */
    private upsertSubscription;
    /**
     * Handle checkout.session.completed — new subscription created.
     * Links the Stripe customer to the internal userId via metadata,
     * then upserts the subscription into Supabase.
     *
     * @param client - Stripe client instance
     * @param session - The completed checkout session
     */
    private handleCheckoutCompleted;
    /**
     * Handle customer.subscription.updated — plan changes, renewals, cancellations.
     * Syncs the current subscription state to Supabase.
     *
     * @param subscription - The updated subscription
     */
    private handleSubscriptionUpdated;
    /**
     * Handle customer.subscription.deleted — subscription cancelled/expired.
     * Updates the Supabase record with canceled status.
     *
     * @param subscription - The deleted subscription
     */
    private handleSubscriptionDeleted;
    /**
     * Handle invoice.payment_failed — payment attempt failed.
     * Updates the subscription status to past_due in Supabase when possible.
     *
     * @param invoice - The failed invoice
     */
    private handlePaymentFailed;
    /**
     * Reset the singleton instance (for testing).
     */
    static resetInstance(): void;
}
//# sourceMappingURL=stripe.service.d.ts.map