Refactor to reduce duplication on payment forms
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 6 May 2019 21:58:11 +0000 (22:58 +0100)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 6 May 2019 21:58:11 +0000 (22:58 +0100)
CRM/Core/Form.php
CRM/Core/Payment/ProcessorForm.php
CRM/Financial/Form/Payment.php

index b396667fe7f4306d153fa680da40dc5e47eacf8c..8dcc839ae2f7bdf27f3708b81c93d0cb70d5ee45 100644 (file)
@@ -766,6 +766,13 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     $this->assign('bltID', $this->_bltID);
   }
 
+  /**
+   * @return int
+   */
+  public function getPaymentProcessorID() {
+    return $this->_paymentProcessorID;
+  }
+
   /**
    * This if a front end form function for setting the payment processor.
    *
@@ -878,9 +885,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       else {
         $this->_paymentProcessor = [];
       }
-      CRM_Financial_Form_Payment::addCreditCardJs($this->_paymentProcessorID);
     }
-    $this->assign('paymentProcessorID', $this->_paymentProcessorID);
+
     // We save the fact that the profile 'billing' is required on the payment form.
     // Currently pay-later is the only 'processor' that takes notice of this - but ideally
     // 1) it would be possible to select the minimum_billing_profile_id for the contribution form
index 6afebf6e535dda762faaaab1685180ba304147f6..9b8fc660e6717447ff73fb9e2f03ccd251c9e320 100644 (file)
@@ -73,6 +73,9 @@ class CRM_Core_Payment_ProcessorForm {
 
     $form->assign('suppressSubmitButton', $form->_paymentObject->isSuppressSubmitButtons());
 
+    CRM_Financial_Form_Payment::addCreditCardJs($form->getPaymentProcessorID());
+    $form->assign('paymentProcessorID', $form->getPaymentProcessorID());
+
     $form->assign('currency', $form->getCurrency());
 
     // also set cancel subscription url
index a559e5ec9274836888e488e040f2d5aac8449733..9deb8ea265545e01b3d6506995834fd3fc0db29c 100644 (file)
@@ -79,11 +79,6 @@ class CRM_Financial_Form_Payment extends CRM_Core_Form {
 
     CRM_Core_Payment_ProcessorForm::preProcess($this);
 
-    self::addCreditCardJs($this->_paymentProcessorID);
-
-    $this->assign('paymentProcessorID', $this->_paymentProcessorID);
-    $this->assign('currency', $this->currency);
-
     $this->assign('suppressForm', TRUE);
     $this->controller->_generateQFKey = FALSE;
   }