CheckoutComponents
Last updated: September 2, 2026
Initializes a CheckoutComponentConfiguration instance.
1/**2Initializes a new instance of `Configuration`.3- Parameter paymentSession: Payment session details (optional for sessionless components)4- Parameter publicKey: Public key to submit payment session5- Parameter environment: Environment selection to interact with6- Parameter appearance: Design token for the user interface elements7- Parameter locale: Locale to be used by the SDK8- Parameter translations: Custom translation override strings9- Parameter callbacks: Callbacks to handle the component lifecycle10*/11public init(paymentSession: PaymentSession?,12publicKey: String,13environment: Environment,14appearance: DesignTokens = .init(),15locale: String? = nil,16translations: [String: [TranslationKey: String]] = [:],17callbacks: Callbacks) async throws(CheckoutComponents.Error)
Initializes a CheckoutComponent instance.
1// Initialize with a payment session2let configuration = try await CheckoutComponents.Configuration(3paymentSession: paymentSession,4publicKey: "YOUR_PUBLIC_KEY",5environment: .sandbox,6callbacks: initialiseCallbacks())78return CheckoutComponents(configuration: configuration)910// Or initialize for sessionless components (no payment session)11let sessionlessConfiguration = try await CheckoutComponents.Configuration(12paymentSession: nil,13publicKey: "YOUR_PUBLIC_KEY",14environment: .sandbox,15callbacks: initialiseCallbacks())1617return CheckoutComponents(configuration: sessionlessConfiguration)
1func initialiseCallbacks() -> CheckoutComponents.Callbacks {2.init(3onSuccess: { paymentMethod, paymentID in4// Handle payment success5},6onError: { paymentMethod in7// Handle payment error8}9)10}
Initializes an Actionable instance for payment flow.
1// Create a `flow component` with multiple options2try checkoutComponentsSDK.create(3.flow(options: [4.card(showPayButton: true, // show your own pay button when set to false5paymentButtonAction: .payment, // or `.tokenization`6cardConfiguration: cardConfiguration, // Configuration options for customizing the Card component7addressConfiguration: addressConfiguration,8rememberMeConfiguration: rememberMeConfiguration),9.applePay(merchantIdentifier: "YOUR_MERCHANT_ID_HERE",10showPayButton: Bool = true, // show your own pay button when set to false11applePayConfiguration: applePayConfiguration // Configuration options for customizing the ApplePay component12)13])14)1516// Create a specific payment method17try checkoutComponentsSDK.create(18.card(showPayButton: true,19paymentButtonAction: .payment,20cardConfiguration: cardConfiguration,21addressConfiguration: addressConfiguration,22rememberMeConfiguration: rememberMeConfiguration)23)
If the payment session carries a stored_card payment method and Remember Me is not available on that session, create(.flow(...)) returns the stored card component instead of the regular Flow list. You can also render the stored card component on its own:
1// Create a stored card component with configuration options2try checkoutComponentsSDK.create(3.storedCard(4storedCardConfiguration: .init(5showPayButton: true,6captureCVV: true,7displayMode: .all,8acceptedCardSchemes: [.visa, .mastercard],9acceptedCardTypes: [.credit]10),11cardConfiguration: cardConfiguration12)13)
For more information, see Accept payments with stored card credentials.
Tip
If you use Apple Pay as a standalone component with your custom payment button, ensure you follow Apple's guidelines for showing Apple Pay logo.
Initialize a sessionless component that does not require a payment session.
1// Create a sessionless address component2typealias ContactData = CheckoutComponents.ContactData3typealias Address = CheckoutComponents.Address4typealias Configuration = CheckoutComponents.AddressConfiguration56let prefilledAddress = ContactData(address: .init(country: .unitedKingdom,7addressLine1: "Wenlock Works",8addressLine2: "Shepherdess Walk",9city: "London",10zip: "N1 7BQ"),11phone: .init(countryCode: "+$4",12number: "1234567890"),13name: .init(firstName: "John",14lastName: "Doe"))1516let addressConfiguration = Configuration.init(data: prefilledAddress,17fields: CheckoutComponents.AddressField.billing18+ [.phone(isOptional: false)]) { collectedAddress in19debugPrint("Collected address: \(collectedAddress)")20}2122try checkoutComponentsSDK.create(23.address(configuration: addressConfiguration)24)
You can also create a sessionless CVV component to collect a security code for a card you hold on your file-on-card system, with no payment session. The component tokenizes on demand and hands the token back to you, rather than submitting a payment request:
1import CheckoutComponents23// No payment session is needed for a sessionless component.4let sdk = try await CheckoutComponents(configuration: configuration)56let cvv = try sdk.create(.cvv(configuration: .init(cvvLength: [3, 4])))78// Render it9cvv.render()1011// Tokenize when the customer is ready. `isValid` reports whether the entered12// code matches one of the accepted lengths.13guard cvv.isValid else { return }1415switch await cvv.tokenize() {16case .success(let response):17// Send response.token to your backend as the CVV for your own payment request.18print(response.token)19case .failure(let error):20print(error.errorCode)21case .none:22break // Not reachable for the CVV component.23}
CardCVVConfiguration.cvvLength accepts the security code lengths, in digits: [3], [4], or [3, 4]. Pass [3] for most schemes, [4] for American Express, or [3, 4] to accept either. An empty array, or any value other than 3 or 4, falls back to [3, 4].
The field is valid once its length matches one of the accepted values, and it stops accepting characters at the largest accepted value.
Updates a FlowComponent instance.
1if component.isAvailable {2component.render()3}
This method only updates the UI. To update the payment session, use the handleSubmit callback.
The update() method takes the updateDetails object as a parameter, which contains the values to update.
This object uses the amount property to update the purchase amount. This value must be:
- Greater than zero
- Expressed in the minor currency unit
1let callbacks = CheckoutComponents.Callbacks(handleSubmit: { sessionData in2submitPaymentSession(sessionData)3})4let configuration = CheckoutComponents.Configuration(..., callbacks: callbacks)56try checkoutComponentsSDK.update(with: UpdateDetails(amount: 100))