Last Updated: 23 August 2024 | Change Log
CVC validation
Validate your customer's CVC before processing it.
The validation does not check if your customer's CVC are correct. The validation only checks the format of the entered CVC.
Get started
- you have added the
AccessCheckoutSDK
to your project as a Cocoapods dependency - you have added an
import AccessCheckoutSDK
at the top of your swift file
The four basic components for this integration are as follows:
- Your AccessCheckoutUITextField for the CVC
- An
AccessCheckoutCvcOnlyValidationDelegate
is designed to receive events pertaining to validation - An instance of
CvcOnlyValidationConfig
contains all the information required for the initialization of the validation flow, including references to the view component to enable validation for - An
AccessCheckoutValidationInitialiser
is responsible for initializing the validation flow
You can see an example of the CVC validation integration here.
Create and reference the UI components
To display your checkout form, you must create your layout first using your storyboard.
Here's an example of how you would reference your UI components using unique identifiers.
import AccessCheckoutSDK class ViewController: UIViewController { @IBOutlet weak var cvcAccessCheckoutView: AccessCheckoutUITextField! ...
Implement the AccessCheckoutCvcOnlyValidationDelegate
protocol
This ensures you are notified of validation events.
extension ViewController: AccessCheckoutCvcOnlyValidationDelegate { // This event handler is notified when the CVC becomes valid or invalid func cvcValidChanged(isValid: Bool) { // You might want to change the text colour cvcAccessCheckoutView.textColor = isValid ? nil : UIColor.red if !valid { // You might want to disable a submit button which would normally be clicked on when all fields are valid submitButton.isEnabled = false } } // This is complimentary to cvcValidChanged() and is notified only when the CVC is valid func validationSuccess() { // You might want to enable a submit button submitButton.isEnabled = true } }
Here's an example.
Instantiate a CvcOnlyValidationConfig
and initialize the validation
We recommend to do this in the viewDidLoad()
handler of your UIViewController.
override func viewDidLoad() { ... let validationConfig = try! CvcOnlyValidationConfig.builder() .cvc(cvcAccessCheckoutView) .validationDelegate(self) .build() AccessCheckoutValidationInitialiser().initialise(validationConfig) }
Create CVC session
Once validation is in place you can request sessions
to implement your payment flow.
Next steps