CRM-17256 further fix to pay-later with billing_required
authoreileenmcnaugton <eileen@fuzion.co.nz>
Tue, 13 Oct 2015 14:18:48 +0000 (03:18 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Tue, 13 Oct 2015 14:24:18 +0000 (03:24 +1300)
CRM/Contribute/Form/ContributionBase.php
CRM/Core/Form.php
CRM/Core/Payment/Manual.php
CRM/Event/Cart/Form/Checkout/Payment.php
CRM/Event/Form/Participant.php
CRM/Event/Form/Registration.php
CRM/Event/Form/Registration/AdditionalParticipant.php
CRM/Event/Form/Registration/Confirm.php
CRM/Event/Form/Registration/Register.php
CRM/Financial/BAO/PaymentProcessor.php
CRM/Member/Form/Membership.php

index 1bc1a51747bead475e49f7226e5cb5441135b5c4..0984975146baa66f06509b6bc4af394e4f249736 100644 (file)
@@ -451,17 +451,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
       $this->_isBillingAddressRequiredForPayLater = CRM_Utils_Array::value('is_billing_required', $this->_values);
       $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater);
     }
-
-    // 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
-    // 2) that profile_id would be set on the payment processor
-    // 3) the payment processor would return a billing form that combines these user-configured
-    // minimums with the payment processor minimums. This would lead to fields like 'postal_code'
-    // only being on the form if either the admin has configured it as wanted or the processor
-    // requires it.
-    $this->assign('billing_profile_id', ($this->_isBillingAddressRequiredForPayLater ? 'billing' : ''));
-
   }
 
   /**
index f5ba798e2b0766b54e4b70afa213d9bdac900dd2..eb971c01f1286c63706a2856fb98f99890616559 100644 (file)
@@ -681,6 +681,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     else {
       throw new CRM_Core_Exception(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
     }
+
   }
 
   /**
@@ -762,6 +763,15 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       CRM_Financial_Form_Payment::addCreditCardJs();
     }
     $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
+    // 2) that profile_id would be set on the payment processor
+    // 3) the payment processor would return a billing form that combines these user-configured
+    // minimums with the payment processor minimums. This would lead to fields like 'postal_code'
+    // only being on the form if either the admin has configured it as wanted or the processor
+    // requires it.
+    $this->assign('billing_profile_id', (CRM_Utils_Array::value('is_billing_required', $this->_values) ? 'billing' : ''));
   }
 
   /**
index b438b8faaf2f10bebcaeb22bda33c2617d3c7859..df49d590f3269ea5334a651e32dbf9cd93b05b83 100644 (file)
@@ -36,12 +36,8 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment {
 
   /**
    * This function checks to see if we have the right config values.
-   *
-   * @return string
-   *   the error message if any
    */
