Skip to main content

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.

PrimerSettings controls how Primer Checkout processes payments and displays the UI. Pass it to PrimerCheckout to customize behavior.

Basic usage

let settings = PrimerSettings(
  paymentHandling: .auto
)

PrimerCheckout(
  clientToken: clientToken,
  primerSettings: settings
)

PrimerSettings

PrimerSettings(
  paymentHandling: PrimerPaymentHandling = .auto,
  uiOptions: PrimerUIOptions? = nil,
  paymentMethodOptions: PrimerPaymentMethodOptions? = nil
)

Parameters

ParameterTypeDefaultDescription
paymentHandlingPrimerPaymentHandling.autoControls whether Primer handles the full payment flow or returns a token for server-side processing
uiOptionsPrimerUIOptions?nilUI display preferences
paymentMethodOptionsPrimerPaymentMethodOptions?nilPayment method-specific configuration

Payment handling

ValueDescription
.autoPrimer handles the complete payment flow including tokenization and payment creation. This is the recommended approach.
.manualPrimer returns a payment method token. You handle payment creation on your server.
let settings = PrimerSettings(paymentHandling: .auto)

PrimerCheckout(
  clientToken: clientToken,
  primerSettings: settings,
  onCompletion: { state in
    switch state {
    case .success(let result):
      print("Payment complete: \(result.payment?.id ?? "")")
    case .failure(let error):
      print("Payment failed: \(error.errorId)")
    default:
      break
    }
  }
)

Manual

let settings = PrimerSettings(paymentHandling: .manual)

PrimerCheckout(
  clientToken: clientToken,
  primerSettings: settings,
  onCompletion: { state in
    switch state {
    case .success(let result):
      // Send token to your server for payment creation
      if let token = result.paymentMethodData?.token {
        createPaymentOnServer(token: token)
      }
    default:
      break
    }
  }
)

Define settings as constants

Define your settings outside the view body to avoid unnecessary re-creation on each SwiftUI render cycle.
// Define once at the top level
private let primerSettings = PrimerSettings(
  paymentHandling: .auto
)

struct CheckoutView: View {
  let clientToken: String

  var body: some View {
    PrimerCheckout(
      clientToken: clientToken,
      primerSettings: primerSettings
    )
  }
}

See also

State and events

Handle checkout lifecycle states

Best practices

Recommended patterns for configuration

Common objects

PrimerSettings API reference