**Last updated**: 30 October 2025 | [**Change log**](/products/checkout/ios/changelog/) # Create a session to pay with a card Enterprise SMB (Worldpay eCommerce) Use our iOS SDK to secure your customer's card details within the UI components by creating a session. Full sample integration You can see an example of the session generation [here](https://github.com/Worldpay/access-checkout-ios/tree/master/AccessCheckoutDemo). ## Reference your UI components To display your checkout form, you must create your layout first using your storyboard. As part of our SDK, we provide a UI component dedicated to capturing your customer's card details to minimize your exposure to PCI data. You must use this component if you want to qualify for the lowest level of PCI compliance (SAQ-A). Here's an example of how you would reference your a UI component using unique identifiers. ```swift import AccessCheckoutSDK class ViewController: UIViewController { @IBOutlet weak var panAccessCheckoutView: AccessCheckoutUITextField! @IBOutlet weak var expiryDateAccessCheckoutView: AccessCheckoutUITextField! @IBOutlet weak var cvcAccessCheckoutView: AccessCheckoutUITextField! func submitButtonClickHandler() { // code to generate your session ... } ... ``` ## Validate card details You can optionally validate your customer's card details. You can find instructions [here](/products/checkout/ios/v3/card-validator). ## Create a session ### Initialize the AccessCheckoutClient You must now initialize the SDK using the `AccessCheckoutClientBuilder`. To do this, you must provide your `BaseURL`, `checkoutId` and other parameters. See the table below for more information. Here's an example of how you would initialize the SDK with the mandatory parameters. ```swift // The AccessCheckoutClientBuilder throws an error if either the accessBaseUrl() or checkoutId() calls are omitted let accessCheckoutClient:AccessCheckoutClient? = try? AccessCheckoutClientBuilder().accessBaseUrl() .checkoutId() .build() ``` | Placeholder | Descriptions | | --- | --- | | `` | For testing use: `https://try.access.worldpay.com/`For live use: `https://access.worldpay.com/` | | `` | Your unique checkout ID as provided by Worldpay. | ## Retrieve the session ### Submitting your customer's card details The SDK extracts your customers card details from the UI Component, the card details are then submitted to retrieve a `session`. ```swift // The CardDetailsBuilder throws an error if the expiry date is provided in a format different from MM/YY or MMYY (which will not happen if you use the components with built-in validation provided by the SDK) let cardDetails:CardDetails = try! CardDetailsBuilder().pan(panAccessCheckoutView) .expiryDate(expiryDateAccessCheckoutView) .cvc(cvcAccessCheckoutView) .build() ``` ### Specifying the session You must specify `[SessionType.card]` as the type of `session` to generate. ```swift try? accessCheckoutClient?.generateSessions(cardDetails: cardDetails, sessionTypes: [SessionType.card]) { result in DispatchQueue.main.async { switch result { case .success(let sessions): // The session is returned in a Dictionary[SessionType:String] let session = sessions[SessionType.card] ... case .failure(let error): // The error returned is of type AccessCheckoutError let errorMessage = error.message ... } } } ``` Note - The call to `generateSessions` takes a closure that returns a `Result<[SessionType: String], AccessCheckoutError>`. - You must use the pattern of the main thread in the closure when handling the success/failure would lead to updating the UI. ### Full code sample Here's the full code sample of the steps above. import AccessCheckoutSDK class MyViewController: UIViewController { private let accessBaseUrl = "https://try.access.worldpay.com" private let checkoutId = "your-checkout-id" @IBOutlet weak var panAccessCheckoutView: AccessCheckoutUITextField! @IBOutlet weak var expiryDateAccessCheckoutView: AccessCheckoutUITextField! @IBOutlet weak var cvcAccessCheckoutView: AccessCheckoutUITextField! @IBAction func submit(_ sender: Any) { let cardDetails = try! CardDetailsBuilder().pan(panAccessCheckoutView) .expiryDate(expiryDateAccessCheckoutView) .cvc(cvcAccessCheckoutView) .build() let accessCheckoutClient = try? AccessCheckoutClientBuilder().accessBaseUrl(accessBaseUrl) .checkoutId(checkoutId) .build() try? accessCheckoutClient?.generateSessions(cardDetails: cardDetails, sessionTypes: [SessionType.card]) { result in DispatchQueue.main.async { switch result { case .success(let sessionsDictionary): let session = sessionsDictionary[SessionType.card] ... case .failure(let error): ... } } } } } Caution Do **not** validate the structure or length of the session resources. We follow HATEOS standard to allow us the flexibility to extend our APIs with non-breaking changes. Important The CARD `session` has a lifespan of **one minute** and you can use it **only once**. If you do not create a token within that time, you must create a new CARD `session` value. ### Next steps Using the Payments API Apply the session in the payment request Enterprise SMB (Worldpay eCommerce) Using our Modular APIs Create a verified token Enterprise