CRM-17728 enotices on payment processor form
authoreileenmcnaugton <eileen@fuzion.co.nz>
Thu, 17 Dec 2015 23:59:54 +0000 (12:59 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Fri, 18 Dec 2015 00:10:02 +0000 (13:10 +1300)
CRM/Admin/Form/PaymentProcessor.php
CRM/Core/Payment.php
CRM/Financial/BAO/PaymentProcessor.php
templates/CRM/Admin/Form/PaymentProcessor.tpl

index 2884833fb183390488273aa2bc771224f7253f95..c14991c9f8f188facfd69d63f153a7607a93273c 100644 (file)
@@ -200,6 +200,14 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
       array('' => ts('- select -')) + $financialAccount,
       TRUE
     );
+    $this->addSelect('payment_instrument_id',
+      array(
+        'entity' => 'contribution',
+        'label' => ts('Payment Method'),
+        'placeholder'  => NULL,
+      )
+    );
+
     // is this processor active ?
     $this->add('checkbox', 'is_active', ts('Is this Payment Processor active?'));
     $this->add('checkbox', 'is_default', ts('Is this Payment Processor the default?'));
@@ -298,6 +306,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
       $defaults['test_url_api'] = $this->_ppDAO->url_api_test_default;
       $defaults['test_url_recur'] = $this->_ppDAO->url_recur_test_default;
       $defaults['test_url_button'] = $this->_ppDAO->url_button_test_default;
+      $defaults['payment_instrument_id'] = $this->_ppDAO->payment_instrument_id;
       // When user changes payment processor type, it is passed in via $this->_ppType so update defaults array.
       if ($this->_ppType) {
         $defaults['payment_processor_type_id'] = $this->_ppType;
@@ -341,7 +350,6 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
    * Process the form submission.
    */
   public function postProcess() {
-    CRM_Utils_System::flushCache('CRM_Financial_DAO_PaymentProcessor');
 
     if ($this->_action & CRM_Core_Action::DELETE) {
       CRM_Financial_BAO_PaymentProcessor::del($this->_id);
@@ -370,46 +378,21 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
    * @param bool $test
    */
   public function updatePaymentProcessor(&$values, $domainID, $test) {
-    // @todo remove this function (some or all) in favour or CRM_Financial_BAO_PaymentProcessor::create.
-    $dao = new CRM_Financial_DAO_PaymentProcessor();
-
-    $dao->id = $test ? $this->_testID : $this->_id;
-    $dao->domain_id = $domainID;
-    $dao->is_test = $test;
-    $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0);
-
-    $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
-
-    $dao->name = $values['name'];
-    $dao->description = $values['description'];
-    $dao->payment_processor_type_id = $values['payment_processor_type_id'];
-
-    foreach ($this->_fields as $field) {
-      $fieldName = $test ? "test_{$field['name']}" : $field['name'];
-      $dao->{$field['name']} = trim(CRM_Utils_Array::value($fieldName, $values));
-      if (empty($dao->{$field['name']})) {
-        $dao->{$field['name']} = 'null';
-      }
-    }
-
-    // also copy meta fields from the info DAO
-    $dao->is_recur = $this->_ppDAO->is_recur;
-    $dao->billing_mode = $this->_ppDAO->billing_mode;
-    $dao->class_name = $this->_ppDAO->class_name;
-    $dao->payment_type = $this->_ppDAO->payment_type;
-
-    $dao->save();
-
-    //CRM-11515
-
-    $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
-    $params = array(
-      'entity_table' => 'civicrm_payment_processor',
-      'entity_id' => $dao->id,
-      'account_relationship' => $relationTypeId,
+    $params  = array_merge(array(
+      'id' => $test ? $this->_testID : $this->_id,
+      'domain_id' => $domainID,
+      'is_test' => $test,
+      'is_active' => 0,
+      'is_default' => 0,
+      'is_recur' => $this->_ppDAO->is_recur,
+      'billing_mode' => $this->_ppDAO->billing_mode,
+      'class_name' => $this->_ppDAO->class_name,
+      'payment_type' => $this->_ppDAO->payment_type,
+      'payment_instrument_id' => $this->_ppDAO->payment_instrument_id,
       'financial_account_id' => $values['financial_account_id'],
-    );
-    CRM_Financial_BAO_FinancialTypeAccount::add($params);
+    ), $values);
+
+    civicrm_api3('PaymentProcessor', 'create', $params);
   }
 
 }
index db6a77f1e92a1c90e93c9850f558283805c94413..77bbeaf93b2ab5da84af9f061369b54ab6df798c 100644 (file)
@@ -1200,8 +1200,7 @@ abstract class CRM_Core_Payment {
         break;
     }
 
-    $session = CRM_Core_Session::singleton();
-    $userId = $session->get('userID');
+    $userId = CRM_Core_Session::singleton()->get('userID');
     $contactID = 0;
     $checksumValue = '';
     $entityArg = '';
index 5ff3237b172abeccfabfa2cb05f2247a820e86fa..cc5c80442197620adbc7c3137ab4ef756dff3321 100644 (file)
@@ -50,7 +50,6 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * @throws Exception
    */
   public static function create($params) {
-    // FIXME Reconcile with CRM_Admin_Form_PaymentProcessor::updatePaymentProcessor
     $processor = new CRM_Financial_DAO_PaymentProcessor();
     $processor->copyValues($params);
 
@@ -79,6 +78,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
       );
       CRM_Financial_BAO_FinancialTypeAccount::add($values);
     }
+
     Civi\Payment\System::singleton()->flushProcessors();
     return $processor;
   }
index a4a3fb14bb3a303f79d081013ed5046660ab0e9a..98822b18c90decc544256b6170f418b40b4997ac 100644 (file)
@@ -56,6 +56,9 @@
         {/if}
       </td>
     </tr>
+    <tr class="crm-paymentProcessor-form-block-payment-instrument-id">
+      <td class="label">{$form.payment_instrument_id.label}</td><td>{$form.payment_instrument_id.html}</td>
+    </tr>
     <tr class="crm-paymentProcessor-form-block-is_active">
         <td></td><td>{$form.is_active.html}&nbsp;{$form.is_active.label}</td>
     </tr>