Skip to main content
Primer Checkout iOS SDK is currently in beta (v3.0.0-beta.8). The API is subject to change before the stable release.
PrimerCheckoutPresenter is the UIKit entry point for the managed checkout. It presents the CheckoutComponents UI from a UIViewController and delivers results through a delegate, acting as a bridge between UIKit apps and the underlying SwiftUI implementation.
For pure SwiftUI apps, use PrimerCheckout directly instead of this class. PrimerCheckoutPresenter exists for view-controller based navigation. Objective-C code can call dismiss and the two presentCheckout overloads that take no settings. PrimerCheckoutPresenterDelegate is a Swift protocol, so a Swift object must receive the results.

Declaration

The presenter is a @MainActor singleton: call its static methods from the main thread (the default for UIKit lifecycle callbacks). It is also exposed to Objective-C via @objc.

Properties

delegate is a weak reference. Retain the object you assign (for example the presenting view controller) for as long as checkout is on screen, otherwise callbacks will not fire.

Presenting checkout

presentCheckout has five overloads. They differ only in how much you configure and whether you supply the presenting view controller yourself. All overloads accept an optional trailing completion closure that runs once the checkout UI has finished presenting. If the automatic overloads cannot find a presenting view controller, completion does not run. While a previous checkout is still animating in, the call presents nothing and completion runs immediately. A checkout that is already on screen does not stop a new call. Check isPresenting, and do not call presentCheckout while it is true. primerSettings and primerTheme have no Swift defaults; completion and the two Express Checkout shipping handlers default to nil. The overloads that omit settings or theme apply the SDK’s current global PrimerSettings and a default PrimerCheckoutTheme() internally. For the shipping handlers, see Express Checkout shipping.

From an explicit view controller

With automatic view controller detection

These overloads locate the top-most presenting view controller for you, which is convenient when you do not have a view controller reference at hand.
If no presenting view controller can be found, the automatic overloads report a PrimerError through primerCheckoutPresenterDidFailWithError(_:checkoutData:) and do not call completion. Assign the delegate before calling these methods.

Parameters

The overloads that take primerSettings or primerTheme are not @objc compatible because of those Swift-only parameter types. From Objective-C, you can call only presentCheckout(clientToken:completion:), presentCheckout(clientToken:from:completion:) and dismiss(animated:completion:). These two presentCheckout overloads use the SDK’s global PrimerSettings. PrimerCheckoutPresenterDelegate is not exposed to Objective-C, so implement the delegate in Swift.

Dismissing checkout

When a checkout is on screen, dismiss closes it. It then calls primerCheckoutPresenterDidDismiss() on the delegate, unless that checkout already delivered its final result. With no checkout on screen, dismiss does nothing and completion runs immediately. The checkout also closes itself when a payment succeeds. It closes after the success screen finishes, or right away when uiOptions.isSuccessScreenEnabled is false. Then it calls primerCheckoutPresenterDidCompleteWithSuccess(_:). When a payment fails and uiOptions.isErrorScreenEnabled is true (the default), the delegate gets primerCheckoutPresenterDidFailWithError(_:checkoutData:) right away. The sheet stays open on the SDK error screen, so the shopper can retry or choose another payment method where available. When uiOptions.isErrorScreenEnabled is false, the sheet closes on failure. The delegate then gets the failure after the sheet has closed. See PrimerSettings.

Swipe to dismiss

The checkout is shown as a sheet. When uiOptions.dismissalMechanism contains .gestures (the default), the shopper can swipe it away. Without .gestures, the sheet is modal and shows no grabber. The swipe is blocked while a payment is processing, so the sheet stays until the result is known. What the delegate receives for a swipe depends on the screen:

PrimerCheckoutPresenterDelegate

Conform to this protocol to receive checkout results. All three methods are required. A failed 3-D Secure challenge is reported through primerCheckoutPresenterDidFailWithError(_:checkoutData:) like any other failure.

Methods

PaymentResult

The success callback delivers a PaymentResult value.

PaymentStatus

When switching on PaymentStatus, always include a default case so your code stays forward-compatible with future status values.

UIKit usage example

To apply custom settings or theming, use the richer overload:
PrimerCheckoutPresenter.shared.delegate is weak. Keep the conforming object (here, the view controller) alive for the duration of checkout so the callbacks are delivered.

See also

PrimerCheckout

The SwiftUI view for embedding checkout directly in a SwiftUI hierarchy.

PrimerCheckoutState

The state model that drives the managed checkout flow.

PrimerError

The error type delivered to the failure callback.

UIKit integration

A guide to integrating the managed checkout in UIKit apps.