[REF] Cleanup access to payment_processor_id
authoreileen <emcnaughton@wikimedia.org>
Thu, 25 Mar 2021 23:38:08 +0000 (12:38 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 26 Mar 2021 00:33:53 +0000 (13:33 +1300)
CRM/Core/Form.php
CRM/Member/Form/Membership.php

index c25e991bdce1ee0dae06f9d822bd23181342c12c..84dce6fa352b0c1c58dff5a71682521a6502ed59 100644 (file)
@@ -816,8 +816,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * @return int
    */
-  public function getPaymentProcessorID() {
-    return $this->_paymentProcessorID;
+  public function getPaymentProcessorID(): int {
+    return (int) $this->_paymentProcessorID;
   }
 
   /**
index 31bcac4792c63695836c72585139c97ae02cf1e7..9d4d85d58b75ad3638a7676718882962e5209179 100644 (file)
@@ -1163,7 +1163,7 @@ DESC limit 1");
       $params['financial_type_id'] = $this->getFinancialTypeID();
 
       //get the payment processor id as per mode. Try removing in favour of beginPostProcess.
-      $params['payment_processor_id'] = $formValues['payment_processor_id'] = $this->_paymentProcessor['id'];
+      $params['payment_processor_id'] = $formValues['payment_processor_id'] = $this->getPaymentProcessorID();
       $params['register_date'] = CRM_Utils_Time::date('YmdHis');
 
       // add all the additional payment params we need
@@ -1808,7 +1808,7 @@ DESC limit 1");
     }
     $recurParams['invoice_id'] = $this->getInvoiceID();
     $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
-    $recurParams['payment_processor_id'] = $params['payment_processor_id'] ?? NULL;
+    $recurParams['payment_processor_id'] = $this->getPaymentProcessorID();
     $recurParams['is_email_receipt'] = (bool) $this->getSubmittedValue('send_receipt');
     // we need to add a unique trxn_id to avoid a unique key error
     // in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
@@ -1879,4 +1879,13 @@ DESC limit 1");
     return $this->_mode && $this->getSubmittedValue('auto_renew');
   }
 
+  /**
+   * Get the payment processor ID.
+   *
+   * @return int
+   */
+  public function getPaymentProcessorID(): int {
+    return (int) ($this->getSubmittedValue('payment_processor_id') ?: $this->_paymentProcessor['id']);
+  }
+
 }