MyCover AI
Search…
⌃K

Javascript SDK

Official MyCover.ai SDK. Supercharge your product with MyCover AI Insurance offerings. Create embedded insurance offerings or full white label insurance applications that excite your customers.

Installation

With NPM

npm install @mycoverai/mca-javascript-sdk

From CDN

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

Usage

With NPM

//import package
import mycoverai from "@mycoverai/mca-javascript-sdk"
//setup your business configuration by supplying your public key. 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.
const config = {
productId: ['a72c4e3c-e868-4782-bb35-df6e3344ae6c'], //optional
publicKey: '[email protected]',
form: {}, /*** Provide forma date that your user has already given to ease form filling. The form object and all it's 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",
"bvn": "22226850607",
"address": "Rem quae molestias h",
"email": "[email protected]",
"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.
***/
paymentOption: 'wallet', //set to 'wallet' or 'gateway' to define default payment option
willInspect: true, // ignore or set to false if you do not need inspection enabled. Set to true to enable inspection
callback: handleSuccess, //A function you want us to call after the user has completed
onClose: handleClose, //A function you want us to call after the user closes without completing a purchase, activation or inspection
reference: '',//optional. 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
}
//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: ['a72c4e3c-e868-4782-bb35-df6e3344ae6c'], //optional
publicKey: '[email protected]',
form: {}, /*** Provide forma date that your user has already given to ease form filling. The form object and all it's 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",
"bvn": "22226850607",
"address": "Rem quae molestias h",
"email": "[email protected]",
"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.
***/
paymentOption: 'wallet', //set to 'wallet' or 'gateway' to define default payment option
willInspect: true, // ignore or set to false if you do not need inspection enabled. Set to true to enable inspection
callback: handleSuccess, //A function you want us to call after the user has completed
onClose: handleClose, //A function you want us to call after the user closes without completing a purchase, activation or inspection
reference: '',//optional. 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
}
function buyInsurance() {
mycoverai(config)
}
function handleClose() {
//do something
}
function handleSuccess() {
//do something
}
</script>