CRM-20264 support card_type_id and pan_truncation in all backoffice form
[civicrm-core.git] / CRM / Core / Payment / Manual.php
index b2d12dd7d250c8d4c931223c5fb8153ffba4513a..9024f10cab53741fe2c0578b6d548ef063339ffd 100644 (file)
@@ -84,8 +84,28 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment {
    * @return array
    */
   public function getPaymentFormFields() {
+    if (!$this->isBackOffice()) {
+      return array();
+    }
+
+    $paymentInstrument = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID());
+    if ($paymentInstrument === 'Credit Card') {
+      // @todo - return credit_card_type field once the underlying code works to extract this field.
+      // Note the problem is this should be stored in civicrm_financial_trxn.credit_card_type.
+      // However there is an ambiguity as that field is an integer & should hence be called
+      // credit_card_type_id, or it should store 'visa' It probably makes sense to fix that before going much
+      // further as the code I've seen makes it clear that it will require work arounds.
+      return array('credit_card_type', 'pan_truncation');
+    }
+    elseif ($paymentInstrument === 'Check') {
+      // Really we should render check_number here, but we need to review how we edit
+      // check_numebr since we expose it as editable on the contribution form,
+      // even though it should only be editable from a transation specific form.
+      return array();
+    }
     return array();
   }
+
   /**
    * Process payment.
    *
@@ -137,6 +157,15 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment {
     $this->result = $result;
   }
 
+  /**
+   * Set payment instrument id.
+   *
+   * @param int $paymentInstrumentID
+   */
+  public function setPaymentInstrumentID($paymentInstrumentID) {
+    $this->paymentInstrumentID = $paymentInstrumentID;
+  }
+
   /**
    * Get the name of the payment type.
    *
@@ -152,7 +181,7 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment {
    * @return string
    */
   public function getPaymentTypeLabel() {
-    return '';
+    return CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID());
   }
 
   /**
@@ -173,6 +202,15 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment {
     return TRUE;
   }
 
+  /**
+   * Are back office payments supported.
+   *
+   * @return bool
+   */
+  protected function supportsBackOffice() {
+    return TRUE;
+  }
+
   /**
    * Submit a manual payment.
    *