@acrosure/js-sdk 中文文档教程
Acrosure JavaScript SDK
用于连接 Acrosure 保险网关的 JavaScript SDK
Installation
通过 npm 安装:
npm install --save @acrosure/js-sdk
或者,如果您正在使用 yarn:
yarn add @acrosure/js-sdk
将
Getting Started
AcrosureClient 导入到您的项目中.
import AcrosureClient from '@acrosure/js-sdk'
// es5
const AcrosureClient = require('@acrosure/js-sdk')
或使用 cdn:使用
<script src="https://cdn.jsdelivr.net/npm/@acrosure/js-sdk@1.0.6/dist/acrosure-sdk.js"></script>
来自 Acrosure Dashboard 的 API 密钥进行实例化。
如果您在客户端使用它,请勿使用您的秘密令牌。
const acrosureClient = new AcrosureClient({
token: '<your_api_key>'
})
Basic Usage
AcrosureClient 提供多个对象,例如application
、product
等. 和相关的 API。
任何数据都将包含在具有 data
键的响应对象中,以及元数据,例如:
{
"data": { ... },
"status": "ok",
...
}
Application
Get
获取具有指定 ID 的应用程序。
const application = acrosureClient.application.get('<application_id>')
Create
创建一个应用程序。
const createdApplication = await acrosureClient.application.create({
productId: '<product_id>', // required
basic_data: {},
package_options: {},
additional_data: {},
package_code: '<package_code>',
attachments: []
})
Update
更新应用程序。
const updatedApplication = await acrosureClient.application.update({
application_id: '<application_id>', // required
basic_data: {},
package_options: {},
additional_data: {},
package_code: '<package_code>',
attachments: []
})
Get packages
获取当前应用程序可用包。
const packages = await acrosureClient.application.getPackages(
'<application_id>'
)
Select package
为当前应用程序选择包。
const updatedApplication = await acrosureClient.application.selectPackage({
application_id: '<application_id>',
package_code: '<package_code>'
})
Get package
获取当前应用程序的选定包。
const currentPackage = await acrosureClient.application.getPackage(
'<application_id>'
)
Redirect to payment page
将用户重定向到 2C2P 支付页面(仅限浏览器)。
await acrosureClient.application.redirectToPayment({
application_id: '<application_id>',
frontend_url: '<redirect_url>'
})
Submit
提交当前申请。
const submittedApplication = await acrosureClient.application.submit(
'<application_id>'
)
Confirm
确认当前应用程序。
此功能需要秘密 API 密钥。
const confirmedApplication = await acrosureClient.application.confirm(
'<application_id>'
)
List
列出您的应用程序(有或没有查询)。
const applications = await acrosureClient.application.list(query)
Product
Get
获取具有指定 ID 的产品。
const product = await acrosureClient.product.get('<product_id>')
List
列出您的产品(有或没有查询)。
const products = await acrosureClient.product.list(query)
Policy
Get
获取具有指定 ID 的策略。
const policy = await acrosureClient.policy.get('<policy_id>')
List
列出您的政策(有或没有查询)。
const policies = await acrosureClient.policy.list(query)
Data
Get
获取处理程序的值(有或没有依赖项,请参阅 Acrosure API 文档)。
// 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
获取当前团队信息。
const teamInfo = await acrosureClient.team.getInfo()
Other functionality
Verify webhook signature
通过指定签名和原始数据字符串来验证 webhook 签名。 (仅限Node.js环境)
const isSignatureValid = acrosureClient.verifySignature(
'<signature>',
'<raw_data>'
)
Advanced Usage
AcrosureClient的使用请参考本文档。
有关 Acrosure API 的更多详细信息,请参阅 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
Acrosure JavaScript SDK
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