import * as react_jsx_runtime from 'react/jsx-runtime'; import React from 'react'; import { AnonymousCheckoutParams, AuthenticatedCheckoutParams, CreatePlanChangeSessionParams, AuthenticatedPlanChangeParams, RequestOptions, CheckoutSessionResult, AuthenticatedCheckoutResult, IssueSessionTokenParams, SessionToken, GraphQLParams, GraphQLResponse, CancelSubscriptionParams, CancelSubscriptionResult, CancelOnetimeOrderParams, CancelOnetimeOrderResult, ReactivateSubscriptionParams, ReactivateSubscriptionResult, CreateRefundTicketParams, RefundTicket, ResubmitRefundTicketParams, RefundTicketVersionData, VerifyWebhookOptions, WebhookEventData, WebhookEvent } from '@waffo/pancake-ts'; export { BillingDetail, CashierLanguage, ChangeTiming, PaymentMethod, PriceInfo, PriceSnapshot, RefundTicketVersionData, RequestOptions, RequestedAmount, TaxCategory, WaffoPancakeError, WebhookEvent, WebhookEventData, WebhookEventType } from '@waffo/pancake-ts'; /** * Parameters for the checkout server action. * * The `type` field selects the flow: a new purchase (`anonymous` / `authenticated`) * or a plan change for an existing subscription (`planChange` / * `authenticatedPlanChange`, which carry the required `originOrderId`). */ type CheckoutActionParams = ({ type?: "anonymous"; } & AnonymousCheckoutParams) | ({ type: "authenticated"; } & AuthenticatedCheckoutParams) | ({ type: "planChange"; } & CreatePlanChangeSessionParams) | ({ type: "authenticatedPlanChange"; } & AuthenticatedPlanChangeParams); /** Result of the checkout server action */ type CheckoutActionResult = CheckoutSessionResult | AuthenticatedCheckoutResult; /** * Server action signature for checkout. * * The optional `options` carries an `idempotencyKey`; without one no key is sent * and a retried call creates a second session. */ type CheckoutAction = (params: CheckoutActionParams, options?: RequestOptions) => Promise; /** Server action signature for issuing customer tokens */ type CustomerTokenAction = (params: IssueSessionTokenParams, options?: RequestOptions) => Promise; /** Customer action types */ type CustomerSessionActionType = "cancelSubscription" | "cancelOnetimeOrder" | "reactivateSubscription" | "createRefundTicket" | "resubmitRefundTicket" | "createPlanChangeSession" | "query"; /** Server action signature for customer session operations */ type CustomerSessionAction = (token: string, actionType: CustomerSessionActionType, params: unknown, options?: RequestOptions) => Promise; /** Server action signature for merchant GraphQL queries */ type MerchantQueryAction = (params: GraphQLParams) => Promise; /** @deprecated Use {@link CustomerTokenAction} instead. */ type BuyerTokenAction = CustomerTokenAction; /** @deprecated Use {@link CustomerSessionAction} instead. */ type BuyerSessionAction = CustomerSessionAction; /** Customer configuration for automatic token management */ interface CustomerConfig { /** Customer identity (email or merchant-provided identifier) */ identity: string; /** Store ID (optional when `productId` is provided) */ storeId?: string; /** Product ID — used to derive the store when `storeId` is omitted */ productId?: string; /** Server action for issuing tokens — from `createCustomerTokenAction()` */ issueToken: CustomerTokenAction; /** Server action for customer operations — from `createCustomerSessionAction()` */ sessionAction: CustomerSessionAction; } /** @deprecated Use {@link CustomerConfig} instead. */ type BuyerConfig = CustomerConfig; interface WaffoPancakeProviderProps { /** Customer configuration for automatic token management */ customer?: CustomerConfig; /** @deprecated Use `customer` instead. */ buyer?: CustomerConfig; children: React.ReactNode; } /** * Provider that manages customer token lifecycle via server actions. * * Auto-issues session tokens on mount and refreshes before expiry. * All customer hooks (`useCustomer`, `useCustomerOrders`, etc.) read from context. * * The private key never leaves the server — token issuance and customer * operations are delegated to server actions. * * @param props - Provider configuration * @param props.customer - Customer identity and server actions * @param props.buyer - Deprecated alias of `customer` * @param props.children - React children * * @example * ```tsx * // identity must match what you passed as `buyerIdentity` at checkout time — * // customer-portal lookups are keyed by merchant_provided_buyer_identity * * * * ``` */ declare function WaffoPancakeProvider({ customer, buyer, children }: WaffoPancakeProviderProps): react_jsx_runtime.JSX.Element; /** Redirect mode for checkout navigation */ type CheckoutMode = "redirect" | "popup"; /** Base checkout options shared by all checkout types */ interface CheckoutBaseOptions { /** How to navigate to checkout page. Default: `"redirect"` */ mode?: CheckoutMode; /** * Loading page URL shown in popup while checkout session is being created. * Only used when `mode` is `"popup"`. Defaults to a minimal inline loading page. */ popupLoadingUrl?: string; /** Callback fired on error */ onError?: (error: Error) => void; } /** Link checkout — redirects to product page URL, no API call needed */ interface LinkCheckoutProps extends CheckoutBaseOptions { type: "link"; /** Store slug (from Dashboard) */ storeSlug: string; /** Product ID */ productId: string; /** Currency code (ISO 4217). If omitted, product page auto-detects. */ currency?: string; /** Pre-fill customer email */ email?: string; /** Redirect URL after successful payment */ successUrl?: string; /** Use test environment */ test?: boolean; /** Pre-fill billing country (ISO 3166-1) */ country?: string; /** Is business purchase */ isBusiness?: boolean; /** * Base URL of the storefront. Default: `"https://pancake.waffo.ai"` */ baseUrl?: string; } /** Anonymous checkout — creates session via server action */ type AnonymousCheckoutProps = CheckoutBaseOptions & { type?: "anonymous"; /** Server action created by `createCheckoutAction()` */ action: CheckoutAction; /** Callback fired when checkout session is successfully created */ onSuccess?: (result: CheckoutSessionResult) => void; } & AnonymousCheckoutParams; /** Authenticated checkout — creates session + token via server action */ type AuthenticatedCheckoutProps = CheckoutBaseOptions & { type: "authenticated"; /** Server action created by `createCheckoutAction()` */ action: CheckoutAction; /** Callback fired when checkout session is successfully created */ onSuccess?: (result: AuthenticatedCheckoutResult) => void; } & AuthenticatedCheckoutParams; /** Union of all checkout prop types */ type CheckoutProps = LinkCheckoutProps | AnonymousCheckoutProps | AuthenticatedCheckoutProps; /** Return type of useCheckout hook */ interface UseCheckoutReturn { /** Trigger the checkout flow */ checkout: () => void; /** Whether a checkout session is being created */ isLoading: boolean; /** Error from the last checkout attempt, if any */ error: Error | null; } type CheckoutButtonBaseProps = { /** Button content */ children: React.ReactNode; /** Content shown while checkout session is being created */ loadingChildren?: React.ReactNode; /** Additional class name */ className?: string; /** Additional inline styles */ style?: React.CSSProperties; /** Disabled state (merged with isLoading) */ disabled?: boolean; } & Omit, "onClick" | "disabled" | "children">; /** Props for CheckoutButton — link mode */ type LinkCheckoutButtonProps = CheckoutButtonBaseProps & LinkCheckoutProps; /** Props for CheckoutButton — anonymous mode */ type AnonymousCheckoutButtonProps = CheckoutButtonBaseProps & AnonymousCheckoutProps; /** Props for CheckoutButton — authenticated mode */ type AuthenticatedCheckoutButtonProps = CheckoutButtonBaseProps & AuthenticatedCheckoutProps; type CheckoutButtonProps = LinkCheckoutButtonProps | AnonymousCheckoutButtonProps | AuthenticatedCheckoutButtonProps; /** * A button that triggers a Waffo Pancake checkout flow on click. * * Three checkout types: * - **link**: Instant redirect to product page URL (no server action needed) * - **anonymous**: Calls server action to create session, then redirects * - **authenticated**: Calls server action to create session + token, then redirects * * The private key never leaves the server — anonymous and authenticated modes * use a server action created by `createCheckoutAction()`. * * @param props - Flattened checkout props, button content, and optional styling * * @example * ```tsx * // Link checkout — no server action needed * * Buy Now * * * // Anonymous checkout — via server action * * Buy Now * * * // Authenticated checkout — via server action * * Buy Now * * ``` */ declare function CheckoutButton(props: CheckoutButtonProps): react_jsx_runtime.JSX.Element; /** * React hook for triggering a Waffo Pancake checkout flow. * * Supports three checkout types: * - **link**: Builds a product page URL and navigates directly (no API call, synchronous) * - **anonymous**: Calls a server action to create a checkout session, then navigates * - **authenticated**: Calls a server action to create a session + token, then navigates * * The private key never leaves the server — anonymous and authenticated modes * use a server action created by `createCheckoutAction()`. * * @param args - Flattened checkout props * @returns `{ checkout, isLoading, error }` * * @example * ```tsx * // Link checkout — no server action needed * const { checkout } = useCheckout({ * type: "link", * storeSlug: "my-store", * productId: "PROD_xxx", * currency: "USD", * }); * * // Anonymous checkout — via server action * const { checkout, isLoading } = useCheckout({ * action: checkout, // from createCheckoutAction() * productId: "PROD_xxx", * currency: "USD", * }); * ``` */ declare function useCheckout(args: CheckoutProps): UseCheckoutReturn; /** State of an async customer action */ interface CustomerActionState { /** Execute the action */ execute: (params: T) => Promise; /** Whether the action is in progress */ isLoading: boolean; /** Error from the last attempt */ error: Error | null; } /** Return type of useCustomer hook */ interface UseCustomerReturn { /** Cancel a subscription order */ cancelSubscription: CustomerActionState & { data: CancelSubscriptionResult | null; }; /** Cancel a one-time order */ cancelOnetimeOrder: CustomerActionState & { data: CancelOnetimeOrderResult | null; }; /** Reactivate a canceling subscription */ reactivateSubscription: CustomerActionState & { data: ReactivateSubscriptionResult | null; }; /** Create a refund ticket */ createRefundTicket: CustomerActionState & { data: RefundTicket | null; }; /** Resubmit a rejected refund ticket */ resubmitRefundTicket: CustomerActionState & { data: RefundTicket | null; }; /** Execute a GraphQL query */ query: >(params: GraphQLParams) => Promise>; } /** * React hook for customer self-service actions. * * Must be used within ``. All operations are executed * via server actions — the private key never leaves the server. * * @returns Customer action handlers with loading/error states * * @example * ```tsx * function AccountPage() { * const customer = useCustomer(); * return ( * * ); * } * ``` */ declare function useCustomer(): UseCustomerReturn; /** @deprecated Use {@link CustomerActionState} instead. */ type BuyerActionState = CustomerActionState; /** @deprecated Use {@link UseCustomerReturn} instead. */ type UseBuyerReturn = UseCustomerReturn; /** @deprecated Use {@link useCustomer} instead. */ declare const useBuyer: typeof useCustomer; /** Query state with typed data */ interface QueryState { data: T | null; isLoading: boolean; error: Error | null; refetch: () => void; } /** A customer's one-time order */ interface CustomerOnetimeOrder { id: string; status: string; currency: string; buyerEmail: string; product: { id: string; name: string; } | null; payments: Array<{ id: string; status: string; snapshotDisplayAmount: string; snapshotDisplayCurrency: string; createdAt: string; }>; createdAt: string; } /** A customer's subscription order */ interface CustomerSubscriptionOrder { id: string; status: string; currency: string; buyerEmail: string; currentPeriodStart: string | null; currentPeriodEnd: string | null; cancelAt: string | null; product: { id: string; name: string; billingPeriod: string; } | null; payments: Array<{ id: string; status: string; snapshotDisplayAmount: string; snapshotDisplayCurrency: string; createdAt: string; }>; createdAt: string; } /** A customer's payment record */ interface CustomerPayment { id: string; orderId: string; status: string; snapshotDisplayAmount: string; snapshotDisplayCurrency: string; failureReason: string | null; createdAt: string; } /** * A customer's refund ticket. * * Ticket-level fields are flat; per-version fields (`reason`, `requestedAmount`) * live under `versionData` because the customer can resubmit a rejected ticket and * each submission is a versioned record. `versionData` reflects the current * (latest) version. The `versionData` shape is shared with `@waffo/pancake-ts`'s * `RefundTicketVersionData`. */ interface CustomerRefundTicket { id: string; status: string; versionNumber: number | null; versionData: RefundTicketVersionData | null; createdAt: string; } interface CustomerOrdersData { onetimeOrders: CustomerOnetimeOrder[]; subscriptionOrders: CustomerSubscriptionOrder[]; } /** * Fetch the customer's order history (one-time + subscription). * * Must be used within ``. Token is auto-managed. * * @returns Orders with product info and payment history * * @example * ```tsx * const { data, isLoading, refetch } = useCustomerOrders(); * // data.onetimeOrders + data.subscriptionOrders * ``` */ declare function useCustomerOrders(): QueryState; /** * Fetch the customer's payment history. * * Must be used within ``. Token is auto-managed. * * @returns Payment records with amounts and status * * @example * ```tsx * const { data: payments, isLoading } = useCustomerPayments(); * ``` */ declare function useCustomerPayments(): QueryState; /** * Fetch the customer's refund tickets. * * Must be used within ``. Token is auto-managed. * * @returns Refund tickets with status and requested amounts * * @example * ```tsx * const { data: tickets, isLoading } = useCustomerRefundTickets(); * ``` */ declare function useCustomerRefundTickets(): QueryState; /** @deprecated Use {@link CustomerOnetimeOrder} instead. */ type BuyerOnetimeOrder = CustomerOnetimeOrder; /** @deprecated Use {@link CustomerSubscriptionOrder} instead. */ type BuyerSubscriptionOrder = CustomerSubscriptionOrder; /** @deprecated Use {@link CustomerPayment} instead. */ type BuyerPayment = CustomerPayment; /** @deprecated Use {@link CustomerRefundTicket} instead. */ type BuyerRefundTicket = CustomerRefundTicket; /** @deprecated Use {@link useCustomerOrders} instead. */ declare const useBuyerOrders: typeof useCustomerOrders; /** @deprecated Use {@link useCustomerPayments} instead. */ declare const useBuyerPayments: typeof useCustomerPayments; /** @deprecated Use {@link useCustomerRefundTickets} instead. */ declare const useBuyerRefundTickets: typeof useCustomerRefundTickets; /** A merchant's recent order (one-time or subscription) */ interface MerchantOrder { id: string; status: string; currency: string; buyerEmail: string; testMode: boolean; product: { id: string; name: string; } | null; payments: Array<{ id: string; status: string; snapshotDisplayAmount: string; snapshotDisplayCurrency: string; }>; createdAt: string; } /** * Sales overview statistics. * * Monetary fields (`totalRevenue`, `revenueByPeriod[].amount`) are returned as * display-formatted strings (e.g., `"9.99"`), not minor-currency-unit integers. * The conversion happens server-side via the GraphQL `currencyDisplayLoader`. */ interface SalesOverview { totalOrders: number; /** Total succeeded payment revenue as display string (e.g., `"1234.56"`) */ totalRevenue: string; totalCustomers: number; currency: string; ordersByStatus: Array<{ status: string; count: number; }>; /** Revenue by period; `amount` is a display string (e.g., `"9.99"`) */ revenueByPeriod: Array<{ period: string; amount: string; }>; } /** Subscription overview */ interface SubscriptionOverview { activeCount: number; cancelingCount: number; pastDueCount: number; totalCount: number; subscriptions: MerchantSubscription[]; } /** A merchant's subscription with status details */ interface MerchantSubscription { id: string; status: string; currency: string; buyerEmail: string; currentPeriodStart: string | null; currentPeriodEnd: string | null; cancelAt: string | null; product: { id: string; name: string; billingPeriod: string; } | null; createdAt: string; } interface MerchantOrdersOptions { /** Store ID to filter by */ storeId: string; /** Max results (default: 20) */ limit?: number; } /** * Fetch recent orders for a store (one-time + subscription). * * @param query - Server action from `createMerchantQueryAction()` * @param options - Store ID and optional limit * @returns Recent orders with product info and payment summary * * @example * ```tsx * const { data, isLoading, refetch } = useMerchantOrders(merchantQuery, { storeId: "STO_xxx" }); * ``` */ declare function useMerchantOrders(query: MerchantQueryAction, options: MerchantOrdersOptions): QueryState<{ onetimeOrders: MerchantOrder[]; subscriptionOrders: MerchantOrder[]; }>; /** * Fetch sales overview for a store. * * @param query - Server action from `createMerchantQueryAction()` * @param storeId - Store ID * @returns Aggregated sales statistics * * @example * ```tsx * const { data: sales } = useMerchantSales(merchantQuery, "STO_xxx"); * ``` */ declare function useMerchantSales(query: MerchantQueryAction, storeId: string): QueryState; /** * Fetch subscription overview for a store. * * @param query - Server action from `createMerchantQueryAction()` * @param storeId - Store ID * @returns Subscription counts and detailed list * * @example * ```tsx * const { data: subs } = useMerchantSubscriptions(merchantQuery, "STO_xxx"); * ``` */ declare function useMerchantSubscriptions(query: MerchantQueryAction, storeId: string): QueryState; /** Handler function for a specific webhook event */ type EventHandler = (event: WebhookEvent) => void | Promise; /** Configuration for the Webhook route handler factory */ interface WebhookConfig { /** Webhook signature verification options (environment, publicKey, tolerance, etc.) */ verifyOptions?: VerifyWebhookOptions; /** Catch-all handler — called for every event regardless of type */ onPayload?: EventHandler; /** One-time order first payment succeeded */ onOrderCompleted?: EventHandler; /** Subscription first payment succeeded (newly activated) */ onSubscriptionActivated?: EventHandler; /** Subscription payment succeeded — a pure payment event, carries no subscription period or status */ onSubscriptionPaymentSucceeded?: EventHandler; /** Current billing period rolled forward (renewal) */ onSubscriptionRenewed?: EventHandler; /** Subscription recovered from past due (a retried charge succeeded) */ onSubscriptionRecovered?: EventHandler; /** Plan change took effect (upgrade/downgrade) */ onSubscriptionPlanChanged?: EventHandler; /** Plan change confirmed, takes effect next billing period */ onSubscriptionPlanChangeScheduled?: EventHandler; /** Plan change did not complete, the current plan stays in effect */ onSubscriptionPlanChangeFailed?: EventHandler; /** Customer initiated cancellation (expires at end of current period) */ onSubscriptionCanceling?: EventHandler; /** Customer withdrew cancellation (subscription restored) */ onSubscriptionUncanceled?: EventHandler; /** Subscription fully terminated */ onSubscriptionCanceled?: EventHandler; /** Renewal payment failed (past due) */ onSubscriptionPastDue?: EventHandler; /** Refund succeeded */ onRefundSucceeded?: EventHandler; /** Refund failed */ onRefundFailed?: EventHandler; } /** * Create a Next.js POST route handler for Waffo Pancake webhooks. * * Automatically verifies the webhook signature using `@waffo/pancake-ts`, * then dispatches to the matching event handler. * * @param config - Verification options and event handlers * @returns A Next.js POST route handler * * @example * ```ts * // app/api/webhooks/waffo/route.ts * import { Webhook } from "@waffo/pancake-nextjs"; * * export const POST = Webhook({ * verifyOptions: { environment: "prod" }, * onOrderCompleted: async (event) => { * console.log("Order completed:", event.data.orderId); * // Grant access to the product * }, * onSubscriptionActivated: async (event) => { * console.log("Subscription activated:", event.data.orderId); * }, * onRefundSucceeded: async (event) => { * console.log("Refund succeeded:", event.data.refundId); * // Revoke access * }, * }); * ``` */ declare function Webhook(config: WebhookConfig): (request: Request) => Promise; export { type AnonymousCheckoutButtonProps, type AnonymousCheckoutProps, type AuthenticatedCheckoutButtonProps, type AuthenticatedCheckoutProps, type BuyerActionState, type BuyerConfig, type BuyerOnetimeOrder, type BuyerPayment, type BuyerRefundTicket, type BuyerSessionAction, type BuyerSubscriptionOrder, type BuyerTokenAction, type CheckoutAction, type CheckoutActionParams, type CheckoutActionResult, type CheckoutBaseOptions, CheckoutButton, type CheckoutButtonProps, type CheckoutMode, type CheckoutProps, type CustomerActionState, type CustomerConfig, type CustomerOnetimeOrder, type CustomerPayment, type CustomerRefundTicket, type CustomerSessionAction, type CustomerSubscriptionOrder, type CustomerTokenAction, type LinkCheckoutButtonProps, type LinkCheckoutProps, type MerchantOrder, type MerchantOrdersOptions, type MerchantQueryAction, type MerchantSubscription, type QueryState, type SalesOverview, type SubscriptionOverview, type UseBuyerReturn, type UseCheckoutReturn, type UseCustomerReturn, WaffoPancakeProvider, type WaffoPancakeProviderProps, Webhook, type WebhookConfig, useBuyer, useBuyerOrders, useBuyerPayments, useBuyerRefundTickets, useCheckout, useCustomer, useCustomerOrders, useCustomerPayments, useCustomerRefundTickets, useMerchantOrders, useMerchantSales, useMerchantSubscriptions };