Last Updated: 23 August 2024 | Change Log
CVC validation
Validate your customer's CVC before processing it.
Get started
To integrate the validation feature you must create an implementation of an AccessCheckoutCardValidationListener
. Initialize the validation using the AccessCheckoutValidationInitialiser
by passing in the android UI element in a CvcValidationConfig
.
You can see an example of the CVC validation integration here.
Implementing AccessCheckoutCvcValidationListener
To receive validation results of your customer's CVC you must create your own implementation of the AccessCheckoutCvcValidationListener
.
package com.worldpay.access.checkout.sample.code import com.worldpay.access.checkout.client.validation.listener.AccessCheckoutCvcValidationListener class CvcValidationListener : AccessCheckoutCvcValidationListener { override fun onCvcValidated(isValid: Boolean) { //TODO: handle the cvc validation result } override fun onValidationSuccess() { //TODO: handle the form when the validation is complete i.e. all fields are valid } }
Function and parameter descriptions
Method | Description |
---|---|
onCvcValidated | This method is called with the validity of the CVC field. isValid indicates whether the field is in a valid or invalid state. |
onValidationSuccess | This method is called when all fields are in a valid state. You would typically used this to enable the submit button. |
Initializing CVC validation
After implementing the AccessCheckoutCvcValidationListener
, you must initialize the validation for your view. To do this, create a CvcValidationConfig
using the builder as shown below. Then use this to initialize the validation.
package com.worldpay.access.checkout.sample.code // android library imports omitted import com.worldpay.access.checkout.client.validation.AccessCheckoutValidationInitialiser import com.worldpay.access.checkout.client.validation.config.CvcValidationConfig class MainActivity : AppCompatActivity() { // fields omitted override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val cvc = findViewById<EditText>(R.id.cvc) // other view references omitted val cvcValidationListener = CvcValidationListener() val cvcValidationConfig = CvcValidationConfig.Builder() .cvc(cvc) .validationListener(cvcValidationListener) .lifecycleOwner(this) .build() AccessCheckoutValidationInitialiser.initialise(cvcValidationConfig) //TODO: generate session here } }
Next steps