Javascript

Create embedded insurance offerings using our JavaScript SDK.

Installation

With NPM

npm install @mycoverai/mca-javascript-sdk

From CDN

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

Usage

With NPM

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

//setup your business configuration by supplying your public key.
const config = {
  productId: [],
  publicKey: 'MCAPUBK_TEST|d24a7f02-99c8-497f-b1cc-d6d14d7963d5',
  form: {
    first_name: "Lucian",
    last_name: "Bryant",
    email: "dyzivoga@mailinator.com",
  },
  paymentOption: 'gateway',
  callback: handleSuccess,
  onClose: handleClose,
}

//create a function that starts up the SDK
function buyInsurance() {
  mycoverai(config)
}
function handleClose() {
//do something
}
function handleSuccess() {
//do something
}

With CDN

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

<script src="https://unpkg.com/@mycoverai/mca-javascript-sdk/dist/index.js"></script>
<script>
  const config = {
    productId: ['a8b4bca1-b870-4648-8704-11c1802a51d0'],
    publicKey: 'MCAPUBK_TEST|d24a7f02-99c8-497f-b1cc-d6d14d7963d5',
    form: {
      first_name: "Lucian",
      last_name: "Bryant",
      email: "dyzivoga@mailinator.com",
    },
    paymentOption: 'wallet',
    callback: handleSuccess,
    onClose: handleClose,
  }

  function buyInsurance() {
    mycoverai(config)
  }
  function handleClose() {
  //do something
  }
  function handleSuccess() {
  //do something
  }
</script>

Configuration

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

PARAMETERDESCRIPTIONREQUIREDTYPEDEFAULT

productId

Mycover.ai insurance product id. If productId is not provided or is an empty array, the SDK will display a list of insurance products for the customer to choose from. You can supply an array of strings, where each string represents an insurance product id, for the user to select from.

No

<string>Array

[]

publicKey

Your unique Mycover.ai public key

Yes

string

-

form

Provide form data that your user has already given to ease form filling. The form object and all its properties are optional, you only need to provide this when they are available. However, the property names must match the following format form: { "state": "Nasarawa", "first_name": "Lucian", "last_name": "Bryant", "address": "Rem quae molestias h", "email": "dyzivoga@mailinator.com", "date_of_birth": "2015-05-19", "phone_number": "+2348011111111", } Where the property names do not match the ones we have provided above, such fields will be discarded and ignored.

No

object

{}

paymentOption

Set to 'wallet' or 'gateway' to define default payment option

Yes

gateway | wallet

gateway

willInspect

Ignore or set to false if you do not need inspection enabled. Set to true to enable inspection

No

boolean

true

callback

A function to call after the user has completed a purchase, claim, or inspection

No

function

-

onClose

A function to call after the user closes without completing a purchase, activation or inspection

No

function

-

action

Sets what action is to be taken on the initialization of the SDK.

Yes

purchase | inspection | claim | inspectionAsService | claimAsService

purchase

reference

Supply reference when you want the user to continue to the insurance activation step. This only applies to users who have previously bought insurance using this SDK

No

string

-

landingUrls

Supply landing page urls if you want your users to be re-routed to your custom web page after completing a purchase or claim. It takes in a maximum of two urls. The first url is called after a purchase. The second url is called after a claim. If you don't specify a url, your users will be redirected to Mycover.ai by default.

No

<string>Array

[]

Last updated