Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-07-19-17-34-09
[civicrm-core.git] / CRM / Core / Payment / AuthorizeNetIPN.php
index 97f35ba2ec1d929b474ec3cafe357907aba10e03..8caa61c67d4b72b9256c2618003d277425418c58 100644 (file)
@@ -101,6 +101,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
   public function recur(&$input, &$ids, &$objects, $first) {
     $this->_isRecurring = TRUE;
     $recur = &$objects['contributionRecur'];
+    $paymentProcessorObject = $objects['contribution']->_relatedObjects['paymentProcessor']['object'];
 
     // do a subscription check
     if ($recur->processor_id != $input['subscription_id']) {
@@ -152,9 +153,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
     $objects['contribution']->total_amount = $input['amount'];
     $objects['contribution']->trxn_id = $input['trxn_id'];
 
-    // since we have processor loaded for sure at this point,
-    // check and validate gateway MD5 response if present
-    $this->checkMD5($ids, $input);
+    $this->checkMD5($paymentProcessorObject, $input);
 
     if ($input['response_code'] == 1) {
       // Approved
@@ -331,17 +330,14 @@ INNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contr
   }
 
   /**
-   * @param $ids
-   * @param $input
+   * Check and validate gateway MD5 response if present.
+   *
+   * @param CRM_Core_Payment_AuthorizeNet $paymentObject
+   * @param array $input
    *
    * @return bool
    */
-  public function checkMD5($ids, $input) {
-    $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ids['paymentProcessor'],
-      $input['is_test'] ? 'test' : 'live'
-    );
-    $paymentObject = CRM_Core_Payment::singleton($input['is_test'] ? 'test' : 'live', $paymentProcessor);
-
+  public function checkMD5($paymentObject, $input) {
     if (!$paymentObject->checkMD5($input['MD5_Hash'], $input['trxn_id'], $input['amount'], TRUE)) {
       CRM_Core_Error::debug_log_message("MD5 Verification failed.");
       echo "Failure: Security verification failed<p>";