/** * Checkouts V2 API Types * * Type definitions matching the backend Checkout V2 APIs. * Backend schema: /backend/app/checkouts/schema.py * * **Available Endpoints:** * - POST /customer_portal/checkouts - Create checkout * - POST /customer_portal/checkouts/{id}/confirm - Confirm checkout * * **Note:** Only the above 2 endpoints are currently implemented in the backend. * Other types are commented out until their corresponding APIs are available. */ /** * Status of checkout session (backend enum values) */ export declare enum CheckoutStatus { /** Session created, awaiting payment initiation */ PENDING = "pending", /** Payment process started */ PAYMENT_INITIATED = "payment_initiated", /** Payment completed successfully */ PAYMENT_SUCCEEDED = "payment_succeeded", /** Payment failed */ PAYMENT_FAILED = "payment_failed", /** Checkout confirmed */ CONFIRMED = "confirmed", /** Contract created from checkout */ CONTRACT_CREATED = "contract_created", /** Session cancelled */ CANCELLED = "cancelled", /** Session expired */ EXPIRED = "expired" } /** * Product quantity override for new checkout (new subscriptions). * Uses pricing_id to identify which pricing to override. * * Note: No line_item_id - contract doesn't exist yet. * For quantity updates on existing contracts, use `QuantityUpdateItem` instead. * * @example * ```typescript * const override: CreateCheckoutQuantityOverride = { * pricing_id: 'pricing-uuid', * quantity_value: 10, * } * ``` */ export type CreateCheckoutQuantityOverride = { /** Pricing ID (required) - identifies which pricing to override quantity for */ pricing_id: string; /** Quantity value (required, must be non-negative) */ quantity_value: number; /** Date from which this quantity is effective */ effective_from?: string; /** Optional description for this quantity override */ description?: string; }; /** * Product quantity override for checkout (backend schema reference) * * @deprecated Use `CreateCheckoutQuantityOverride` for new checkouts * or `QuantityUpdateItem` for quantity updates on existing contracts. * * Backend schema: ProductQuantityOverride */ export type ProductQuantityOverride = { /** ID of the pricing to override quantity for. Optional for single-product plans. */ pricing_id?: string; /** Contract line item ID for updates (used in amendments) */ line_item_id?: string; /** Quantity value (must be non-negative) */ quantity_value: number; /** Date from which this quantity is effective */ effective_from?: string; /** Optional description for this quantity override */ description?: string; }; /** * Product quantity in response * * Backend schema: ProductQuantityResponseSchema */ export type ProductQuantityResponse = { /** Pricing ID */ pricing_id?: string; /** Contract line item ID */ line_item_id?: string; /** Quantity value */ quantity_value: number; /** Effective from date */ effective_from?: string; /** Description */ description?: string; }; /** * Request schema for creating a quantity update checkout. * Used when updating quantities on an existing contract. * * @example * ```typescript * const request: QuantityUpdateCheckoutRequest = { * contract_id: 'contract-uuid', * product_quantities: [{ * line_item_id: 'line-item-uuid', * quantity_value: 15, * }], * } * ``` */ export type QuantityUpdateCheckoutRequest = { /** Contract ID to update (required) */ contract_id: string; /** Product quantities with line_item_id (required) */ product_quantities: QuantityUpdateItem[]; /** URL to redirect after successful checkout */ success_url?: string; /** URL to redirect if checkout is cancelled */ cancel_url?: string; }; /** * Product quantity item for contract updates. * Requires line_item_id to identify the contract line being updated. * * Note: No pricing_id needed - line_item_id already references the contract line * which has the pricing. pricing_id is only for createCheckout (new subscriptions). */ export type QuantityUpdateItem = { /** Contract line item ID (required) - identifies which line to update */ line_item_id: string; /** New quantity value (required) */ quantity_value: number; /** When the quantity change takes effect */ effective_from?: string; /** Description for this quantity change */ description?: string; }; /** * Simplified estimates response * * Backend schema: CheckoutEstimatesResponseSchema * * @note Will be fully typed soon once backend schema is finalized. */ export type CheckoutEstimates = { /** The current/first invoice estimate */ current_invoice?: Record; /** The next upcoming invoice estimate */ next_invoice?: Record; }; /** * Request parameters for previewing a checkout (dry run). * Returns billing estimates without creating a checkout session or any records. * * Use this to show customers estimated charges before they commit to a checkout. * * @example * ```typescript * // Preview a new subscription * const { data } = await checkout.previewCheckout({ * plan_id: 'plan-uuid', * product_quantities: [{ pricing_id: 'pricing-uuid', quantity_value: 10 }], * }) * ``` */ export type PreviewCheckoutRequest = { /** Plan ID for new subscription preview (required) */ plan_id: string; /** Start date for the contract */ start_date?: string; /** End date for the contract */ end_date?: string; /** Customer ID (optional, uses context if not provided) */ customer_id?: string; /** Business entity ID */ business_entity_id?: string; /** Product quantity overrides */ product_quantities?: CreateCheckoutQuantityOverride[]; }; /** * Request parameters for getting pricing schedules. * Used to retrieve product/pricing schedules for a customer's contract. * * @example * ```typescript * // Get all schedules for active contract * const { data } = await checkout.getPricingSchedule() * * // Get schedules active on a specific date * const { data } = await checkout.getPricingSchedule({ * effective_date: '2025-06-01', * }) * * // Get schedules for a specific contract * const { data } = await checkout.getPricingSchedule({ * contract_id: 'contract-uuid', * }) * ``` */ export type GetPricingScheduleRequest = { /** Filter schedules active on this date (ISO date string) */ effective_date?: string; /** Specific contract ID (defaults to customer's active contract) */ contract_id?: string; }; /** * Request parameters for creating a new checkout session. * Used with the `createCheckout()` hook method for new subscriptions. * * @example * ```typescript * const { data: session } = await checkout.createCheckout({ * plan_id: 'plan-uuid', * customer_id: 'customer-uuid', * start_date: '2025-01-01', * product_quantities: [{ * pricing_id: 'pricing-uuid', * quantity_value: 10, * }], * }) * ``` */ export type CreateCheckoutRequest = { /** Plan ID for the subscription (required) */ plan_id: string; /** Start date for the contract */ start_date?: string; /** End date for the contract (optional for evergreen) */ end_date?: string; /** Customer ID */ customer_id?: string; /** Business entity ID */ business_entity_id?: string; /** Session expiration time */ expires_at?: string; /** Redirect URL after successful checkout */ success_url?: string; /** Redirect URL if checkout is cancelled */ cancel_url?: string; /** Product quantity overrides (uses pricing_id) */ product_quantities?: CreateCheckoutQuantityOverride[]; }; /** * Internal API payload for POST /customer_portal/checkout * * This type is exported from this module for internal use by hooks, * but is NOT exported from the public SDK API (src/index.ts). * SDK consumers should use `CreateCheckoutRequest` or * `QuantityUpdateCheckoutRequest` instead. * * Backend schema: CreateCheckoutRequestSchema */ export type CheckoutApiPayload = { /** Plan ID for new contracts */ plan_id?: string; /** Existing contract ID for amendments */ contract_id?: string; /** Start date for the contract */ start_date?: string; /** End date for the contract */ end_date?: string; /** ID of an existing customer */ customer_id?: string; /** ID of the business entity */ business_entity_id?: string; /** When the checkout session expires */ expires_at?: string; /** URL to redirect after successful checkout */ success_url?: string; /** URL to redirect if checkout is cancelled */ cancel_url?: string; /** List of quantity overrides */ product_quantities?: (CreateCheckoutQuantityOverride | QuantityUpdateItem)[]; }; /** * Request schema for POST /customer_portal/checkout/{id}/confirm * * Backend schema: ConfirmCheckoutRequestSchema * * Confirms a pending checkout and creates the actual contract. */ export type CheckoutConfirmRequest = { /** Optional payment method ID to attach to the customer/contract */ payment_method_id?: string; }; /** * Response schema for POST /customer_portal/checkout * * Backend schema: CheckoutResponse */ export type CheckoutResponse = { /** Unique checkout session ID */ id: string; /** Organization ID */ organisation_id: string; /** ID of the plan being purchased */ plan_id?: string; /** Source contract ID (for amendments) */ source_contract_id?: string; /** Contract start date */ start_date?: string; /** Contract end date */ end_date?: string; /** Current status of the checkout session */ checkout_status: CheckoutStatus; /** ID of the customer (for non-guest checkouts) */ customer_id?: string; /** ID of the business entity */ business_entity_id?: string; /** Whether this is a guest checkout */ guest_checkout: boolean; /** Customer data for guest checkouts */ customer_data?: Record; /** Invoice estimates (current and next invoice only) */ estimates?: CheckoutEstimates; /** When the checkout session expires */ expires_at?: string; /** URL to redirect after successful checkout */ success_url?: string; /** URL to redirect if checkout is cancelled */ cancel_url?: string; /** Product quantity overrides */ product_quantities?: ProductQuantityResponse[]; /** When the checkout was created */ created_at?: string; /** When the checkout was last updated */ updated_at?: string; }; /** * Response schema for POST /customer_portal/checkout/{id}/confirm * * Backend schema: ConfirmCheckoutResponse */ export type ConfirmCheckoutResponse = { /** Checkout session ID */ id: string; /** Current checkout status */ checkout_status: CheckoutStatus; /** ID of the created contract */ contract_id?: string; /** Success message */ message: string; /** When checkout was created */ created_at: string; /** When checkout was last updated */ updated_at: string; }; /** * Response schema for POST /customer_portal/checkouts/preview * * Returns billing estimates without creating any records. * Backend schema: CheckoutPreviewResponse */ export type CheckoutPreviewResponse = { /** Billing estimates for current and next invoice */ estimates: CheckoutEstimates; }; /** * Product information in a pricing schedule item. */ export type ScheduleProductInfo = { /** Product ID */ id: string; /** Product name */ name: string; /** Product type */ type: string; }; /** * Pricing information in a pricing schedule item. */ export type SchedulePricingInfo = { /** Pricing ID */ id: string; /** Pricing name */ name: string; /** Pricing configuration data */ pricing_data: Record; }; /** * Individual schedule item in the pricing schedule response. * Represents a product with its pricing configuration for a time period. */ export type ScheduleItem = { /** Contract line item ID (ContractPhasePricingAssociation) */ line_item_id: string; /** Product details */ product: ScheduleProductInfo; /** Pricing configuration */ pricing: SchedulePricingInfo; /** Plan ID if pricing originated from a plan template */ plan_id: string | null; /** Schedule start date (ISO datetime string) */ start_date: string; /** Schedule end date (ISO datetime string, null for evergreen) */ end_date: string | null; }; /** * Response schema for GET /customer_portal/pricing/schedule * * Returns pricing schedules for a customer's contract including * product and pricing details for each line item. * * Backend schema: ContractSchedulesResponse */ export type ContractSchedulesResponse = { /** Contract ID */ contract_id: string; /** Contract name */ contract_name: string; /** Current phase ID */ phase_id: string; /** Current phase name */ phase_name: string; /** Plan type indicator */ plan_type: 'NOT_PLAN_BASED' | 'plan_based' | 'plan_customized'; /** Contract/phase start date (ISO datetime string) */ start_date: string; /** Contract/phase end date (ISO datetime string, null for evergreen) */ end_date: string | null; /** List of pricing schedule items */ schedules: ScheduleItem[]; };