JavaScript SDK for connecting with Acrosure Insurance Gateway
Install via npm:
npm install --save @acrosure/js-sdk
Or if you're using yarn:
yarn add @acrosure/js-sdk
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/[email protected]/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>'
})
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",
...
}
Get application with specified id.
const application = acrosureClient.application.get('<application_id>')
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 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 current application available packages.
const packages = await acrosureClient.application.getPackages(
'<application_id>'
)
Select package for current application.
const updatedApplication = await acrosureClient.application.selectPackage({
application_id: '<application_id>',
package_code: '<package_code>'
})
Get selected package of current application.
const currentPackage = await acrosureClient.application.getPackage(
'<application_id>'
)
Redirect user to 2C2P payment page (Browser only).
await acrosureClient.application.redirectToPayment({
application_id: '<application_id>',
frontend_url: '<redirect_url>'
})
Submit current application.
const submittedApplication = await acrosureClient.application.submit(
'<application_id>'
)
Confirm current application.
This function needs secret API key.
const confirmedApplication = await acrosureClient.application.confirm(
'<application_id>'
)
List your applications (with or without query).
const applications = await acrosureClient.application.list(query)
Get product with specified id.
const product = await acrosureClient.product.get('<product_id>')
List your products (with or without query).
const products = await acrosureClient.product.list(query)
Get policy with specified id.
const policy = await acrosureClient.policy.get('<policy_id>')
List your policies (with or without query).
const policies = await acrosureClient.policy.list(query)
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>']
})
Get current team information.
const teamInfo = await acrosureClient.team.getInfo()
Verify webhook signature by specify signature and raw data string. (Only Node.js environment)
const isSignatureValid = acrosureClient.verifySignature(
'<signature>',
'<raw_data>'
)
Please refer to this document for AcrosureClient usage.
And refer to Acrosure API Document for more details on Acrosure API.
/applications/get
/applications/list
/applications/create
/applications/update
/applications/get-packages
/applications/get-package
/applications/select-package
/applications/submit
/applications/confirm
/applications/get-hash
/products/get
/products/list
/policies/get
/policies/list
/data/get
/teams/get-info