Last Updated: 22 January 2024 | Change Log

Create sessionState

Create a sessionState by sending your customer's card details.


A sessionState is a unique identifier for your customer's card details, generated by the SDK.

Create an AccessCheckoutClient instance

The AccessCheckoutDiscovery component provides the entry point to our SDK, it also provides the single discover() function. This function may be called anywhere in your application lifecycle.

let accessCheckoutDiscovery = AccessCheckoutDiscovery(baseUrl: <ACCESS_CHECKOUT_BASE_URL>) URLSession.shared) {
      self.accessCheckoutClient = AccessCheckoutClient(discovery: accessCheckoutDiscovery,
                                                        merchantIdentifier: <MERCHANT_ID>)
  • For testing use :
  • For live use :
<MERCHANT_ID>Your unique merchant ID.

Ensure the Access Checkout URL has been added to your App's Transport Security Settings.

  • For testing use :
  • For live use :

Implement CardDelegate

Implementing your ViewController with our CardDelegate notifies you of the validity of your customer's card details.

Here is an example of how you would implement your MyViewController with our CardDelegate class.

extension ViewController: CardDelegate {

Inside the implementation above, you can set the behavior of your form based on the result of the validation.

In the example below, when the details that your customers has entered in the views are valid, the submit button becomes enabled. The example also uses the rules to determine the brand of your customer's card, which can be used to update a UI component.

  func cardView(_ cardView: CardView, isValid valid: Bool) {
      // Update your UI with the validation result
      cardView.isValid(valid: valid)
      // Check for card validity to enable submission
      if let valid = card?.isValid() {
          submitButton.isEnabled = valid

  func didChangeCardBrand(_ cardBrand: CardConfiguration.CardBrand?) {
      // Update any card brand on the panView
      if let imageUrl = cardBrand?.imageUrl {
          // Load the brand image here...
      } else {
          // Clear brand image here...

The validation rules and both SVG and PNG versions of your customer's card band icons are stored in the same JSON file.

Submitting Form and getting sessionState

When your customer's card details are valid, and they select the submit button, you must invoke the func submit() function. Invoking this function sends your customer's card details and potentially respond with a sessionState.

func submitCard(pan: PAN, month: ExpiryMonth, year: ExpiryYear, cvv: CVV) {

  accessCheckoutClient?.createSession(pan: pan,
                                      expiryMonth: expiryMonth,
                                      expiryYear: expiryYear,
                                      cvv: cvv) { result in
                                          DispatchQueue.main.async {
                                              switch result {
                                              case .success(let session):
                                                  // Session is returned here
                                              case .failure(let error):
                                                  // Error handling
                                                  if let accessCheckoutClientError = error as? AccessCheckoutClientError {
                                                      switch accessCheckoutClientError {
                                                      case .bodyDoesNotMatchSchema(_, let validationErrors):
                                                          // Handle validation errors
                                                  } else {
                                                      // handle other errors

The function above sends your customer's card number(pan), card expiry month and year and card cvv.

The function then perform another validation check on your customer's card details, as well as checking your <MERCHANT_ID> and any other provided information.

If there is an error, our SDK returns an error containing the errorName, message and a validationErrors, detailing the reason an error was returned.

If successful a sessionState is returned instead, you must use the sessionState to create a verified token.

Create a Verified token

Once you've received a sessionState you must create a verified token to take a payment.

Next steps

Verified token