CRM-19707 CiviContribute Assigns Payment Processor ID correctly (#9481)
authorLogan Bear <webminister@dignityusa.org>
Fri, 13 Jan 2017 02:55:50 +0000 (21:55 -0500)
committercolemanw <coleman@civicrm.org>
Fri, 13 Jan 2017 02:55:50 +0000 (21:55 -0500)
* CRM-19707 CiviContribute Assigns Payment Processor ID correctly

Original code used Payment Processor Type ID for PayPal.  New code
looks up actual Payment Processor ID, instead.

* Corrected coding standards

Removed white space

* Revert "Corrected coding standards"

This reverts commit 6f8109650736ccb20ee08328f208c3852742b71e.

* Revert "CRM-19707 CiviContribute Assigns Payment Processor ID correctly"

This reverts commit 597e639e632ae793c422a2f5ce6c41e44c70b29e.

* CRM-19707

Created function to get Payment Processing ID and called it in the two
locations needed

* Corrected Coding Standards

I’m still learning

* Corrected function call

Misnamed Processor as Processing

* Forgot this

It’s been a while,  Forgot the this-> to call the proper function.

* Still trying removed this

Attempting to get through the errors

* self, not this

Still learning OO PHP.  This should finally fix it.

CRM/Core/Payment/PayPalProIPN.php

index f3a8008c2f274b23b53d7d40d1ab101934dfad69..e557541c362f9cc20418a55e39848d9f48af1c51 100644 (file)
@@ -384,6 +384,29 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN {
     $this->completeTransaction($input, $ids, $objects, $transaction, $recur);
   }
 
+  /**
+   * Gets PaymentProcessorID for PayPal
+   *
+   * @return int
+   */
+  public function getPayPalPaymentProcessorID() {
+    // This is an unreliable method as there could be more than one instance.
+    // Recommended approach is to use the civicrm/payment/ipn/xx url where xx is the payment
+    // processor id & the handleNotification function (which should call the completetransaction api & by-pass this
+    // entirely). The only thing the IPN class should really do is extract data from the request, validate it
+    // & call completetransaction or call fail? (which may not exist yet).
+    $paymentProcessorTypeID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
+      'PayPal', 'id', 'name'
+    );
+    return (int) civicrm_api3('PaymentProcessor', 'getvalue', array(
+      'is_test' => 0,
+      'options' => array('limit' => 1),
+      'payment_processor_type_id' => $paymentProcessorTypeID,
+      'return' => 'id',
+    ));
+
+  }
+
   /**
    * This is the main function to call. It should be sufficient to instantiate the class
    * (with the input parameters) & call this & all will be done
@@ -444,15 +467,8 @@ INNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contr
     // processor id & the handleNotification function (which should call the completetransaction api & by-pass this
     // entirely). The only thing the IPN class should really do is extract data from the request, validate it
     // & call completetransaction or call fail? (which may not exist yet).
-    $paymentProcessorTypeID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
-      'PayPal', 'id', 'name'
-    );
-    $paymentProcessorID = (int) civicrm_api3('PaymentProcessor', 'getvalue', array(
-      'is_test' => 0,
-      'options' => array('limit' => 1),
-      'payment_processor_type_id' => $paymentProcessorTypeID,
-      'return' => 'id',
-    ));
+
+    $paymentProcessorID = self::getPayPalPaymentProcessorID();
 
     if (!$this->validateData($input, $ids, $objects, TRUE, $paymentProcessorID)) {
       return FALSE;
@@ -576,9 +592,7 @@ INNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contr
     // membership would be an easy add - but not relevant to my customer...
     $this->_component = $input['component'] = 'contribute';
     $input['trxn_date'] = date('Y-m-d-H-i-s', strtotime(self::retrieve('time_created', 'String')));
-    $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
-      'PayPal', 'id', 'name'
-    );
+    $paymentProcessorID = self::getPayPalPaymentProcessorID();
 
     if (!$this->validateData($input, $ids, $objects, TRUE, $paymentProcessorID)) {
       throw new CRM_Core_Exception('Data did not validate');