> ## Documentation Index
> Fetch the complete documentation index at: https://primer.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Handle payment result

> Navigate to a confirmation screen after payment completion

Use the `onCompletion` callback to react when a payment succeeds, fails, or the checkout is dismissed.

## Basic usage

```swift theme={"dark"}
struct CheckoutView: View {
  let clientToken: String
  @State private var paymentCompleted = false
  @State private var paymentResult: PaymentResult?

  var body: some View {
    if paymentCompleted, let result = paymentResult {
      ConfirmationView(result: result)
    } else {
      PrimerCheckout(
        clientToken: clientToken,
        onCompletion: { state in
          switch state {
          case .success(let result):
            paymentResult = result
            paymentCompleted = true
          case .failure(let error):
            // Error is displayed in the checkout UI
            print("Payment failed: \(error.errorId)")
          case .dismissed:
            // User dismissed the checkout
            break
          default:
            break
          }
        }
      )
    }
  }
}
```

## With NavigationStack

```swift theme={"dark"}
struct CheckoutView: View {
  let clientToken: String
  @State private var path = NavigationPath()

  var body: some View {
    NavigationStack(path: $path) {
      PrimerCheckout(
        clientToken: clientToken,
        onCompletion: { state in
          if case .success(let result) = state {
            path.append(result)
          }
        }
      )
      .navigationDestination(for: PaymentResult.self) { result in
        ConfirmationView(result: result)
      }
    }
  }
}
```

## See also

<CardGroup cols={2}>
  <Card title="Show success message" icon="check" href="/checkout/primer-checkout/guides-and-recipes/show-success-message">
    Display a custom success UI
  </Card>

  <Card title="SwiftUI navigation" icon="arrow-right" href="/sdk/ios-checkout/v3.0.0-beta/integration-patterns/swiftui-navigation">
    Navigation patterns for checkout
  </Card>
</CardGroup>
