CRM-16820. Check curl info and regex result.
authorChris Burgess <chris@giantrobot.co.nz>
Thu, 1 Oct 2015 02:51:35 +0000 (15:51 +1300)
committerChris Burgess <chris@giantrobot.co.nz>
Thu, 1 Oct 2015 02:51:35 +0000 (15:51 +1300)
CRM/Core/Payment/PaymentExpressIPN.php

index 7525758d9f7c3213ea7e1dea46e045d1bc2ac123..dc6c681d0521064f618cbad546e37adfe511b79b 100644 (file)
@@ -296,23 +296,32 @@ class CRM_Core_Payment_PaymentExpressIPN extends CRM_Core_Payment_BaseIPN {
       ));
       $success = FALSE;
       if ($response = curl_exec($curl)) {
-        fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"),
-          $response
-        ));
-        curl_close($curl);
-
-        // Assign the returned XML values to variables
-        $valid = CRM_Core_Payment_PaymentExpressUtils::_xmlAttribute($response, 'valid');
-        $success = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'Success');
-        $txnId = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'TxnId');
-        $responseText = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'ResponseText');
-        $authCode = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'AuthCode');
-        $DPStxnRef = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'DpsTxnRef');
-        $qfKey = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "TxnData1");
-        $privateData = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "TxnData2");
-        list($component, $paymentProcessorID,) = explode(',', CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "TxnData3"));
-        $amount = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "AmountSettlement");
-        $merchantReference = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "MerchantReference");
+        $info = curl_getinfo($curl);
+        if ($info['http_code'] < 200 || $info['http_code'] > 299) {
+          $log_message = "DPS error: HTTP %1 retrieving %2.";
+          CRM_Core_Error::fatal(ts($log_message, array(1 => $info['http_code'], 2 => $info['url'])));
+        }
+        else {
+          fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"), $response));
+          curl_close($curl);
+
+          // Assign the returned XML values to variables
+          $valid = CRM_Core_Payment_PaymentExpressUtils::_xmlAttribute($response, 'valid');
+          // CRM_Core_Payment_PaymentExpressUtils::_xmlAttribute() returns NULL if preg fails.
+          if (is_null($valid)) {
+            CRM_Core_Error::fatal(ts("DPS error: Unable to parse XML response from DPS.", array(1 => $valid)));
+          }
+          $success = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'Success');
+          $txnId = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'TxnId');
+          $responseText = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'ResponseText');
+          $authCode = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'AuthCode');
+          $DPStxnRef = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, 'DpsTxnRef');
+          $qfKey = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "TxnData1");
+          $privateData = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "TxnData2");
+          list($component, $paymentProcessorID,) = explode(',', CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "TxnData3"));
+          $amount = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "AmountSettlement");
+          $merchantReference = CRM_Core_Payment_PaymentExpressUtils::_xmlElement($response, "MerchantReference");
+        }
       }
       else {
         // calling DPS failed