Skip to main content

A Simple Implementation

You can implement the Vertical Insure insurance purchase flow into your platform in a few easy steps.

Add the web component to your checkout page

The details for installing our web component can be found in the Web Component Installation & Usage Guide, but our web component can be instantiated with simple HTML. You can do this step with either server-side or client-side rendering.

<season-interruption
client-id="{{VI_CLIENT_ID}}"
event-start-date="{{event_start_date}}"
event-end-date="{{event_end_date}}"
customer-first-name="{{customer.first_name}}"
customer-last-name="{{customer.last_name}}"
customer-email-address="{{customer.email_address}}"
customer-state="{{customer.state}}"
customer-street-address="{{customer.street_address"}}"
customer-city="{{customer.city}}"
customer-postal-code="{{customer.postal_code}}"
insurable-amount="{{event_cost_in_cents}}"
participant-first-name="{{participant.first_name}}"
participant-last-name="{{participant.last_name}}"
>
</season-interruption>

Validate and retrieve insurance quote details

When you a customer is ready to complete checkout, you can simply reference the component in your javascript.

<script type="text/javascript">
async function completeCheckout(e) {
const insuranceComponent = document.querySelector('season-interruption');
const quote = insuranceComponent.quote;
const validationStatus = await insuranceComponent.validate();

if (validationStatus.isValid) {
const quoteId = quote.quote_id;
const insuranceAmount = quote.total;

/*
send quote id and insuranceAmount along with your other order-related details to
backend via API call or FormData
*/
const orderDetails = { ... }
const insuranceDetails = {
amount: insuranceAmount,
quoteId: quoteId
}
}
}
</script>

Call our Purchase Endpoint from your Backend

Once a customer has submitted the checkout page, you can reference the quote information in your backend call where you would handle the checkout process.

import requests
import json
import os
import base64
import stripe

stripe.api_key = os.environ['STRIPE_API_KEY']

def complete_checkout(orderDetails, insuranceDetails):

# Create a payment intent for the registration, event, etc...
order_payment_intent = stripe.PaymentIntent.create(
amount=orderDetails.amount,
currency="usd",
automatic_payment_methods={"enabled": True},
)

# Create a second payment intent for the insurance
insurance_payment_intent = stripe.PaymentIntent.create(
amount=insuranceDetails.amount,
currency="usd",
automatic_payment_methods={"enabled": True},
stripe_account=os.environ['VERTICAL_INSURE_STRIPE_ACCOUNT_ID']
)

# Post to the Vertical Insure purchase endpoint
url = "https://api.verticalinsure.com/v1/purchase/season-interruption"

payload = json.dumps({
"quote_id": insuranceDetails.quoteId,
"payment_method": {
"token": "stripe:" + insurance_payment_intent.id,
}
})

headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': base64.b64encode(os.environ['VERTICAL_INSURE_CLIENT_ID'] + ':' + os.environ['VERTICAL_INSURE_CLIENT_SECRET'])
}

response = requests.request("POST", url, headers=headers, data=payload)