CheckoutComponents
Last updated: April 16, 2025
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`6addressConfiguration: addressConfiguration),7.applePay(merchantIdentifier: "YOUR_MERCHANT_ID_HERE")8])9)1011// Create a specific payment method12try checkoutComponentsSDK.create(13.card(showPayButton: true,14paymentButtonAction: .payment,15addressConfiguration: addressConfiguration)16)
// Initialize a sessionless component that doesn't 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)