UNPKG

@vue-stripe/vue-stripe

Version:

Vue Stripe elements and composables for Stripe.js

72 lines 2.24 kB
import { Ref } from 'vue-demi'; /** * Options for URL-based checkout redirect (v8.x compatible) */ export interface CheckoutRedirectOptions { /** The checkout session URL from your server */ url: string; } /** * Options for legacy redirectToCheckout (v7.x only) * @deprecated Use CheckoutRedirectOptions with URL redirect instead */ export interface LegacyCheckoutOptions { /** Checkout Session ID */ sessionId?: string; /** Line items for client-side session creation */ lineItems?: Array<{ price: string; quantity: number; }>; /** Checkout mode */ mode?: 'payment' | 'subscription' | 'setup'; /** Success redirect URL */ successUrl?: string; /** Cancel redirect URL */ cancelUrl?: string; } export interface UseStripeCheckoutReturn { /** * Redirect to Stripe Checkout using session URL (v8.x compatible, recommended) */ redirectToCheckout: (options: CheckoutRedirectOptions | LegacyCheckoutOptions) => Promise<void>; /** * Redirect to checkout using session URL (v8.x compatible) */ redirectToUrl: (url: string) => void; loading: Readonly<Ref<boolean>>; error: Readonly<Ref<string | null>>; } /** * Composable for handling Stripe Checkout redirects. * * Supports both @stripe/stripe-js v7.x (redirectToCheckout) and v8.x (URL redirect). * * @example * ```vue * <script setup> * import { useStripeCheckout } from '@vue-stripe/vue-stripe' * * const { redirectToCheckout, redirectToUrl, loading, error } = useStripeCheckout() * * // v8.x compatible (recommended) * const handleCheckout = async () => { * const response = await fetch('/api/create-checkout-session', { * method: 'POST', * body: JSON.stringify({ priceId: 'price_xxx' }) * }) * const { url } = await response.json() * redirectToUrl(url) * } * * // Or using redirectToCheckout with URL * const handleCheckoutAlt = async () => { * const response = await fetch('/api/create-checkout-session') * const { url } = await response.json() * await redirectToCheckout({ url }) * } * </script> * ``` */ export declare function useStripeCheckout(): UseStripeCheckoutReturn; //# sourceMappingURL=useStripeCheckout.d.ts.map