Link/React

React SDK

useCoverPayLink is the React wrapper around CoverPayLink. Pass the link token from your server; open Link from a button.

Install

Early access
@coverpay/react isn't on npm yet. Email support@coverpayme.com and we'll send you the package.
npm install @coverpay/react   # once you have access

Use it

import { useCoverPayLink } from '@coverpay/react';

function PayLaterButton({ linkToken }: { linkToken: string | null }) {
  const { open, ready, error } = useCoverPayLink({
    token: linkToken,
    onSuccess: (publicToken, metadata) => {
      fetch('/api/coverpay/exchange', { method: 'POST', body: JSON.stringify({ publicToken }) });
    },
    onExit: (error, metadata) => {},
  });

  return <button disabled={!ready} onClick={() => open()}>Pay later</button>;
}
ReturnsDescription
open()Opens Link. Call it from a click.
readyTrue once a valid token is set.
exit()Closes Link as if the shopper did (onExit, no error).
errorSet if the token is not a CoverPay link token.
Redirects are handled for you
Providers take the whole page to approve the plan; CoverPay then sends the shopper back. On mount the hook checks for that result and calls your onSuccess or onExit once, so mount it on the page that opened Link.

The older CoverPayProvider / CoverPayButton components still work in sandbox and acceptlinkToken in open(); they refuse production without one.