Menu

CVC validation

SDK v2
Last updated September 2021

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.

Full sample Integration: You can see an example of the CVC validation integrationhere.

Implementing AccessCheckoutCvcValidationListener

To receive validation results of your customer's CVC you must create your own implementation of the AccessCheckoutCvcValidationListener.

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

}
package com.worldpay.access.checkout.sample.code

import com.worldpay.access.checkout.client.validation.listener.AccessCheckoutCvcValidationListener;

public class CvcValidationListener implements AccessCheckoutCvcValidationListener {

    @Override
    public void onCvcValidated(Boolean isValid) {
        //TODO: handle the cvc validation result
    }

    @Override
    public void onValidationSuccess() {
        //TODO: handle the form when the validation is complete i.e. all fields are valid
    }

}

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.

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

}
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;
import com.worldpay.access.checkout.client.validation.listener.AccessCheckoutCvcValidationListener;

public class MainActivity extends AppCompatActivity {

    // fields omitted

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        EditText cvc = findViewById<EditText>(R.id.cvc);

        // other view references omitted

        AccessCheckoutCvcValidationListener cvcValidationListener = CvcValidationListener();

        CvcValidationConfig cvcValidationConfig = CvcValidationConfig.Builder()
                .cvc(cvc)
                .validationListener(cardValidationListener)
                .lifecycleOwner(this)
                .build();

        AccessCheckoutValidationInitialiser.initialise(cvcValidationConfig);

        //TODO: generate session here
    }

}

Back to CVC session creation.