PrimerCheckoutState value:
| Case | Associated value | Meaning |
|---|---|---|
.success | PaymentResult | The payment completed. |
.failure | PrimerError | The payment or checkout failed. |
.dismissed | — | The user closed the checkout without completing a payment. |
The same
PrimerCheckoutState also has lifecycle cases (.initializing, .ready) that you do not need to handle when reacting to the final outcome. Always include a default case when switching, so future enum additions stay source-compatible.SwiftUI
Using PrimerCheckout
The prebuiltPrimerCheckout view accepts an onCompletion closure that fires once with the final state.
Using the .primerCheckoutSession modifier
When you embed the composable views (for examplePrimerCardForm) inline in your own layout, hold a PrimerCheckoutSession as a @StateObject and receive the outcome through the onCompletion parameter of the .primerCheckoutSession(_:onCompletion:) modifier.
onCompletion is delivered exactly once. The session latches the first terminal state, so any later .dismissed produced by a view-lifecycle teardown is ignored.Navigating on success
Use thePaymentResult to drive navigation. PaymentResult is Equatable but not Hashable, so it cannot be appended to a NavigationPath or used with navigationDestination(for:) directly. Instead, store the result in @State and present the confirmation screen with navigationDestination(isPresented:).
UIKit
In UIKit, present the checkout withPrimerCheckoutPresenter and adopt PrimerCheckoutPresenterDelegate to receive the outcome. The presenter dismisses its own modal before calling the relevant delegate method.
PrimerCheckoutState cases:
| Delegate method | Equivalent state |
|---|---|
primerCheckoutPresenterDidCompleteWithSuccess(_:) | .success(PaymentResult) |
primerCheckoutPresenterDidFailWithError(_:) | .failure(PrimerError) |
primerCheckoutPresenterDidDismiss() | .dismissed |
Reading the PaymentResult
On success you receive aPaymentResult. Read its properties to build your confirmation UI, send analytics, or reconcile against your backend.
| Property | Type | Description |
|---|---|---|
paymentId | String | The Primer payment ID. |
status | PaymentStatus | The payment status: .pending, .success, or .failed. |
token | String? | The payment method token, when available. |
redirectUrl | String? | A redirect URL, when the flow requires one. |
errorMessage | String? | A human-readable error message, when present. |
amount | Int? | The amount in minor units (for example, cents for USD). |
currencyCode | String? | The ISO 4217 currency code (for example, "USD"). |
paymentMethodType | String? | The payment method type used (for example, "PAYMENT_CARD"). |
status is usually .success for a .success(PaymentResult) outcome. In manual payment handling, the payment may still be .pending until your backend confirms it.Handling the PrimerError
On failure you receive aPrimerError. The SDK already surfaces failures inside the checkout UI, so you typically use the error for logging, analytics, and support workflows rather than for displaying a message yourself.
| Property | Type | Description |
|---|---|---|
errorId | String | A stable, machine-readable identifier for the error category. |
diagnosticsId | String | A unique ID for this specific occurrence — include it in support requests. |
errorDescription | String? | A formatted description combining the error ID, message, and diagnostics ID. |
recoverySuggestion | String? | A suggested recovery action, when one is available. |
See also
PrimerCheckoutState
The full state enum and the PaymentResult model.
PrimerError
Error categories, IDs, and diagnostics.
PrimerCheckoutPresenter
The UIKit entry point and delegate callbacks.
PrimerCheckout
The prebuilt SwiftUI checkout view.