Events & Purchase Flow
Complete event contract for the Checkout Widget and the end-to-end purchase flow that partner backends must implement.
The widget communicates with the partner's page via Custom Events dispatched on document. This page documents the full event contract and the backend purchase flow partners must implement.
Event Contract
All events are standard CustomEvent instances dispatched on document with a detail payload.
| Event | When | Payload |
|---|---|---|
weatherit:coverage-selected | Customer selects a protection tier | quoteId, optionName, premium, totalCoverage, nights, dailyRate |
weatherit:coverage-changed | Customer switches tier | Same shape as coverage-selected |
weatherit:coverage-declined | Customer selects "No Protection" | quoteId |
weatherit:quote-loaded | Quote API returned successfully | quoteId, options, location, dates |
weatherit:widget-error | Widget encountered an error | error (string), code (string) |
Design notes:
- There is no
coverage-removedevent. The customer always has an active selection — either a protection tier or "No Protection". - There is no
payment-completeevent. The widget does not handle payment.
Listening for Events
document.addEventListener('weatherit:coverage-selected', (e) => {
const { quoteId, optionName, premium } = e.detail;
// Store quoteId against the booking for later purchase
});
document.addEventListener('weatherit:coverage-declined', (e) => {
const { quoteId } = e.detail;
// Remove any stored quoteId for this booking
});Partner Purchase Flow
The widget handles quoting and selection only. After the customer completes the partner's checkout, the partner's backend activates the policy.
sequenceDiagram
participant Customer
participant PartnerFrontend as Partner Frontend
participant PartnerBackend as Partner Backend
participant Widget as WeatherIt Widget
participant API as WeatherIt API
participant Stripe as Stripe Connect
Widget->>Customer: Display protection options
Customer->>Widget: Selects protection tier
Widget->>PartnerFrontend: weatherit:coverage-selected event
PartnerFrontend->>PartnerBackend: Store quoteId with booking
Note over Customer,Stripe: Customer completes partner checkout
PartnerBackend->>Stripe: Charge total (booking + premium split)
Stripe-->>PartnerBackend: transaction_id
PartnerBackend->>API: POST /quotes/quoteId/purchase
API-->>PartnerBackend: policyId, status active
PartnerBackend->>PartnerBackend: Store policyId
Note over Customer,API: Customer views confirmation page
Customer->>PartnerFrontend: Loads confirmation page
PartnerFrontend->>Customer: Renders weatherit-confirmation with policy-id
Step-by-Step
-
During checkout — Your frontend listens for the
weatherit:coverage-selectedevent and stores thequoteIdagainst the booking. -
On
weatherit:coverage-declined— Remove any storedquoteIdfor the booking. No further action needed. -
After checkout completes — If a
quoteIdis stored for the booking, your backend calls:POST /quotes/{quoteId}/purchaseWith the Stripe transaction ID and customer details. See the Purchase API reference for the full request/response shape.
-
Policy activated — The purchase API returns a
policyId. Store this for the confirmation page. -
Confirmation page — Pass the
policyIdto the confirmation widget:<weatherit-confirmation partner="{WEATHERIT_PARTNER_ID}" booking="{booking.reference}" policy-id="{policyId}" ></weatherit-confirmation>
Confirmation Widget Data Flow
The confirmation component operates independently on a separate page. It has no shared state with the checkout widgets.
Recommended approach: Pass policy-id and quote-id attributes from your booking flow. This gives the component the data it needs without additional API calls.
| Attributes passed | Component behaviour |
|---|---|
policy-id | Shows policy confirmation (or hides if hide-on-confirmed set) |
quote-id (no policy-id) | Shows upsell card with premium and "Add now" link |
| Neither | Shows generic offer with link to WeatherIt |
Booking-ref lookup — A future release will allow the confirmation widget to look up policies by booking reference alone. Currently, partners should passpolicy-idand/orquote-idexplicitly.
Related
Updated 7 months ago
