@paypal/react-paypal-js
Version:
React components for the PayPal JS SDK
43 lines (42 loc) • 1.99 kB
TypeScript
import type { BasePaymentSessionReturn, CreateOrderCallback, PayLaterOneTimePaymentSessionOptions, PayPalPresentationModeOptions } from "../types";
export type UsePayLaterOneTimePaymentSessionProps = ((Omit<PayLaterOneTimePaymentSessionOptions, "orderId"> & {
createOrder: CreateOrderCallback;
orderId?: never;
}) | (PayLaterOneTimePaymentSessionOptions & {
createOrder?: never;
orderId: string;
})) & PayPalPresentationModeOptions;
/**
* Hook for managing Pay Later one-time payment sessions.
*
* This hook creates and manages a Pay Later payment session. It handles session lifecycle, resume flows
* for redirect-based presentation modes (`"redirect"` and `"direct-app-switch"`), and provides methods
* to start, cancel, and destroy the session.
*
* @returns Object with: `error` (any session error), `isPending` (SDK loading), `handleClick` (starts session), `handleCancel` (cancels session), `handleDestroy` (cleanup)
*
* @example
* function PayLaterCheckoutButton() {
* const { error, isPending, handleClick, handleCancel } = usePayLaterOneTimePaymentSession({
* presentationMode: 'popup',
* createOrder: async () => ({ orderId: 'ORDER-123' }),
* onApprove: (data) => console.log('Approved:', data),
* onCancel: () => console.log('Cancelled'),
* });
* const { eligiblePaymentMethods } = usePayPal();
* const payLaterDetails = eligiblePaymentMethods?.getDetails?.("paylater");
*
* if (isPending) return null;
* if (error) return <div>Error: {error.message}</div>;
*
* return (
* <paypal-pay-later-button
* countryCode={payLaterDetails?.countryCode}
* productCode={payLaterDetails?.productCode}
* onClick={handleClick}
* onCancel={handleCancel}
* />
* );
* }
*/
export declare function usePayLaterOneTimePaymentSession({ presentationMode, fullPageOverlay, autoRedirect, createOrder, orderId, ...callbacks }: UsePayLaterOneTimePaymentSessionProps): BasePaymentSessionReturn;