MyCover AI
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 package
import mycoverai from "@mycoverai/mca-javascript-sdk";

//setup your business configuration by supplying your public key.
const config = {
  action: "purchase",
  pid: ["<product-id>"],
  pk: "MCAPUBK_...your_public_key...",
  callback: handleSuccess,
  onClose: handleClose,
};

//create a function that starts up the SDK
function buyInsurance() {
  mycoverai(config);
}
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_...your_public_key...",
    callback: handleSuccess,
    onClose: handleClose,
  };

  function buyInsurance() {
    mycoverai(config);
  }
  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).