Link/Web / JavaScript

Web / JavaScript SDK

CoverPayLink opens CoverPay's checkout over your page with a link token from your server. It works with any framework. For React, use useCoverPayLink.

Install

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

Open Link

import { CoverPayLink } from '@coverpay/sdk';

const callbacks = {
  onSuccess: (publicToken, metadata) => exchangeOnYourServer(publicToken),
  onExit: (error, metadata) => {},
};

CoverPayLink.handleRedirect(callbacks);   // once, on page load (see "Redirects" below)

const link = CoverPayLink.create({
  token: linkToken,                       // from POST /v1/link/token/create on your server
  ...callbacks,
  onEvent: (name, metadata) => {},        // optional funnel events
});

payLaterButton.addEventListener('click', () => link.open());

Options

OptionTypeDescription
tokenstringRequired. A link token (lt_test_… or lt_live_…). Anything else throws right away.
onSuccess(publicToken, metadata) => voidRequired. The shopper finished. Exchange publicToken on your server. It is null only when the provider approved but CoverPay hadn't confirmed yet: don't charge again, wait for your webhook.
onExit(error, metadata) => voidThe shopper closed Link (error is null) or it failed (error.code, error.message).
onEvent(name, metadata) => voidFunnel events: OPEN, OFFERS_LOADED, OFFER_SELECTED, STEP_CHANGE, CLOSE.

onSuccess or onExit is called exactly once per open(). The handler also hasexit() (close as if the shopper did) and destroy() (remove without callbacks).

onSuccess metadata

{
  provider: "zip",                 // klarna | affirm | afterpay | zip | coverpay
  sessionId: "pi_3UO3…",           // CoverPay payment id (also returned by the exchange)
  status: "succeeded",             // succeeded | requires_capture | processing
  paymentIntentId: "pi_3UO3…"      // Stripe PaymentIntent for Stripe-backed providers, else null
}

Redirects

Klarna, Affirm, Afterpay, Zip and CoverPay's own plan take the shopper's whole page to the provider to approve. When they finish, CoverPay sends them back to the page that opened Link with the result in the URL fragment. CoverPayLink.handleRedirect(callbacks) reads it, callsonSuccess or onExit once, removes it from the URL and returns true. Call it on every load of your checkout page.

What comes back
#coverpay_status=success&coverpay_public_token=public-sandbox-…&coverpay_provider=zip&…(or coverpay_status=exit / error). It is in the fragment, so it never reaches your server logs. The public token is useless without your secret key.

Script tag

<script src="coverpay.js"></script>  <!-- the built @coverpay/sdk bundle -->
<script>
  CoverPayLink.handleRedirect({ onSuccess, onExit });
  const link = CoverPayLink.create({ token, onSuccess, onExit });
</script>

Older API

CoverPay.create({ clientId }).open({ amount, ... }) still works in sandboxfor demos and accepts linkToken. Without a link token it refuses production, because the amount would come from the browser. checkEligibility is deprecated: callPOST /v1/checkout/verify-eligibility from your server.