import Stripe from 'stripe'; import { Request as Request$1, Response as Response$1 } from 'express'; import { D as DonationTier, a as DonationCheckoutOptions, b as DonationCheckoutResult } from './donation-BosbuKM6.mjs'; declare class StripeServerAPI { private stripe; constructor(secretKey: string, options?: { apiVersion?: string; typescript?: boolean; }); createCustomer(params: { email: string; name?: string; phone?: string; metadata?: Record; }): Promise>; getCustomer(customerId: string): Promise>; updateCustomer(customerId: string, params: { email?: string; name?: string; phone?: string; metadata?: Record; }): Promise>; deleteCustomer(customerId: string): Promise>; createSubscription(params: { customerId: string; priceId: string; quantity?: number; trialPeriodDays?: number; metadata?: Record; paymentBehavior?: 'default_incomplete' | 'error_if_incomplete' | 'allow_incomplete'; }): Promise>; getSubscription(subscriptionId: string): Promise>; updateSubscription(subscriptionId: string, params: { priceId?: string; quantity?: number; metadata?: Record; cancelAtPeriodEnd?: boolean; }): Promise>; cancelSubscription(subscriptionId: string, immediately?: boolean): Promise>; reactivateSubscription(subscriptionId: string): Promise>; getCustomerSubscriptions(customerId: string): Promise>>; createCheckoutSession(params: { priceId: string; customerId?: string; customerEmail?: string; successUrl: string; cancelUrl: string; mode?: 'payment' | 'subscription' | 'setup'; allowPromotionCodes?: boolean; billingAddressCollection?: 'auto' | 'required'; metadata?: Record; trialPeriodDays?: number; }): Promise>; getPaymentIntent(paymentIntentId: string): Promise>; createPaymentIntent(params: { amount: number; currency: string; customerId?: string; paymentMethodTypes?: string[]; metadata?: Record; description?: string; }): Promise>; confirmPaymentIntent(paymentIntentId: string, params?: { paymentMethod?: string; }): Promise>; createSetupIntent(params: { customerId: string; paymentMethodTypes?: string[]; metadata?: Record; }): Promise>; createPortalSession(params: { customerId: string; returnUrl: string; }): Promise>; getCustomerPaymentMethods(customerId: string, type?: Stripe.PaymentMethodListParams.Type): Promise>>; attachPaymentMethod(paymentMethodId: string, customerId: string): Promise>; detachPaymentMethod(paymentMethodId: string): Promise>; setDefaultPaymentMethod(customerId: string, paymentMethodId: string): Promise>; getCustomerInvoices(customerId: string, limit?: number): Promise>>; getInvoice(invoiceId: string): Promise>; constructWebhookEvent(payload: string | Buffer, signature: string, webhookSecret: string): Stripe.Event; getPrice(priceId: string): Promise>; getPrices(params?: { active?: boolean; limit?: number; product?: string; }): Promise>>; getProduct(productId: string): Promise>; createEphemeralKey(customerId: string, apiVersion: string): Promise>; } interface NextApiRequest { method?: string; headers: Record; body: any; } interface NextApiResponse { setHeader(name: string, value: string): void; status(code: number): NextApiResponse; json(body: unknown): void; } interface WebhookHandlers { onCustomerSubscriptionCreated?: (subscription: Stripe.Subscription) => Promise; onCustomerSubscriptionUpdated?: (subscription: Stripe.Subscription) => Promise; onCustomerSubscriptionDeleted?: (subscription: Stripe.Subscription) => Promise; onInvoicePaymentSucceeded?: (invoice: Stripe.Invoice) => Promise; onInvoicePaymentFailed?: (invoice: Stripe.Invoice) => Promise; onCheckoutSessionCompleted?: (session: Stripe.Checkout.Session) => Promise; onPaymentIntentSucceeded?: (paymentIntent: Stripe.PaymentIntent) => Promise; onPaymentIntentPaymentFailed?: (paymentIntent: Stripe.PaymentIntent) => Promise; } declare class StripeWebhookHandler { private stripeAPI; private handlers; constructor(secretKey: string, handlers?: WebhookHandlers); handleWebhook(payload: string | Buffer, signature: string, webhookSecret: string): Promise<{ success: boolean; error?: string; }>; private processEvent; private handleSubscriptionCreated; private handleSubscriptionUpdated; private handleSubscriptionDeleted; private handleInvoicePaymentSucceeded; private handleInvoicePaymentFailed; private handleCheckoutSessionCompleted; private handlePaymentIntentSucceeded; private handlePaymentIntentFailed; } declare const createStripeWebhookHandler: (secretKey: string, handlers?: WebhookHandlers) => StripeWebhookHandler; declare const createStripeWebhookMiddleware: (secretKey: string, webhookSecret: string, handlers?: WebhookHandlers) => (req: Request$1, res: Response$1) => Promise> | undefined>; /** * Next.js App Router webhook handler (Next.js 13+ with `app/` directory). * * Returns a `POST` function suitable for use in `app/api/.../route.ts` files. * Uses the Web-standard `Request`/`Response` API instead of Pages Router types. * * @example * ```ts * // app/api/stripe-webhook/route.ts * import { createAppRouterWebhookHandler } from '@digilogiclabs/saas-factory-payments/server'; * * export const POST = createAppRouterWebhookHandler( * process.env.STRIPE_SECRET_KEY!, * process.env.STRIPE_WEBHOOK_SECRET!, * { * onCheckoutSessionCompleted: async (session) => { * if (session.metadata?.product_type === 'donation') { * // Handle donation... * } * }, * }, * ); * ``` */ declare const createAppRouterWebhookHandler: (secretKey: string, webhookSecret: string, handlers?: WebhookHandlers) => (request: Request) => Promise; /** @deprecated Use `createAppRouterWebhookHandler` for Next.js 13+ App Router. */ declare const createNextJSWebhookHandler: (secretKey: string, webhookSecret: string, handlers?: WebhookHandlers) => (req: NextApiRequest, res: NextApiResponse) => Promise; interface CreateCheckoutSessionOptions { priceId: string; customerId?: string; successUrl: string; cancelUrl: string; mode?: 'payment' | 'subscription' | 'setup'; metadata?: Record; } interface ProcessPaymentOptions { amount: number; currency: string; paymentMethodId: string; customerId?: string; description?: string; metadata?: Record; } interface CreateSubscriptionOptions { customerId: string; priceId: string; paymentMethodId?: string; trialPeriodDays?: number; metadata?: Record; } interface UpdateSubscriptionOptions { subscriptionId: string; priceId?: string; quantity?: number; metadata?: Record; } /** * Create a Stripe checkout session */ declare const createStripeCheckoutSession: (stripe: Stripe, options: CreateCheckoutSessionOptions) => Promise; /** * Process a one-time payment */ declare const processPayment: (stripe: Stripe, options: ProcessPaymentOptions) => Promise; /** * Create a subscription */ declare const createSubscription: (stripe: Stripe, options: CreateSubscriptionOptions) => Promise; /** * Update a subscription */ declare const updateSubscription: (stripe: Stripe, options: UpdateSubscriptionOptions) => Promise; /** * Cancel a subscription */ declare const cancelSubscription: (stripe: Stripe, subscriptionId: string, cancelAtPeriodEnd?: boolean) => Promise; /** * Create a donation checkout session using inline price_data. * * Unlike `createStripeCheckoutSession` which requires a pre-created Price ID, * this uses Stripe's inline `price_data` so apps don't need any Stripe * Dashboard setup. Stripe auto-creates the products on first use. * * Supports: * - Named tiers with fixed amounts (one-time or monthly) * - Custom amounts with configurable recurrence * - Metadata tagging for webhook identification * * @example * ```ts * const tiers: DonationTier[] = [ * { id: 'fan', name: 'Fan', description: 'Monthly $3 support', amountCents: 300, recurring: true }, * { id: 'gold', name: 'Gold', description: 'One-time $25 donation', amountCents: 2500 }, * ]; * * const result = await createDonationCheckout(stripe, tiers, { * tier: 'fan', * successUrl: 'https://example.com/thank-you?session_id={CHECKOUT_SESSION_ID}', * cancelUrl: 'https://example.com/support', * }); * // result.url → redirect user here * ``` */ declare const createDonationCheckout: (stripe: Stripe, tiers: DonationTier[], options: DonationCheckoutOptions) => Promise; /** * Validate Stripe webhook signature */ declare const validateStripeSignature: (payload: string | Buffer, signature: string, endpointSecret: string) => Stripe.Event; /** * Handle common Stripe webhook events */ declare const handleStripeWebhook: (event: Stripe.Event, handlers: { onPaymentSucceeded?: (paymentIntent: Stripe.PaymentIntent) => Promise; onPaymentFailed?: (paymentIntent: Stripe.PaymentIntent) => Promise; onSubscriptionCreated?: (subscription: Stripe.Subscription) => Promise; onSubscriptionUpdated?: (subscription: Stripe.Subscription) => Promise; onSubscriptionDeleted?: (subscription: Stripe.Subscription) => Promise; onInvoicePaid?: (invoice: Stripe.Invoice) => Promise; onInvoicePaymentFailed?: (invoice: Stripe.Invoice) => Promise; }) => Promise; export { type CreateCheckoutSessionOptions, type CreateSubscriptionOptions, DonationCheckoutOptions, DonationCheckoutResult, DonationTier, type ProcessPaymentOptions, StripeServerAPI, StripeWebhookHandler, type UpdateSubscriptionOptions, type WebhookHandlers, cancelSubscription, createAppRouterWebhookHandler, createDonationCheckout, createNextJSWebhookHandler, createStripeCheckoutSession, createStripeWebhookHandler, createStripeWebhookMiddleware, createSubscription, handleStripeWebhook, processPayment, updateSubscription, validateStripeSignature };