Skip to main content

Checkout

The Embedded Checkout allows users to onboard with autopay or make a one-time payment.

Initialization​

Configure the Embedded Checkout by calling sdk.checkout(config) with a CheckoutConfig object.

Swift
import FlexCheckout

sdk.checkout(CheckoutConfig(
onClose: { },
onError: { error in },
onEvent: { event in },
onOpen: { }
))

When opened, the Embedded Checkout guides the user through onboarding and payment.
The interstitial introduces the Flex offer before the user proceeds to the full flow, ending on a confirmation screen.

9:41
Checkout interstitial
9:41
Checkout approved

Options​

Options for configuring and listening to events from the Embedded Checkout.

ParameterTypeDescription
interstitialBoolWhether to show or hide the interstitial screen. Defaults to true.
onClose() -> VoidCalled when the Embedded Checkout is closed.
onError(String) -> VoidCalled when an error occurs. Returns a String with the error message.
onEvent(ModalEvent) -> VoidEvents in the Flex app will trigger onEvent to be called. Returns a ModalEvent with a type field indicating which event has been triggered.
onOpen() -> VoidCalled when the Embedded Checkout is opened.

Event Types​

The onEvent callback receives a ModalEvent object with a type field and an optional data field.

Event TypeDescription
.onboardingCompletedUser has completed onboarding.
Check event.data.autopayEnabled for autopay status.
.paymentCompletedUser has completed payment.
.onboardingCompleted will have been sent first.
.autopayStatusUpdatedUser has updated their autopay status.
Check event.data.autopayEnabled for new status.
Swift
sdk.checkout(CheckoutConfig(
onEvent: { event in
switch event.type {
case .onboardingCompleted:
// User has completed onboarding.
// event.data.autopayEnabled indicates if autopay was enabled.
break
case .paymentCompleted:
// User has completed payment.
break
case .autopayStatusUpdated:
// User has updated their autopay status.
// event.data.autopayEnabled indicates the new status.
break
}
}
))

Error Handling​

If the checkout fails to load — network unavailable, app.getflex.com unreachable, or the JS handshake doesn't complete within 15 seconds — the SDK displays a recoverable error screen inside the sheet so the partner does not need to dismiss it.

  • First failure: "Something went wrong — Please try again" with a Try Again button that retries the load.
  • Retry also fails: terminal "We're experiencing technical issues" screen (no retry button).
  • A Help link in both states opens help.getflex.com in the user's browser.
  • The user can dismiss the sheet at any time via the close X.

Your onError callback is also invoked on every failure with a descriptive message:

Swift
sdk.checkout(CheckoutConfig(
onError: { error in
// error is a String like:
// "Checkout failed to load: The Internet connection appears to be offline."
// "Checkout failed to load: Checkout did not load in time"
// "Checkout failed to load: Failed to load token: ..."
log(error)
}
))

You don't need to take any UI action on onError — the SDK already shows the user-facing error UI. Use the callback for logging, analytics, or your own diagnostics.


Methods​

closeCheckout()​

Programmatically closes the Embedded Checkout.

Swift
sdk.closeCheckout()