Skip to content

Commit

Permalink
CRM-20166: New setting to make CVV required for front office separately.
Browse files Browse the repository at this point in the history
  • Loading branch information
agilewarealok committed Oct 27, 2017
1 parent cde3f71 commit 4464592
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CRM/Admin/Form/Preferences/Contribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences {
protected $_settings = array(
'cvv_backoffice_required' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'cvv_frontoffice_required' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'update_contribution_on_membership_type_change' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'acl_financial_type' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'always_post_to_accounts_receivable' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
Expand Down Expand Up @@ -177,7 +178,7 @@ public function buildQuickForm() {
public function setDefaultValues() {
$defaults = Civi::settings()->get('contribution_invoice_settings');
//CRM-16691: Changes made related to settings of 'CVV'.
foreach (array('cvv_backoffice_required') as $setting) {
foreach (array('cvv_backoffice_required', 'cvv_frontoffice_required') as $setting) {
$defaults[$setting] = civicrm_api3('setting', 'getvalue',
array(
'name' => $setting,
Expand Down Expand Up @@ -225,7 +226,7 @@ public function postProcess() {
Civi::settings()->set('user_dashboard_options', $settingName);
}
//CRM-16691: Changes made related to settings of 'CVV'.
$settings = array_intersect_key($params, array('cvv_backoffice_required' => 1));
$settings = array_intersect_key($params, array('cvv_backoffice_required' => 1, 'cvv_frontoffice_required' => 1));
$result = civicrm_api3('setting', 'create', $settings);
CRM_Core_Session::setStatus(ts('Your changes have been saved.'), ts('Changes Saved'), "success");
}
Expand Down
8 changes: 6 additions & 2 deletions CRM/Core/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,13 @@ 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 = Civi::settings()->get('cvv_backoffice_required');
if (!$isBackOffice) {
$isCVVRequired = Civi::settings()->get('cvv_frontoffice_required');
}
return array(
'credit_card_number' => array(
'htmlType' => 'text',
Expand All @@ -686,7 +690,7 @@ public function getPaymentFormFieldsMetadata() {
'maxlength' => 10,
'autocomplete' => 'off',
),
'is_required' => Civi::settings()->get('cvv_backoffice_required'),
'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 @@ -71,7 +71,7 @@ static public function setPaymentFieldsByProcessor(&$form, $processor, $billing_
$paymentTypeLabel = self::getPaymentTypeLabel($processor);
$form->assign('paymentTypeLabel', $paymentTypeLabel);
$form->assign('isBackOffice', $isBackOffice);
$form->_paymentFields = $form->billingFieldSets[$paymentTypeName]['fields'] = self::getPaymentFieldMetadata($processor);
$form->_paymentFields = $form->billingFieldSets[$paymentTypeName]['fields'] = self::getPaymentFieldMetadata($processor, $isBackOffice);
$form->_paymentFields = array_merge($form->_paymentFields, self::getBillingAddressMetadata($processor, $form->_bltID));
$form->assign('paymentFields', self::getPaymentFields($processor));
self::setBillingAddressFields($form, $processor);
Expand Down Expand Up @@ -156,8 +156,8 @@ public static function getPaymentFields($paymentProcessor) {
*
* @return array
*/
public static function getPaymentFieldMetadata($paymentProcessor) {
return array_intersect_key($paymentProcessor['object']->getPaymentFormFieldsMetadata(), array_flip(self::getPaymentFields($paymentProcessor)));
public static function getPaymentFieldMetadata($paymentProcessor, $isBackOffice = FALSE) {
return array_intersect_key($paymentProcessor['object']->getPaymentFormFieldsMetadata($isBackOffice), array_flip(self::getPaymentFields($paymentProcessor)));
}

/**
Expand Down
15 changes: 15 additions & 0 deletions api/v3/examples/Setting/GetFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ function setting_getfields_expectedresult() {
'description' => 'Is the CVV code required for back office credit card transactions',
'help_text' => 'If set it back-office credit card transactions will required a cvv code. Leave as required unless you have a very strong reason to change',
),
'cvv_frontoffice_required' => array(
'group_name' => 'Contribute Preferences',
'group' => 'contribute',
'name' => 'cvv_frontoffice_required',
'type' => 'Boolean',
'quick_form_type' => 'YesNo',
'default' => '1',
'add' => '4.1',
'title' => 'CVV required for front office?',
'is_domain' => 1,
'default' => 1,
'is_contact' => 0,
'description' => 'Is the CVV code required for front office credit card transactions',
'help_text' => 'If set it front-office credit card transactions will required a cvv code. Leave as required unless you have a very strong reason to change',
),
'contribution_invoice_settings' => array(
'group_name' => 'Contribute Preferences',
'group' => 'contribute',
Expand Down
15 changes: 15 additions & 0 deletions settings/Contribute.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@
'description' => 'Is the CVV code required for back office credit card transactions',
'help_text' => 'If set it back-office credit card transactions will required a cvv code. Leave as required unless you have a very strong reason to change',
),
'cvv_frontoffice_required' => array(
'group_name' => 'Contribute Preferences',
'group' => 'contribute',
'name' => 'cvv_frontoffice_required',
'type' => 'Boolean',
'quick_form_type' => 'YesNo',
'default' => '1',
'add' => '4.1',
'title' => 'CVV required for front office?',
'is_domain' => 1,
'default' => 1,
'is_contact' => 0,
'description' => 'Is the CVV code required for front office credit card transactions',
'help_text' => 'If set it front-office credit card transactions will required a cvv code. Leave as required unless you have a very strong reason to change',
),
'contribution_invoice_settings' => array(
'group_name' => 'Contribute Preferences',
'group' => 'contribute',
Expand Down

0 comments on commit 4464592

Please sign in to comment.