import type { GooglePayConfig, GooglePayConfigFromFindEligibleMethods, GooglePayButtonOptions, GooglePayApprovePaymentResponse, GooglePayTransactionInfo, LiabilityShiftType, BasePaymentSessionReturn } from "../types"; /** * Data passed to `onApprove`. When the order required 3DS * (`PAYER_ACTION_REQUIRED`), this fires after the payer-action flow resolves and * includes the resulting `liabilityShift`. * * @remarks * `liabilityShift` is the only 3DS field the JS SDK surfaces client-side. The * full authentication result — `liability_shift` alongside the enrollment and * authentication statuses — lives on the order at * `payment_source.google_pay.card.authentication_result`. Merchants who need * that richer context to decide whether to capture (for example, a `"NO"` * shift can mean either a hard decline or "card not enrolled, proceed at your * own risk") should read it from the order server-side rather than from this * payload. */ export type GooglePayOnApproveData = GooglePayApprovePaymentResponse & { /** * The 3DS liability-shift outcome, present only when 3DS ran. For the * enrollment and authentication statuses, read the order's * `payment_source.google_pay.card.authentication_result` server-side. */ liabilityShift?: LiabilityShiftType; }; export type UseGooglePayOneTimePaymentSessionProps = { /** * Google Pay configuration from findEligibleMethods. * Used to format the payment request with allowed payment methods and merchant info. */ googlePayConfig: GooglePayConfigFromFindEligibleMethods; /** * Transaction info for the Google Pay payment request. */ transactionInfo: GooglePayTransactionInfo; /** * Google Pay environment. Use "TEST" for sandbox and "PRODUCTION" for live. * @default "TEST" */ environment?: "TEST" | "PRODUCTION"; /** * Callback function to create an order. * Should return a promise that resolves to an object with orderId. */ createOrder: () => Promise<{ orderId: string; }>; /** * Callback invoked when the payment is successfully approved. * * When 3DS (`PAYER_ACTION_REQUIRED`) is required, this fires after the * payer-action flow resolves, and the data includes `liabilityShift`. * The enrollment and authentication statuses are not surfaced here; read the * order's `payment_source.google_pay.card.authentication_result` server-side * if you need them. */ onApprove: (data: GooglePayOnApproveData) => void | Promise; /** * Optional callback invoked when the payment is cancelled. */ onCancel?: () => void; /** * Optional callback invoked when an error occurs. */ onError?: (error: Error) => void; }; export type UseGooglePayOneTimePaymentSessionReturn = BasePaymentSessionReturn & { /** * The Google Pay PaymentsClient instance. * Used internally to check readiness and create the payment button. * Advanced users may interact with this directly if needed. * @default null (until session is fully initialized) */ paymentsClient: google.payments.api.PaymentsClient | null; /** * The formatted Google Pay configuration for the payment request. * Includes allowed payment methods, merchant info, and API versions. * @default null (until session is fully initialized) */ formattedConfig: GooglePayConfig | null; /** * Creates the native Google Pay button after checking eligibility via isReadyToPay. * Setup errors are captured in hook state and forwarded to onError. */ createGooglePayButton: (options: GooglePayButtonOptions) => Promise; }; /** * Hook for managing Google Pay one-time payment sessions. * * This hook creates and manages a complete Google Pay payment session, handling the entire * flow from button click through payment authorization to order confirmation. * * Unlike Apple Pay and Venmo (which use web components), Google Pay uses Google's PaymentsClient * to drive the payment UI. This hook returns the PaymentsClient and formatted config so the * GooglePayOneTimePaymentButton component can: * 1. Check device/browser readiness with `isReadyToPay()` * 2. Create the native Google Pay button before user interaction * 3. Load payment data and handle payment callbacks * * The hook manages the entire session lifecycle including order creation, payment confirmation, * 3DS (PAYER_ACTION_REQUIRED) handling, and error management. * * When an order requires 3DS, the hook launches the payer-action (SCA) flow automatically and * calls `onApprove` (which merchants typically use to capture) after the payer-action flow * resolves. On that path the `onApprove` data also includes `liabilityShift`. If the buyer * cancels or authentication errors out, `onError` is called instead. * * @example * ```typescript * function GooglePayCheckoutButton() { * const { sdkInstance } = usePayPal(); * const [googlePayConfig, setGooglePayConfig] = useState(null); * * useEffect(() => { * const fetchConfig = async () => { * const methods = await sdkInstance?.findEligibleMethods({ currencyCode: "USD" }); * if (methods?.isEligible("googlepay")) { * setGooglePayConfig(methods.getDetails("googlepay").config); * } * }; * fetchConfig(); * }, [sdkInstance]); * * const { isPending, error, handleClick } = useGooglePayOneTimePaymentSession({ * googlePayConfig, * transactionInfo: { * countryCode: "US", * currencyCode: "USD", * totalPriceStatus: "FINAL", * totalPrice: "100.00", * }, * createOrder: async () => { * const response = await fetch("/api/orders", { method: "POST" }); * const data = await response.json(); * return { orderId: data.id }; * }, * onApprove: (data) => { * // data.liabilityShift is present when 3DS ran * console.log("Payment approved:", data); * }, * onError: (err) => console.error("Payment error:", err), * }); * * if (isPending || !googlePayConfig) return null; * if (error) return
Error: {error.message}
; * * return ; * } * ``` */ export declare function useGooglePayOneTimePaymentSession({ googlePayConfig, transactionInfo, environment, createOrder, ...callbacks }: UseGooglePayOneTimePaymentSessionProps): UseGooglePayOneTimePaymentSessionReturn;