Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIVICRM-706: Making front-end CVV always required, regardless of the CVV required for back office option. #11227

Merged
merged 1 commit into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions CRM/Core/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,19 @@ protected function getDirectDebitFormFields() {
* @return array
* field metadata
*/
public function getPaymentFormFieldsMetadata() {
public function getPaymentFormFieldsMetadata($isBackOffice = FALSE) {
//@todo convert credit card type into an option value
$creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard();
$isCVVRequired = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'cvv_backoffice_required',
NULL,
1
);

if (!$isBackOffice) {
$isCVVRequired = TRUE;
}

return array(
'credit_card_number' => array(
'htmlType' => 'text',
Expand All @@ -401,11 +411,7 @@ public function getPaymentFormFieldsMetadata() {
'maxlength' => 10,
'autocomplete' => 'off',
),
'is_required' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'cvv_backoffice_required',
NULL,
1
),
'is_required' => $isCVVRequired,
'rules' => array(
array(
'rule_message' => ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'),
Expand Down
6 changes: 3 additions & 3 deletions CRM/Core/Payment/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static public function setPaymentFieldsByProcessor(&$form, $processor, $forceBil
$form->assign('paymentTypeName', $paymentTypeName);
$form->assign('paymentTypeLabel', $paymentTypeLabel);

$form->billingFieldSets[$paymentTypeName]['fields'] = $form->_paymentFields = array_intersect_key(self::getPaymentFieldMetadata($processor), array_flip($paymentFields));
$form->billingFieldSets[$paymentTypeName]['fields'] = $form->_paymentFields = array_intersect_key(self::getPaymentFieldMetadata($processor, $isBackOffice), array_flip($paymentFields));
if (in_array('cvv2', $paymentFields) && $isBackOffice) {
if (!civicrm_api3('setting', 'getvalue', array('name' => 'cvv_backoffice_required', 'group' => 'Contribute Preferences'))) {
$form->billingFieldSets[$paymentTypeName]['fields'][array_search('cvv2', $paymentFields)]['required'] = 0;
Expand Down Expand Up @@ -252,9 +252,9 @@ public static function getPaymentFields($paymentProcessor) {
*
* @return array
*/
public static function getPaymentFieldMetadata($paymentProcessor) {
public static function getPaymentFieldMetadata($paymentProcessor, $isBackOffice = FALSE) {
$paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
return $paymentProcessorObject->getPaymentFormFieldsMetadata();
return $paymentProcessorObject->getPaymentFormFieldsMetadata($isBackOffice);
}

/**
Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/CRM/Core/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,42 @@ public function testHandlePaymentMethodLogging() {
$this->assertEquals('payment_notification processor_name=Paypal', $log['values'][$log['id']]['message']);
}

/**
* Test that CVV is always required for front facing pages.
*/
public function testCVVSettingForContributionPages() {

CRM_Core_BAO_Setting::setItem(
0,
CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'cvv_backoffice_required'
);

$processor = NULL;
$dummyPayment = new CRM_Core_Payment_Dummy("test", $processor);
$paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata();
$this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should be required for front office.");

$paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata(TRUE);
$this->assertEquals(0, $paymentMetaData["cvv2"]["is_required"], "CVV should not be required for back office.");

$paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata(FALSE);
$this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should not be required for front office.");

CRM_Core_BAO_Setting::setItem(
1,
CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'cvv_backoffice_required'
);

$paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata();
$this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should be required for front office.");

$paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata(TRUE);
$this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should be required for back office.");

$paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata(FALSE);
$this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should be required for front office.");
}

}