import { type Signal } from '@wix/services-definitions/core-services/signals'; /** * Service definition for the Buy Now service. * This defines the reactive API contract for managing buy now functionality. * * @constant */ export declare const BuyNowServiceDefinition: string & { __api: { /** Function to redirect to checkout with the current product */ redirectToCheckout: () => Promise; /** Reactive signal indicating if a checkout redirect is in progress */ loadingSignal: Signal; /** Reactive signal containing any error message, or null if no error */ errorSignal: Signal; /** Reactive signal indicating if the product is in stock */ inStockSignal: Signal; /** Reactive signal indicating if pre-order is available */ preOrderAvailableSignal: Signal; /** The name of the product */ productName: string; /** The price of the product as a string */ price: string; /** The currency code for the product price */ currency: string; }; __config: {}; isServiceDefinition?: boolean; } & { /** Function to redirect to checkout with the current product */ redirectToCheckout: () => Promise; /** Reactive signal indicating if a checkout redirect is in progress */ loadingSignal: Signal; /** Reactive signal containing any error message, or null if no error */ errorSignal: Signal; /** Reactive signal indicating if the product is in stock */ inStockSignal: Signal; /** Reactive signal indicating if pre-order is available */ preOrderAvailableSignal: Signal; /** The name of the product */ productName: string; /** The price of the product as a string */ price: string; /** The currency code for the product price */ currency: string; }; /** * Configuration interface for the Buy Now service. * Contains all the product information needed to initialize the buy now functionality. * * @interface BuyNowServiceConfig */ export interface BuyNowServiceConfig { /** The unique product ID */ productId: string; /** The optional variant ID if a specific variant is selected */ variantId?: string; /** The display name of the product */ productName: string; /** The price of the product as a string */ price: string; /** The currency code for the product price */ currency: string; /** Whether the product is currently in stock */ inStock: boolean; /** Whether pre-order is available for this product */ preOrderAvailable: boolean; } /** * Implementation of the Buy Now service that manages buy now functionality. * This service provides signals for loading state, stock status, and error handling, * along with a method to redirect directly to checkout. * * @example * ```tsx * import { BuyNowServiceImplementation, BuyNowServiceDefinition } from '@wix/stores/services'; * import { useService } from '@wix/services-manager-react'; * * function BuyNowComponent({ buyNowConfig }) { * return ( * * * * ); * } * * function BuyNowButton() { * const buyNowService = useService(BuyNowServiceDefinition); * const isLoading = buyNowService.loadingSignal.get(); * const error = buyNowService.errorSignal.get(); * const inStock = buyNowService.inStockSignal.get(); * * const handleBuyNow = async () => { * await buyNowService.redirectToCheckout(); * }; * * return ( *
* {error &&
{error}
} * *
* ); * } * ``` */ export declare const BuyNowServiceImplementation: import("@wix/services-definitions").ServiceFactory Promise; /** Reactive signal indicating if a checkout redirect is in progress */ loadingSignal: Signal; /** Reactive signal containing any error message, or null if no error */ errorSignal: Signal; /** Reactive signal indicating if the product is in stock */ inStockSignal: Signal; /** Reactive signal indicating if pre-order is available */ preOrderAvailableSignal: Signal; /** The name of the product */ productName: string; /** The price of the product as a string */ price: string; /** The currency code for the product price */ currency: string; }; __config: {}; isServiceDefinition?: boolean; } & { /** Function to redirect to checkout with the current product */ redirectToCheckout: () => Promise; /** Reactive signal indicating if a checkout redirect is in progress */ loadingSignal: Signal; /** Reactive signal containing any error message, or null if no error */ errorSignal: Signal; /** Reactive signal indicating if the product is in stock */ inStockSignal: Signal; /** Reactive signal indicating if pre-order is available */ preOrderAvailableSignal: Signal; /** The name of the product */ productName: string; /** The price of the product as a string */ price: string; /** The currency code for the product price */ currency: string; }, { productId: string; variantId?: string; productName: string; price: string; currency: string; inStock: boolean; preOrderAvailable: boolean; }>; /** * Loads buy now service initial data from the Wix Stores API for SSR initialization. * This function is designed to be used during Server-Side Rendering (SSR) to preload * product data required for the buy now functionality. * * @param {string} productSlug - The product slug to load data for * @param {string} [variantId] - Optional variant ID if a specific variant should be used * @returns {Promise} Promise that resolves to the buy now service configuration data * * @example * ```tsx * --- * // Astro page example - pages/product/[slug].astro * import { loadBuyNowServiceInitialData } from '@wix/stores/services'; * import { BuyNow } from '@wix/stores/components'; * * const { slug } = Astro.params; * const variantId = Astro.url.searchParams.get('variant'); * * // Load buy now data during SSR * const buyNowData = await loadBuyNowServiceInitialData(slug, variantId); * --- * * * {({ redirectToCheckout, isLoading, inStock, price, currency }) => ( * * )} * * ``` * * @example * ```tsx * // Next.js page example - pages/product/[slug].tsx * import { GetServerSideProps } from 'next'; * import { loadBuyNowServiceInitialData } from '@wix/stores/services'; * * export const getServerSideProps: GetServerSideProps = async ({ params, query }) => { * const slug = params?.slug as string; * const variantId = query.variant as string | undefined; * * const buyNowData = await loadBuyNowServiceInitialData(slug, variantId); * * return { * props: { * buyNowData, * }, * }; * }; * ``` */ export declare const loadBuyNowServiceInitialData: (productSlug: string, variantId?: string) => Promise<{ [BuyNowServiceDefinition]: { productId: string; productName: string; price: string; currency: string; variantId: string | null | undefined; inStock: boolean | undefined; preOrderAvailable: boolean | undefined; }; }>; /** * Helper function to create a buy now service binding with configuration. * This function simplifies the process of binding the buy now service with its configuration * and allows for additional configuration overrides. * * @template T - Type of the services configurations object * @param {T} servicesConfigs - Object containing service configurations * @param {Partial} [additionalConfig={}] - Additional configuration to override defaults * @returns Tuple containing service definition, implementation, and merged configuration * * @example * ```tsx * import { buyNowServiceBinding, loadBuyNowServiceInitialData } from '@wix/stores/services'; * * // Load initial data * const initialData = await loadBuyNowServiceInitialData('my-product-slug'); * * // Create service binding with additional config * const buyNowBinding = buyNowServiceBinding(initialData, { * inStock: false, // Override stock status * }); * * // Use in service provider * const services = createServicesMap([buyNowBinding]); * ``` */ export declare const buyNowServiceBinding: >[typeof BuyNowServiceDefinition]; }>(servicesConfigs: T, additionalConfig?: Partial) => readonly [string & { __api: { /** Function to redirect to checkout with the current product */ redirectToCheckout: () => Promise; /** Reactive signal indicating if a checkout redirect is in progress */ loadingSignal: Signal; /** Reactive signal containing any error message, or null if no error */ errorSignal: Signal; /** Reactive signal indicating if the product is in stock */ inStockSignal: Signal; /** Reactive signal indicating if pre-order is available */ preOrderAvailableSignal: Signal; /** The name of the product */ productName: string; /** The price of the product as a string */ price: string; /** The currency code for the product price */ currency: string; }; __config: {}; isServiceDefinition?: boolean; } & { /** Function to redirect to checkout with the current product */ redirectToCheckout: () => Promise; /** Reactive signal indicating if a checkout redirect is in progress */ loadingSignal: Signal; /** Reactive signal containing any error message, or null if no error */ errorSignal: Signal; /** Reactive signal indicating if the product is in stock */ inStockSignal: Signal; /** Reactive signal indicating if pre-order is available */ preOrderAvailableSignal: Signal; /** The name of the product */ productName: string; /** The price of the product as a string */ price: string; /** The currency code for the product price */ currency: string; }, import("@wix/services-definitions").ServiceFactory Promise; /** Reactive signal indicating if a checkout redirect is in progress */ loadingSignal: Signal; /** Reactive signal containing any error message, or null if no error */ errorSignal: Signal; /** Reactive signal indicating if the product is in stock */ inStockSignal: Signal; /** Reactive signal indicating if pre-order is available */ preOrderAvailableSignal: Signal; /** The name of the product */ productName: string; /** The price of the product as a string */ price: string; /** The currency code for the product price */ currency: string; }; __config: {}; isServiceDefinition?: boolean; } & { /** Function to redirect to checkout with the current product */ redirectToCheckout: () => Promise; /** Reactive signal indicating if a checkout redirect is in progress */ loadingSignal: Signal; /** Reactive signal containing any error message, or null if no error */ errorSignal: Signal; /** Reactive signal indicating if the product is in stock */ inStockSignal: Signal; /** Reactive signal indicating if pre-order is available */ preOrderAvailableSignal: Signal; /** The name of the product */ productName: string; /** The price of the product as a string */ price: string; /** The currency code for the product price */ currency: string; }, { productId: string; variantId?: string; productName: string; price: string; currency: string; inStock: boolean; preOrderAvailable: boolean; }>, { productId: string; variantId?: string; productName: string; price: string; currency: string; inStock: boolean; preOrderAvailable: boolean; }];