Skip to main content

iOS SDK

The iOS SDK is the native counterpart of the web Headless Checkout and the sibling of the Android SDK: the same concepts (client session, payment methods, primary and secondary methods, split, submit) in Swift. You build the checkout screen; the SDK exposes the session's payment methods as observable state, renders each method's own step (a secure card form, Apple Pay's sheet, Klarna's widget, a PSP page) and drives the payment to its outcome.

How it works​

Key characteristics​

AspectDetail
Integration@Published properties on an ObservableObject for methods, tokens, amounts and session state; one type, PaymentElement, renders any method
UI controlYou build the whole checkout screen; the SDK renders only each method's own step
Payment methodsCard (Purse vault), Apple Pay, PayPal, Klarna, every redirection method the session offers, gift cards, saved cards and saved PayPal accounts, BNPL instalment simulation
ComplianceCard data is captured by the embedded iOS Secure Fields and never reaches your code
DistributionSwift Package Manager: one library product plus one optional product per partner SDK
Web paritySame session, same /init and /validate contract, same error codes and method states as the web SDK

Products​

ProductContentsAdd it when
PurseHeadlessCheckoutEngine, payment elements, card and redirection methods, gift cards, saved methodsAlways
PurseCheckoutApplePayApple Pay plugin and PassKitYou offer Apple Pay
PurseCheckoutKlarnaKlarna plugin and the Klarna Mobile SDKYou offer Klarna
PurseCheckoutPayPalPayPal plugin and the PayPal iOS SDKYou offer PayPal

A merchant offering cards only links none of the partner SDKs, embeds no PassKit and declares no Apple Pay entitlement. The four products release together and share one version number.

Partner products are installed explicitly

Unlike Android, where a partner artifact registers itself from the classpath, iOS has no ServiceLoader. Each partner product you link must be installed once at startup:

PluginRegistry.shared.install(ApplePayModule(configuration: applePayConfiguration))
PluginRegistry.shared.install(PayPalModule())
PluginRegistry.shared.install(KlarnaModule())

Apple Pay's merchant identifier is bound to your app's entitlement, so it can only come from your app. What each partner needs from your project is on its own page under Payment methods.

Requirements​

RequirementValue
Minimum iOS16.0
Swift6.0. The package builds in Swift 6 language mode with strict concurrency
Xcode16+
UISwiftUI or UIKit. Each payment element is a UIView, wrapped for SwiftUI by PaymentElementView
Client sessionCreated by your backend with the Purse API; the app receives its widget.data string

PurseHeadlessCheckout is annotated @MainActor: create it, read its state and call it from the main actor. Every network call it makes is async and runs off the main thread by construction.

When to use this SDK​

ScenarioRecommendation
Native iOS checkout with your own design✅ iOS SDK
Native Android checkout with your own designAndroid SDK
Web checkout with your own designHeadless Checkout (web)
Collect card data only and pay server-sideiOS Secure Fields
Fastest integration, standard checkoutDrop-in Checkout in a web view, or Hosted Page

What you build vs. what the SDK handles​

  • Decoding the client session and listing what it offers
  • Each method's own step: secure card form, Apple Pay sheet, PayPal browser switch, Klarna widget, PSP page
  • /init and /validate calls, 3-D Secure and redirect returns
  • Amount split between a primary method and gift cards
  • Saved cards and accounts, wallet management, BNPL simulation
  • Refusing a double submit, an expired or an already paid session
  • Snapshot and restore across process death (saveState() / restore(_:))

Differences from the Android SDK​

The two native SDKs are deliberately the same shape. Where they differ, it is because the platform forced it:

TopicAndroidiOS
Partner discoveryServiceLoader finds an artifact on the classpathPluginRegistry.install(_:), called by your app
WalletGoogle PayApple Pay, configured from the session and your merchant identifier
Reactive stateStateFlow@Published on an ObservableObject
RenderingOne composable, rememberPaymentElementPaymentElement, wrapped by PaymentElementView for SwiftUI
ThemingCSS-like strings parsed into valuesNative UIColor, UIFont and CGFloat

The full list, including every deliberate divergence and its reason, is kept in the SDK repository's own web ↔ Android ↔ iOS map.

How this documentation is organized​

Like the other Purse SDKs, this section follows the Diátaxis framework: each page is one of four kinds, and never mixes them.

KindRead it toPages
TutorialLearn by doingGetting started: a card payment in sandbox from an empty project
How-to guidesSolve one taskPayment methods, one guide per method · Advanced guides · Error handling · Run the sample app
ReferenceLook something upSDK reference · Error codes · Method states · Supported payment methods · Changelog
ExplanationUnderstand the modelThis page · Key concepts

Known limitations​

  • Purse 3-D Secure is not supported yet. Card payments are authenticated only by the PSP's own 3-D Secure, which the SDK presents as a redirection. 3-D Secure run by Purse, as the Web SDK does with threeDSChallenge, has no equivalent in this SDK.

Next steps​