@acrosure/js-sdk

Acrosure JavaScript SDK

Usage no npm install needed!

<script type="module">
  import acrosureJsSdk from 'https://cdn.skypack.dev/@acrosure/js-sdk';
</script>

README

Acrosure JavaScript SDK

Acrosure

JavaScript SDK for connecting with Acrosure Insurance Gateway

Installation

Install via npm:

npm install --save @acrosure/js-sdk

Or if you're using yarn:

yarn add @acrosure/js-sdk

Getting Started

Import AcrosureClient into your project.

import AcrosureClient from '@acrosure/js-sdk'

// es5
const AcrosureClient = require('@acrosure/js-sdk')

or use cdn:

<script src="https://cdn.jsdelivr.net/npm/@acrosure/js-sdk@1.0.6/dist/acrosure-sdk.js"></script>

Instantiate with an API key from Acrosure Dashboard.

If you're using this on client-side, DO NOT use your secret token.

const acrosureClient = new AcrosureClient({
  token: '<your_api_key>'
})

Basic Usage

AcrosureClient provides several objects such as application, product, etc. and associated APIs.

Any data will be inside an response object with data key, along with meta data, such as:

{
  "data": { ... },
  "status": "ok",
  ...
}

Application

Get

Get application with specified id.

const application = acrosureClient.application.get('<application_id>')

Create

Create an application.

const createdApplication = await acrosureClient.application.create({
  productId: '<product_id>', // required
  basic_data: {},
  package_options: {},
  additional_data: {},
  package_code: '<package_code>',
  attachments: []
})

Update

Update an application.

const updatedApplication = await acrosureClient.application.update({
  application_id: '<application_id>', // required
  basic_data: {},
  package_options: {},
  additional_data: {},
  package_code: '<package_code>',
  attachments: []
})

Get packages

Get current application available packages.

const packages = await acrosureClient.application.getPackages(
  '<application_id>'
)

Select package

Select package for current application.

const updatedApplication = await acrosureClient.application.selectPackage({
  application_id: '<application_id>',
  package_code: '<package_code>'
})

Get package

Get selected package of current application.

const currentPackage = await acrosureClient.application.getPackage(
  '<application_id>'
)

Redirect to payment page

Redirect user to 2C2P payment page (Browser only).

await acrosureClient.application.redirectToPayment({
  application_id: '<application_id>',
  frontend_url: '<redirect_url>'
})

Submit

Submit current application.

const submittedApplication = await acrosureClient.application.submit(
  '<application_id>'
)

Confirm

Confirm current application.

This function needs secret API key.

const confirmedApplication = await acrosureClient.application.confirm(
  '<application_id>'
)

List

List your applications (with or without query).

const applications = await acrosureClient.application.list(query)

Product

Get

Get product with specified id.

const product = await acrosureClient.product.get('<product_id>')

List

List your products (with or without query).

const products = await acrosureClient.product.list(query)

Policy

Get

Get policy with specified id.

const policy = await acrosureClient.policy.get('<policy_id>')

List

List your policies (with or without query).

const policies = await acrosureClient.policy.list(query)

Data

Get

Get values for a handler (with or without dependencies, please refer to Acrosure API Document).

// Without dependencies
const values = await acrosureClient.data.get({
  handler: '<some_handler>'
})

// With dependencies
const values = await acrosureClient.data.get({
  handler: '<some_handler>',
  dependencies: ['<dependency_1>', '<dependency_2>']
})

Team

Get info

Get current team information.

const teamInfo = await acrosureClient.team.getInfo()

Other functionality

Verify webhook signature

Verify webhook signature by specify signature and raw data string. (Only Node.js environment)

const isSignatureValid = acrosureClient.verifySignature(
  '<signature>',
  '<raw_data>'
)

Advanced Usage

Please refer to this document for AcrosureClient usage.

And refer to Acrosure API Document for more details on Acrosure API.

Associated Acrosure API endpoints

Application

/applications/get
/applications/list
/applications/create
/applications/update
/applications/get-packages
/applications/get-package
/applications/select-package
/applications/submit
/applications/confirm
/applications/get-hash

Product

/products/get
/products/list

Policy

/policies/get
/policies/list

Data

/data/get

Team

/teams/get-info