Skip to main content

useCheckout

SolvaPay SDK v1.0.0


SolvaPay SDK / react/src / useCheckout

Function: useCheckout()

useCheckout(options): UseCheckoutReturn

Defined in: packages/react/src/hooks/useCheckout.ts:71

Hook to manage checkout flow for payment processing.

Handles payment intent creation and Stripe initialization. This hook manages the checkout state including loading, errors, Stripe instance, and client secret. Use this for programmatic checkout flows.

Parameters

options

Checkout options

planRef

string

Plan reference to purchase (required)

productRef?

string

Optional product reference for usage tracking

Returns

UseCheckoutReturn

Checkout state and methods

Example

import { useCheckout } from '@solvapay/react';
import { PaymentElement } from '@stripe/react-stripe-js';

function CustomCheckout() {
const { loading, error, stripePromise, clientSecret, startCheckout } = useCheckout({
planRef: 'pln_premium',
productRef: 'prd_myapi',
});

useEffect(() => {
startCheckout();
}, []);

if (loading) return <Spinner />;
if (error) return <div>Error: {error.message}</div>;
if (!clientSecret || !stripePromise) return null;

return (
<Elements stripe={await stripePromise} options={{ clientSecret }}>
<PaymentElement />
</Elements>
);
}

See

Since

1.0.0