Libraries and SDKs

JavaScript

Create embedded insurance offerings using our JavaScript SDK.

Installation

Package Manager

npm install @mycoverai/mca-javascript-sdk

CDN

<script src="https://unpkg.com/@mycoverai/mca-javascript-sdk/dist/index.js"></script>

Usage

With A Package Manager

//import SDK package
import mycoverai from "@mycoverai/mca-javascript-sdk";

//Define your configuration object
const config = {
  action: "purchase",
  pid: ["<product-id>"],
  pk: "MCAPUBK_ENV|your_public_key",
  payment_option: "gateway",
  reference: "BUY-<unique-reference-id>", // Required if using wallet payment option
  callback: handleSuccess,
  onClose: handleClose,
};

// Initialize the SDK with your configuration
function buyInsurance() {
  mycoverai(config);
}

// Optional callbacks
function handleClose(close_url) {
  console.log("SDK closed", close_url);
}

function handleSuccess(success_url, data) {
  console.log("Operation successful", success_url, data);
}

With CDN

<button onclick="buyInsurance()">Buy Insurance</button>

<script src="https://unpkg.com/@mycoverai/mca-javascript-sdk/dist/index.js"></script>
<script>
  const config = {
    action: "purchase",
    pid: ["<product-id>"],
    pk: "MCAPUBK_ENV|your_public_key",
    payment_option: "gateway",
    reference: "BUY-<unique-reference-id>", // Required if using wallet payment option
    callback: handleSuccess,
    onClose: handleClose,
  };

  // Initialize the SDK with your configuration
  function buyInsurance() {
    mycoverai(config);
  }

  // Optional callbacks
  function handleClose(close_url) {
    console.log("SDK closed", close_url);
  }
  function handleSuccess(success_url, data) {
    console.log("Operation successful", success_url, data);
  }
</script>

Configuration

The table below contains the available config parameters and their descriptions.

ParameterTypeRequiredDescription
pkstringYesYour unique Mycover.ai public key.
actionstringYesThe action you want to perform. Options: purchase, managePolicy, renewal, claim.
pidstring | string[]Yes*The product ID or an array of product IDs. Required for purchase and claim actions.
payment_optionstringYes*How the customer will pay. Options: gateway or wallet. Required for purchase and renewal actions.
referencestringNoA unique payment reference. Required if using the wallet payment option.
callbackfunctionNoA function called upon successful operation (Purchase, Claim, Renewal, etc). Receives success_url (string) and data (object).
onClosefunctionNoA function called when the customer cancels or closes the SDK. Receives close_url (string).
policy_idstringNoThe ID of an existing policy (used for policy management).
claim_idstringNoThe ID of an existing claim (used to resume/track a claim).
Copyright © 2026