cimplify

Element Events

Elements communicate via postMessage between your page and link.cimplify.io iframes. The React SDK wraps these into typed callback props.

React SDK callbacks
// Unified checkout element (recommended)
<CimplifyCheckout
  onStatusChange={(status, context) => console.log(status, context.display_text)}
  onComplete={(result) => console.log(result.order?.id)}
  onError={(error) => console.error(error.code, error.message)}
/>

// Standalone auth element
<AuthElement
  onReady={() => console.log("auth ready")}
  onAuthenticated={(data) => console.log(data.token)}
  onRequiresOtp={(data) => console.log(data.contactMasked)}
  onError={(error) => console.error(error.code, error.message)}
/>

Core element events

EventElementsPayload
readycheckout, auth, address, payment{ height }
authenticatedcheckout, auth{ accountId, customerId, token, customer }
requires_otpcheckout, auth{ contactMasked }
order_type_changedcheckout{ orderType }
contact_providedcheckout{ contact, contactType }
address_selectedcheckout{ address }
changeaddress, payment{ address, saveToLink } or { paymentMethod, saveToLink }
checkout_statuscheckout{ status, context }
checkout_completecheckout{ success, order?, error?, enrolled_in_link? }
request_submitcheckout{}
errorall{ code, message }

Checkout status values

The checkout_status event fires at each state transition. See Checkout Lifecycle for the full state machine.

TS
// Status values:
// "preparing" | "recovering" | "processing" | "awaiting_authorization"
// | "polling" | "finalizing" | "success" | "failed"

PostMessage protocol

Parent to iframe

MessagePurpose
INITInitialize element with config
SET_TOKENPass access token to iframe (skipped for unified checkout)
SET_CARTSend cart data (line items, totals, tax) for inline order summary
GET_DATARequest current element data
PROCESS_CHECKOUTTrigger checkout from checkout/payment element
ABORT_CHECKOUTCancel in-progress checkout
REFRESH_TOKENRequest token refresh from element
LOGOUTLog out user from element

Iframe to parent

MessagePurpose
READYElement loaded and ready
HEIGHT_CHANGEAuto-resize iframe height
AUTHENTICATEDAuth completed with token (from checkout or auth element)
TOKEN_REFRESHEDAccess token was refreshed
REQUIRES_OTPOTP/PIN entry needed (from checkout or auth element)
ORDER_TYPE_CHANGEDUser changed order type in checkout element
CONTACT_PROVIDEDUser provided email or phone in checkout element
ADDRESS_CHANGEDAddress input updated
ADDRESS_SELECTEDSaved address selected
PAYMENT_METHOD_SELECTEDPayment method chosen
CHECKOUT_STATUSCheckout state machine transition
CHECKOUT_COMPLETECheckout reached terminal state
REQUEST_SUBMITCheckout element's built-in submit button was pressed
ERRORError occurred in element
LOGOUT_COMPLETEUser logged out from element

React callback mapping

PostMessageReact PropComponents
READYonReadyAuthElement
AUTHENTICATEDonAuthenticatedAuthElement
REQUIRES_OTPonRequiresOtpAuthElement
ERRORonErrorAuthElement, CimplifyCheckout
ADDRESS_CHANGED / PAYMENT_METHOD_SELECTEDonChangeAddressElement, PaymentElement
CHECKOUT_STATUSonStatusChangeCimplifyCheckout
CHECKOUT_COMPLETEonCompleteCimplifyCheckout
REQUEST_SUBMIT(handled internally)CimplifyCheckout triggers processCheckout() automatically

Checkout lifecycle events

TYPESCRIPT
const result = await elements.processCheckout({
  cart_id: "cart_123",
  order_type: "delivery",
  on_status_change: (status, context) => {
    // status: "preparing" | "recovering" | "processing"
    //       | "awaiting_authorization" | "polling" | "finalizing"
    //       | "success" | "failed"
    console.log(status, context);
  },
});

// result: { success, order?, error?, enrolled_in_link? }

Security

The SDK validates message origins and only accepts events from *.cimplify.io and localhost (in dev). This isolates sensitive auth/payment UI from merchant-page scripts.

Use SDK callbacks instead of raw postMessage listeners. The SDK handles origin validation and type safety automatically.

Related