Making the Credit Card CVV Field Optional in CiviCRM

Fen Labalme Profile Photo from DCSF
Fen Labalme

on

August 13, 2010

Making the Credit Card CVV Field Optional in CiviCRM

We have a client that wanted to be able to process donations when the Credit Card's CVV numbers were not available. I had thought this field was mandatory, and indeed, CiviCRM's AuthorizeNet payment processor package requires it. But after talking with AuthorizeNet (the company) we discovered that the field is optional.

This is a useful trick that fellow CivicActions team member and CiviCRM wizard Matt Chapman showed me. Basically, the hook_civicrm_validate() function can be used to reset an error caused by a missing field. Here's the entirety of the civicrm_cvv module:

<?php
/**
* This removes the requirement for the CVV field in the credit card
* Requires Matt's patch to v3.1.6 CiviCRM core (now in 3.2.x core)
* See: http://issues.civicrm.org/jira/browse/CRM-6393
*/
function civicrm_cvv_civicrm_validate( $formName, &$fields, &$files, &$form ) {
  if ( $formName == 'CRM_Contribute_Form_Contribution_Main' ||
       $formName == 'CRM_Contribute_Form_Contribution' ) {
    $form->setElementError('cvv2', null);
  }
  return true;
}

If running CiviCRM v3.1.x (we were running v3.1.6) you'll need to hack core to get this to work. Fortunately, the hack is small (and it's included in CiviCRM v3.2+). See the link in the code for the patch.

The better way to do this would be to add a setting to the AuthorizNet.php package in CiviCRM that can turn the requirements of this field on or off for each place it appears. Such a patch would likely be accepted by the CiviCRM team as there's a strong argument to be made that if the provider considers the field optional, then the interface package should not require it. But that's for another day.

For now, the client is happy and I learned a good use of hook_civicrm_vlaidate() that may well come in handy again.

Share it!

Im little curiouse about the first comment mentioned above .. What does solar charger to do with this post ?Anyways thanks for the post .. It was really usefull ..
This is excellent!  I needed this tonight for a client with the same issue (some constituents still mail or fax in forms with credit card numbers but no CVV2).  I very much appreciate you sharing the knowledge!