Create sessions to pay with card and CVC

Use our Android SDK to secure your customer's payment details by creating separate sessions for the card details and CVC.

Full sample integration: You can see an example of the session generationhere.

Reference your views

To display your checkout form, you must create your layout first using your storyboard.

Here's an example of how you would reference your views using unique identifiers.

Copied!
import AccessCheckoutSDK
class ViewController: UIViewController {

    @IBOutlet weak var panView: PanView!
    @IBOutlet weak var expiryDateView: ExpiryDateView!
    @IBOutlet weak var cvcView: CvcView!

    func submitButtonClickHandler() {
        // code to generate your sessions
        ...
    }    ...

Card Validation

You can optionally validate your customer's card details. You can find instructionshere

Create a session

Initialize the AccessCheckoutClientBuilder

You must now initialize the SDK using the AccessCheckoutClientBuilder.

To do this, you must provide your BaseURL, merchantID and other parameters.

Here's an example of how you would initialize the SDK with the mandatory parameters.

Copied!
// The AccessCheckoutClientBuilder throws an error if either the accessBaseUrl() or merchantId() calls are omitted 
let accessCheckoutClient:AccessCheckoutClient? = try? AccessCheckoutClientBuilder().accessBaseUrl(<ACCESS_BASE_URL>)
   .merchantId(<MERCHANT_ID>)
   .build()
PlaceholderDescriptions
<ACCESS_BASE_URL>
  • For testing use: https://try.access.worldpay.com/
  • For live use: https://access.worldpay.com/
<MERCHANT_ID>Your unique merchant ID as provided by Worldpay.

Retrieve the session

Submitting your customer's card details

The CardDetails contains the customer's data that is submitted to retrieve the sessions.

Copied!
// 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(panView.text)
    .expiryDate(expiryDateView.text)
    .cvc(cvcView.text)
    .build()

Specifying the sessions

You must specify [SessionType.card] and [SessionType.cvc] as the type of sessions to generate.

Copied!
try? accessCheckoutClient?.generateSessions(cardDetails: cardDetails, sessionTypes: [SessionType.card, SessionType.cvc]) { result in
    DispatchQueue.main.async {
        switch result {
        case .success(let sessions):
            // The session is returned in a Dictionary[SessionType:String]
            let cardSession = sessions[SessionType.card]
            let cvcSession = sessions[SessionType.cvc]
            ...
        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.

Copied!
import AccessCheckoutSDK
class MyViewController: UIViewController {
    private let accessBaseUrl = "https://try.access.worldpay.com"
    private let merchantId = "your-merchant-id"
    @IBOutlet weak var panView: PanView!
    @IBOutlet weak var expiryDateView: ExpiryDateView!
    @IBOutlet weak var cvcView: CvcView!
    @IBAction func submit(_ sender: Any) {
        let cardDetails = try! CardDetailsBuilder().pan(panView.text)
            .expiryDate(expiryDateView.text)
            .cvc(cvcView.text)
            .build()
        let accessCheckoutClient = try? AccessCheckoutClientBuilder().accessBaseUrl(accessBaseUrl)
            .merchantId(merchantId)
            .build()
        try? accessCheckoutClient?.generateSessions(cardDetails: cardDetails, sessionTypes: [SessionType.card, SessionType.cvc]) { result in
            DispatchQueue.main.async {
                switch result {
                    case .success(let sessionsDictionary):
                        let cardSession = sessionsDictionary[SessionType.card]
                        let cvcSession = sessionsDictionary[SessionType.cvc]
                        ...
                    case .failure(let error):
                        ...
                }
            }
        }
    }
}

Create a Verified token

Once you've received the card session you must create averified tokenand use it alongside your cvc session totake a payment.

Take a Payment

Use the value of the cvc session and the verified token in our card/checkout paymentInstrument to take a card on file payment.

Important: The cvc session has a lifespan of 15 minutes. If you do not take a payment within that time, you must create a new cvc session value. You can do this with ourCVC only SDK.

This paymentInstrument can be used in any of our card on file resources (payments:cardonFileAuthorize,payments:migrateCardOnFileSaleandpayments:migrateCardOnFileAuthorize).


Need to create a session for CVC only? Take a look at our integration example below:

Create a session for CVC only

Create a Payments Cvc session by sending your customer's CVC.

Full sample integration: You can see an example of the session generationhere.

Reference your views

To display your checkout form, you must create your layout first using your storyboard.

Here's an example of how you would reference your views using unique identifiers.

Copied!
import AccessCheckoutSDK

class ViewController: UIViewController {

    @IBOutlet weak var cvcView: CvcView!

    func submitButtonClickHandler() {
        // code to generate your session
        ...
    }   
    ...

CVC Validation

You can optionally validate your customer's CVC. You can find instructionshere

Create a session

Initialize the AccessCheckoutClientBuilder

You must now initialize the SDK using the AccessCheckoutClientBuilder.

To do this, you must provide your BaseURL, merchantID and other parameters.

Here's an example of how you would initialize the SDK with the mandatory parameters.

Copied!
// The AccessCheckoutClientBuilder throws an exception if either the accessBaseUrl() or merchantId() calls are omitted 
let accessCheckoutClient:AccessCheckoutClient? = try? AccessCheckoutClientBuilder().accessBaseUrl(<ACCESS_BASE_URL>)
   .merchantId(<MERCHANT_ID>)
   .build()
PlaceholderDescriptions
<ACCESS_BASE_URL>
  • For testing use: https://try.access.worldpay.com/
  • For live use: https://access.worldpay.com/
<MERCHANT_ID>Your unique merchant ID as provided by Worldpay.

Retrieve the session

Submitting your customer's card details

The CardDetails contains the customer's data that is submitted to retrieve a session.

Copied!
// 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().cvc(cvcView.text)
    .build()

Specifying the session

You must specify [SessionType.cvc] as the type of session to generate.

Copied!
try? accessCheckoutClient?.generateSessions(cardDetails: cardDetails, sessionTypes: [SessionType.cvc]) { result in
    DispatchQueue.main.async {
        switch result {
        case .success(let sessions):
            // The session is returned in a Dictionary[SessionType:String]
            let session = sessions[SessionType.cvc]
            ...
        case .failure(let error):
            // The error returned is of type AccessCheckoutError 
            let errorMessage = error.message
            ...
        }
    }
}

Recommendation:

  • 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.

Copied!
import AccessCheckoutSDK
class MyViewController: UIViewController {
    private let accessBaseUrl = "https://try.access.worldpay.com"
    private let merchantId = "your-merchant-id"
    @IBOutlet weak var cvcView: CvcView!
    @IBAction func submit(_ sender: Any) {
        let cardDetails = try! CardDetailsBuilder().cvc(cvcView.text)
            .build()
        let accessCheckoutClient = try? AccessCheckoutClientBuilder().accessBaseUrl(accessBaseUrl)
            .merchantId(merchantId)
            .build()
        try? accessCheckoutClient?.generateSessions(cardDetails: cardDetails, sessionTypes: [SessionType.card, SessionType.cvc]) { result in
            DispatchQueue.main.async {
                switch result {
                    case .success(let sessionsDictionary):
                        let cardSession = sessionsDictionary[SessionType.card]
                        let cvcSession = sessionsDictionary[SessionType.cvc]
                        ...
                    case .failure(let error):
                        ...
                }
            }
        }
    }
}

Take a payment

Use the value of the cvc session and your stored verified token in our card/checkout paymentInstrument to take a card on file payment.

Important: The cvc session has a lifespan of 15 minutes. If you do not take a payment within that time, you must create a new cvc session value.

This paymentInstrument can be used in any of our card on file resources (payments:cardonFileAuthorize,payments:migrateCardOnFileSaleandpayments:migrateCardOnFileAuthorize).


Next Steps

Take acard on file sale
Take acard on file authorizationor
Migrate a card on file authorization