Scripts
Overview
Scripts are javascript which are to be executed in CoverGo's backend. They are very useful in the calculations of pricing and claims in Product, Offer and Policy.
In this example, we will demostrate how Product, Case, Proposal, Offer, Policy and Scripts work together.
Create Products
Create the products
Let's create two products: Demo Insurance Plan 1 and Demo Insurance Plan 2.
Tips:
Creation of products can be done through the Product Builder developed by CoverGo.
Querying the products created:
query product {
products_2 {
totalCount
list{
productId { plan type version }
representation
}
}
}
result:
{
"data": {
"products_2": {
"totalCount": 2,
"list": [
{
"productId": {
"plan": "Plan 1",
"type": "Demo Insurance",
"version": "1"
},
"representation": "<PRODUCT_REPRESENTATION_CREATED_BY_PRODUCT_BUILDER>"
},
{
"productId": {
"plan": "Plan 2",
"type": "Demo Insurance",
"version": "1"
},
"representation": "<PRODUCT_REPRESENTATION_CREATED_BY_PRODUCT_BUILDER>"
}
]
}
}
}
Calculation of pricing
Pricing calculation is done through PRICING script. The script inteprets product.representation
and a dataInput
to calculate the pricing (eg. premium, levies, etc). An example of PRICING script result will be:
"{\n \"isSuccess\": true,\n \"data\": {\n \"aggregatePerContract\": {\n \"grossPrice\": 100,\n \"grossPriceProrated\": 0,\n \"netPrice\": 100,\n \"netPriceProrated\": 0,\n \"grossPriceWithFormat\": \"$100\",\n \"grossPriceProratedWithFormat\": \"$0\",\n \"netPriceWithFormat\": \"$100\",\n \"netPriceProratedWithFormat\": \"$0\"\n },\n \"aggregatePerPlans\": {\n \"undefined\": {\n \"grossPrice\": 100,\n \"grossPriceProrated\": 0,\n \"netPrice\": 100,\n \"netPriceProrated\": 0,\n \"grossPriceWithFormat\": \"$100\",\n \"grossPriceProratedWithFormat\": \"$0\",\n \"netPriceWithFormat\": \"$100\",\n \"netPriceProratedWithFormat\": \"$0\"\n }\n }\n }\n}"
Tips:
PRICING scripts are to be provided by CoverGo.
Create Case, Proposal and Offers
A client is interested in purchasing the two products we have. We shall create a case for the client with a proposal including two offers, which are "Demo Insurance Plan 1" and "Demo Insurance Plan 2".
Create a case
mutation creatCase(
$input: createCaseInput!
) {
createCase(input: $input) {
status
createdStatus { id }
errors
}
}
Input:
{
"input": {
"name": "Demo case",
"description": "A case for demo",
"status": "created",
"fields": "{\"key\":\"value\"}"
}
}
Add proposal to the case
mutation addProposalToCase(
$caseId:String!
$input:addProposalInput!
) {
addProposal(
caseId: $caseId
input: $input
) {
status
createdStatus { id }
errors
}
}
Input:
{
"caseId": "3e456424-daa4-4f32-ab9b-a303c8af98bd",
"input": {
"name": "Demo Proposal",
"status": "Created",
"expiryDate": "2022-04-28T10:26:36.738Z"
}
}
Add offers to the case proposal
mutation addOfferToProposal(
$caseId:String!
$proposalId:String!
$input:addOfferInput!
) {
addOfferToProposal(
caseId: $caseId
proposalId: $proposalId
input: $input
){
status
createdStatus { id }
errors
}
}
Input:
{
"caseId": "3e456424-daa4-4f32-ab9b-a303c8af98bd",
"proposalId": "1049d48c-bd35-4170-9d68-ca14160e29a9",
"input": {
"productId": {
"type": "Demo Insurance",
"plan":"Plan 1",
"version":"1"
},
"fields": "<FIELDS_AS_DATA_INPUT_FOR_PRICING_SCRIPT>"
}
}
and:
{
"caseId": "3e456424-daa4-4f32-ab9b-a303c8af98bd",
"proposalId": "1049d48c-bd35-4170-9d68-ca14160e29a9",
"input": {
"productId": {
"type": "Demo Insurance",
"plan":"Plan 2",
"version":"1"
},
"fields": "<FIELDS_AS_DATA_INPUT_FOR_PRICING_SCRIPT>"
}
}
Tips:
The
fields
in the above offer serve as thedataInput
for the PRICING script.
Querying the case created
query cases{
cases {
totalCount
list{
id
proposals {
id
basket {
id
fields
pricing
product {
productId { type plan version }
representation
}
}
}
}
}
}
result:
{
"data": {
"cases": {
"totalCount": 1,
"list": [
{
"id": "3e456424-daa4-4f32-ab9b-a303c8af98bd",
"proposals": [
{
"id": "1049d48c-bd35-4170-9d68-ca14160e29a9",
"basket": [
{
"id": "7d642f3d-7e5d-4f33-8401-a57c8c05d641",
"fields": "<FIELDS_AS_DATA_INPUT_FOR_PRICING_SCRIPT>",
"pricing": "<EXECUTION_RESULT_OF_PRICING_SCRIPT>",
"product": {
"productId": {
"type": "Demo Insurance",
"plan": "Plan 1",
"version": "1"
},
"representation": "<PRODUCT_REPRESENTATION_CREATED_BY_PRODUCT_BUILDER>"
}
},
{
"id": "9c554602-d6eb-4986-b7bb-4ed9035bface",
"fields": "<FIELDS_AS_DATA_INPUT_FOR_PRICING_SCRIPT>",
"pricing": "<EXECUTION_RESULT_OF_PRICING_SCRIPT>",
"product": {
"productId": {
"type": "Demo Insurance",
"plan": "Plan 2",
"version": "1"
},
"representation": "<PRODUCT_REPRESENTATION_CREATED_BY_PRODUCT_BUILDER>"
}
}
]
}
]
}
]
}
}
}
The case.proposal.basket.pricing
field is the execution result of script
with dataInput
defined in the offer.fields
and product.represenation
.
Generating the Policy
The client feels good towards our proposal and would like to proceed to purchasing the two products we offered. Policies can then be created.
Generate policies from proposal
mutation generatePoliciesFromProposal (
$caseId: String!,
$proposalId: String!
){
generatePoliciesFromProposal(
caseId: $caseId
proposalId: $proposalId
){
status
createdStatus { id }
errors
}
}
input:
{
"caseId": "3e456424-daa4-4f32-ab9b-a303c8af98bd",
"proposalId": "1049d48c-bd35-4170-9d68-ca14160e29a9"
}
Querying the policies
query policies{
policies {
totalCount
list{
id
fields
pricing
}
}
}
result:
{
"data": {
"policies": {
"totalCount": 2,
"list": [
{
"id": "c272848e-8f12-475b-895b-2730f91b4916",
"fields": "<FIELDS_AS_DATA_INPUT_FOR_PRICING_SCRIPT>",
"pricing": "<EXECUTION_RESULT_OF_PRICING_SCRIPT>"
},
{
"id": "5306e748-010a-434a-9c89-5f1b17ae8667",
"fields": "<FIELDS_AS_DATA_INPUT_FOR_PRICING_SCRIPT>",
"pricing": "<EXECUTION_RESULT_OF_PRICING_SCRIPT>"
}
]
}
}
}
Policy and product have one-to-one relationship. Since we are offering two product in the proposal, two policies are generated. Same as offer
, CoverGo's backend executed the script
using policy.fields
as the dataInput
, and the result of execution is presented in policy.pricing
.