-  public function checkConfig() {
-  }
+  public function checkConfig() {}
 
   /**
    * Get billing fields required for this processor.
@@ -158,4 +154,5 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment {
   public function getPaymentTypeLabel() {
     return '';
   }
+
 }
index 292adda6f8d32d7fc7e59db29d85e9d4fff4821c..bbbac759d94f2750ab7c6047ce913d9bfd181dca 100644 (file)
@@ -394,13 +394,14 @@ class CRM_Event_Cart_Form_Checkout_Payment extends CRM_Event_Cart_Form_Cart {
       CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors);
 
       // validate payment instrument values (e.g. credit card number)
-      CRM_Core_Payment_Form::validatePaymentInstrument($self->_paymentProcessor['id'], $fields, $errors, $self);
+      CRM_Core_Payment_Form::validatePaymentInstrument($self->_paymentProcessor['id'], $fields, $errors, NULL);
     }
 
     return empty($errors) ? TRUE : $errors;
   }
 
   /**
+   * @todo this should surely go! Test & remove.
    * @return bool
    */
   public function validate() {
index 0be659cf5610f9fc5d7dba1979dc5c11531cf848..05e0822f87e7926b9818b2d06550dd478507c748 100644 (file)
@@ -806,7 +806,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
 
     if (!empty($values['payment_processor_id'])) {
       // make sure that payment instrument values (e.g. credit card number and cvv) are valid
-      CRM_Core_Payment_Form::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, $self);
+      CRM_Core_Payment_Form::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL);
     }
 
     if (!empty($values['record_contribution'])) {
index ce05f738074e13ca650bb371e2d6cf8beb15ded8..f37433b2c9a4a1e0b295cc855fd74a1dcb1833a1 100644 (file)
@@ -176,8 +176,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
 
   /**
    * Set variables up before form is built.
-   *
-   * @return void
    */
   public function preProcess() {
     $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
@@ -414,7 +412,12 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
       $this->_values['event']['campaign_id'] = $campID;
     }
 
+    // Set the same value for is_billing_required as contribution page so code can be shared.
+    $this->_values['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $this->_values['event']);
     // check if billing block is required for pay later
+    // note that I have started removing the use of isBillingAddressRequiredForPayLater in favour of letting
+    // the CRM_Core_Payment_Manual class handle it - but there are ~300 references to it in the code base so only
+    // removing in very limited cases.
     if (CRM_Utils_Array::value('is_pay_later', $this->_values['event'])) {
       $this->_isBillingAddressRequiredForPayLater = CRM_Utils_Array::value('is_billing_required', $this->_values['event']);
       $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater);
index 62f6d891133185bba4faa296371cf3898150ef79..9aadd5978d74c65846d205af08e56ff16995a9ed 100644 (file)
@@ -561,7 +561,7 @@ class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_R
 
     // validate supplied payment instrument values (e.g. credit card number and cvv)
     $payment_processor_id = $self->_params[0]['payment_processor'];
-    CRM_Core_Payment_Form::validatePaymentInstrument($payment_processor_id, $self->_params[0], $errors, $self);
+    CRM_Core_Payment_Form::validatePaymentInstrument($payment_processor_id, $self->_params[0], $errors, (!$self->_isBillingAddressRequiredForPayLater ? NULL : 'billing'));
 
     if (!empty($errors)) {
       return FALSE;
index 6f5471da5c45b451c7c1080e5f5ce2fec22bccf9..4cca3d8e3e99870e51032a47edde80a9bfdc9606 100644 (file)
@@ -329,6 +329,10 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
     //consider total amount.
     $this->assign('isAmountzero', ($this->_totalAmount <= 0) ? TRUE : FALSE);
 
+    // @todo this needs to GO! We are getting rid of references to processor types in the code base in favour of
+    // over-ride-able functions on them.
+    // The processor effectively has a 'buildForm' hook it can use if it needs to.
+    // The tricky thing is that we have no way of testing this code out - perhaps it hasn't worked for years!
     if ($this->_paymentProcessor['payment_processor_type'] == 'Google_Checkout' && empty($this->_params[0]['is_pay_later']) && !($this->_params[0]['amount'] == 0) &&
       !$this->_allowWaitlist && !$this->_requireApproval
     ) {
index 24b22cf28643721eec652d26fb13df559e88e4d1..6d39361aa95d0c53ad6eed46b02bef5d72b5e9d3 100644 (file)
@@ -34,7 +34,6 @@
 
 /**
  * This class generates form components for processing Event
- *
  */
 class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
 
@@ -73,8 +72,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
 
   /**
    * Set variables up before form is built.
-   *
-   * @return void
    */
   public function preProcess() {
     parent::preProcess();
@@ -844,21 +841,12 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
       }
     }
 
+    // @todo - can we remove the 'is_monetary' concept?
     if ($self->_values['event']['is_monetary']) {
       if (empty($self->_requireApproval) && !empty($fields['amount']) && $fields['amount'] > 0 && !isset
         ($fields['payment_processor_id'])) {
         $errors['payment_processor_id'] = ts('Please select a Payment Method');
       }
-      // return if this is express mode
-      if ($self->_paymentProcessor &&
-        $self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON
-      ) {
-        if (!empty($fields[$self->_expressButtonName . '_x']) || !empty($fields[$self->_expressButtonName . '_y']) ||
-          CRM_Utils_Array::value($self->_expressButtonName, $fields)
-        ) {
-          return empty($errors) ? TRUE : $errors;
-        }
-      }
 
       $isZeroAmount = $skipPaymentValidation = FALSE;
       if (!empty($fields['priceSetId'])) {
@@ -885,14 +873,19 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
         $skipPaymentValidation = TRUE;
       }
 
-      // also return if paylater mode or zero fees for valid members
-      if (!empty($fields['is_pay_later']) || !empty($fields['bypass_payment']) ||
+      // also return if zero fees for valid members
+      if (!empty($fields['bypass_payment']) ||
         $skipPaymentValidation ||
         (!$self->_allowConfirmation && ($self->_requireApproval || $self->_allowWaitlist))
       ) {
         return empty($errors) ? TRUE : $errors;
       }
-      CRM_Core_Payment_Form::validatePaymentInstrument($self->_paymentProcessorID, $fields, $errors, $self);
+      CRM_Core_Payment_Form::validatePaymentInstrument(
+        $fields['payment_processor_id'],
+        $fields,
+        $errors,
+        (!$self->_isBillingAddressRequiredForPayLater ? NULL : 'billing')
+      );
     }
 
     foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
index 4e9f92c0597d9143d3b01b7ad2b8b9457f244271..382bf8a0962e35afd11782d0a9fd925e892fd5b3 100644 (file)
@@ -305,9 +305,11 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
 
     // Add the pay-later pseudo-processor.
     $processors['values'][0] = array(
-      'object' =>  new CRM_Core_Payment_Manual(),
+      'object' => new CRM_Core_Payment_Manual(),
       'id' => 0,
       'payment_processor_type_id' => 0,
+      // This shouldn't be required but there are still some processors hacked into core with nasty 'if's.
+      'payment_processor_type' => 'Manual',
       'class_name' => 'Payment_Manual',
       'name' => 'pay_later',
       'billing_mode' => '',
index fa394ac5c5d13a5e41dce2a5821f0aa78f2b7dc6..fedfa1e9eb13d10fcadadfe0c8760596ccbf0845 100644 (file)
@@ -806,7 +806,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form {
 
     if (!empty($params['payment_processor_id'])) {
       // validate payment instrument (e.g. credit card number)
-      CRM_Core_Payment_Form::validatePaymentInstrument($params['payment_processor_id'], $params, $errors, $self);
+      CRM_Core_Payment_Form::validatePaymentInstrument($params['payment_processor_id'], $params, $errors, NULL);
     }
 
     $joinDate = NULL;