Menu

Create sessionState

SDK v1

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

sessionState

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.

Copied!
let accessCheckoutDiscovery = AccessCheckoutDiscovery(baseUrl: <ACCESS_CHECKOUT_BASE_URL>)
accessCheckoutDiscovery.discover(urlSession: URLSession.shared) {
      self.accessCheckoutClient = AccessCheckoutClient(discovery: accessCheckoutDiscovery,
                                                        merchantIdentifier: <MERCHANT_ID>)
  }
MethodsDescriptions
<ACCESS_CHECKOUT_BASE_URL>
  • For testing use : https://try.access.worldpay.com/
  • For live use : https://access.worldpay.com/
<MERCHANT_ID>Your unique merchant ID.

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

  • For testing use : https://try.access.worldpay.com/
  • For live use : https://access.worldpay.com/

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.

Copied!
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.

Copied!
...
  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 sameJSON 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.

Copied!
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
                                                      default:
                                                          break
                                                      }
                                                  } 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 averified token.

Create a Verified token

Once you've received a sessionState you must create averified tokentotake a payment.


Next steps


Verified token