CRM-16573 Back office supress back office cvn
[civicrm-core.git] / CRM / Core / Payment / Form.php
index 865fa196db96a5d52ba5aa0151d639012884957d..71d1c9ff1426e3b4dbb56c3895ff29f93e73e9cc 100644 (file)
@@ -49,12 +49,19 @@ class CRM_Core_Payment_Form {
    *   Array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors.
    * @param bool $forceBillingFieldsForPayLater
    *   Display billing fields even for pay later.
+   * @param bool $isBackOffice
+   *   Is this a back office function? If so the option to suppress the cvn needs to be evaluated.
    */
-  static public function setPaymentFieldsByProcessor(&$form, $processor, $forceBillingFieldsForPayLater = FALSE) {
+  static public function setPaymentFieldsByProcessor(&$form, $processor, $forceBillingFieldsForPayLater = FALSE, $isBackOffice = FALSE) {
     $form->billingFieldSets = array();
     if ($processor != NULL) {
       // ie it is pay later
       $paymentFields = self::getPaymentFields($processor);
+      if (in_array('cvv2', $paymentFields) && $isBackOffice) {
+        if (!civicrm_api3('setting', 'getvalue', array('name' => 'cvv_backoffice_required', 'group' => 'Contribute Preferences'))) {
+          unset($paymentFields[array_search('cvv2', $paymentFields)]);
+        }
+      }
       $paymentTypeName = self::getPaymentTypeName($processor);
       $paymentTypeLabel = self::getPaymentTypeLabel($processor);
       //@todo if we switch to iterating through $form->billingFieldSets we won't need to assign these directly
@@ -254,7 +261,7 @@ class CRM_Core_Payment_Form {
    *
    * @return bool
    */
-  public static function buildPaymentForm(&$form, $processor, $isBillingDataOptional) {
+  public static function buildPaymentForm(&$form, $processor, $isBillingDataOptional, $isBackOffice) {
     //if the form has address fields assign to the template so the js can decide what billing fields to show
     $profileAddressFields = $form->get('profileAddressFields');
     if (!empty($profileAddressFields)) {
@@ -268,7 +275,7 @@ class CRM_Core_Payment_Form {
       return NULL;
     }
 
-    self::setPaymentFieldsByProcessor($form, $processor, empty($isBillingDataOptional));
+    self::setPaymentFieldsByProcessor($form, $processor, empty($isBillingDataOptional), $isBackOffice);
     self::addCommonFields($form, !$isBillingDataOptional, $form->_paymentFields);
     self::addRules($form, $form->_paymentFields);
     self::addPaypalExpressCode($form);