npm package: @mycoverai/mca-javascript-sdk
Description: Supercharge your business with embedded insurance
Author: MyCover.ai
Latest version: 0.9.0

# MyCover.ai 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

```bash
npm install @mycoverai/mca-javascript-sdk@latest
```

### From CDN

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

## Usage

### With NPM

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

//setup your business configuration by supplying your public key. If pid 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 = {
  pid: ["a72c4e3c-e868-4782-bb35-df6e3344ae6c"], //optional
  pk: "MCAPUBK_TEST|d24a7f02-99c8-497f-b1cc-d6d14d7963d5",
  form: {} /*** Provide form data 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": "lagos",
   "first_name": "micheal",
   "last_name": "okafor",
   "bvn": "22226850607",
   "address": "Plot 8, Providence Street, Lekki Phase 1, Lagos, Nigeria",
   "email": "mikeokafor@mailinator.com",
   "date_of_birth": "2015-05-19",
   "phone_number": "08011111111",
  }
   Where the property names do not match the ones we have provided above, such fields will be discarded and ignored.
 ***/,
  payment_option: "gateway", //set to 'wallet' or 'gateway' to define default payment option
  callback: Function, //A function you want us to call after the user has completed
  onClose: Function, //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,
  action: "purchase",
};

//create a function that starts up the SDK
function buyInsurance() {
  mycoverai(config);
}
```

### With CDN

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

<script src="https://unpkg.com/@mycoverai/mca-javascript-sdk/dist/index.js"></script>
<script>
  const config = {
    pid: ["a72c4e3c-e868-4782-bb35-df6e3344ae6c"], //optional
    pk: "MCAPUBK_TEST|d24a7f02-99c8-497f-b1cc-d6d14d7963d5",
    form: {} /*** Provide form 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": "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.
     ***/,
    payment_option: "gateway", //set to 'wallet' or 'gateway' to define default payment option
    callback: Function, //A function you want us to call after the user has completed
    onClose: Function, //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,
    action: "purchase",
  };

  function buyInsurance() {
    mycoverai(config);
  }
</script>
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License

[MIT](https://choosealicense.com/licenses/mit/)