import { RequestOptions, IssueSessionTokenParams, SessionToken, AnonymousCheckoutParams, AuthenticatedCheckoutParams, CreatePlanChangeSessionParams, AuthenticatedPlanChangeParams, CheckoutSessionResult, AuthenticatedCheckoutResult, GraphQLParams, GraphQLResponse, WaffoPancakeConfig } 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; /** * Create a server action that handles checkout session creation. * * The private key is captured in the closure and never sent to the client. * * Handles both new purchases and plan changes; `params.type` selects the flow. * * @param config - WaffoPancake client configuration (merchantId + privateKey) * @returns A server action function * * @example * ```ts * "use server"; * import { createCheckoutAction } from "@waffo/pancake-nextjs/server"; * * export const checkout = createCheckoutAction({ * merchantId: process.env.WAFFO_MERCHANT_ID!, * privateKey: process.env.WAFFO_PRIVATE_KEY!, * }); * ``` * * @example * ```ts * // Plan change link for an existing subscription — originOrderId is required * const session = await checkout({ * type: "planChange", * originOrderId: "ORD_xxx", * productId: "PROD_target_plan", * currency: "USD", * }); * // session.checkoutUrl points at the change confirmation page * ``` */ declare function createCheckoutAction(config: WaffoPancakeConfig): CheckoutAction; /** Server action signature for issuing customer tokens */ type CustomerTokenAction = (params: IssueSessionTokenParams, options?: RequestOptions) => Promise; /** * Create a server action that issues customer session tokens. * * @param config - WaffoPancake client configuration * @returns A server action function * * @example * ```ts * "use server"; * import { createCustomerTokenAction } from "@waffo/pancake-nextjs/server"; * * export const issueCustomerToken = createCustomerTokenAction({ * merchantId: process.env.WAFFO_MERCHANT_ID!, * privateKey: process.env.WAFFO_PRIVATE_KEY!, * }); * ``` */ declare function createCustomerTokenAction(config: WaffoPancakeConfig): CustomerTokenAction; /** 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; /** * Create a server action that executes customer self-service operations. * * `config.environment` is required — session tokens carry no environment, and the * gateway rejects a session request without the matching header. * * `createPlanChangeSession` is the customer-driven half of a plan change: it returns * a confirmation-page URL, and the platform allows it only when the subscription * belongs to that customer, the target plan is in the same product group, and that * group's `selfServicePlanChange` is on — otherwise 403. The merchant-only pricing * fields are not part of its params; the platform drops them on this path silently. * * No call sends an idempotency key unless you pass one (`options.idempotencyKey`, * the last argument) — the same rule as every other method in the SDK — so a write * retried after a timeout executes twice. * * @param config - WaffoPancake client configuration * @returns A server action function * * @example * ```ts * "use server"; * import { createCustomerSessionAction } from "@waffo/pancake-nextjs/server"; * * export const customerAction = createCustomerSessionAction({ * merchantId: process.env.WAFFO_MERCHANT_ID!, * privateKey: process.env.WAFFO_PRIVATE_KEY!, * environment: "test", * }); * ``` */ declare function createCustomerSessionAction(config: WaffoPancakeConfig): CustomerSessionAction; /** Server action signature for merchant GraphQL queries */ type MerchantQueryAction = (params: GraphQLParams) => Promise; /** * Create a server action that executes merchant GraphQL queries. * * @param config - WaffoPancake client configuration * @returns A server action function * * @example * ```ts * "use server"; * import { createMerchantQueryAction } from "@waffo/pancake-nextjs/server"; * * export const merchantQuery = createMerchantQueryAction({ * merchantId: process.env.WAFFO_MERCHANT_ID!, * privateKey: process.env.WAFFO_PRIVATE_KEY!, * }); * ``` */ declare function createMerchantQueryAction(config: WaffoPancakeConfig): MerchantQueryAction; /** @deprecated Use {@link CustomerTokenAction} instead. */ type BuyerTokenAction = CustomerTokenAction; /** @deprecated Use {@link createCustomerTokenAction} instead. */ declare const createBuyerTokenAction: typeof createCustomerTokenAction; /** @deprecated Use {@link CustomerSessionActionType} instead. */ type BuyerSessionActionType = CustomerSessionActionType; /** @deprecated Use {@link CustomerSessionAction} instead. */ type BuyerSessionAction = CustomerSessionAction; /** @deprecated Use {@link createCustomerSessionAction} instead. */ declare const createBuyerSessionAction: typeof createCustomerSessionAction; export { type BuyerSessionAction, type BuyerSessionActionType, type BuyerTokenAction, type CheckoutAction, type CheckoutActionParams, type CheckoutActionResult, type CustomerSessionAction, type CustomerSessionActionType, type CustomerTokenAction, type MerchantQueryAction, createBuyerSessionAction, createBuyerTokenAction, createCheckoutAction, createCustomerSessionAction, createCustomerTokenAction, createMerchantQueryAction };