npm install @mycoverai/mca-javascript-sdk
pnpm add @mycoverai/mca-javascript-sdk
yarn add @mycoverai/mca-javascript-sdk
bun add @mycoverai/mca-javascript-sdk
<script src="https://unpkg.com/@mycoverai/mca-javascript-sdk/dist/index.js"></script>
//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);
}
<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>
The table below contains the available config parameters and their descriptions.
| Parameter | Type | Required | Description |
|---|---|---|---|
pk | string | Yes | Your unique Mycover.ai public key. |
action | string | Yes | The action you want to perform. Options: purchase, managePolicy, renewal, claim. |
pid | string | string[] | Yes* | The product ID or an array of product IDs. Required for purchase and claim actions. |
payment_option | string | Yes* | How the customer will pay. Options: gateway or wallet. Required for purchase and renewal actions. |
reference | string | No | A unique payment reference. Required if using the wallet payment option. |
callback | function | No | A function called upon successful operation (Purchase, Claim, Renewal, etc). Receives success_url (string) and data (object). |
onClose | function | No | A function called when the customer cancels or closes the SDK. Receives close_url (string). |
policy_id | string | No | The ID of an existing policy (used for policy management). |
claim_id | string | No | The ID of an existing claim (used to resume/track a claim). |