Merge pull request #23280 from eileenmcnaughton/import_job
[civicrm-core.git] / CRM / Core / Payment / Elavon.php
index 8990e8586039111a382879148860944fa7511ccc..fbc74d43446b4104f58801ef3406a937a4ec41da 100644 (file)
@@ -84,13 +84,28 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
   /**
    * This function sends request and receives response from the processor.
    *
-   * @param array $params
+   * @param array|PropertyBag $params
+   *
+   * @param string $component
    *
    * @return array
+   *   Result array (containing at least the key payment_status_id)
    *
-   * @throws \CRM_Core_Exception
+   * @throws \Civi\Payment\Exception\PaymentProcessorException
    */
-  public function doDirectPayment(&$params) {
+  public function doPayment(&$params, $component = 'contribute') {
+    $propertyBag = \Civi\Payment\PropertyBag::cast($params);
+    $this->_component = $component;
+    $result = $this->setStatusPaymentPending([]);
+
+    // If we have a $0 amount, skip call to processor and set payment_status to Completed.
+    // Conceivably a processor might override this - perhaps for setting up a token - but we don't
+    // have an example of that at the moment.
+    if ($propertyBag->getAmount() == 0) {
+      $result = $this->setStatusPaymentCompleted($result);
+      return $result;
+    }
+
     if (isset($params['is_recur']) && $params['is_recur'] == TRUE) {
       throw new CRM_Core_Exception(ts('Elavon - recurring payments not implemented'));
     }
@@ -141,7 +156,7 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
     // set this for debugging -look for output in apache error log
     //curl_setopt ($ch,CURLOPT_VERBOSE,1 );
     // ensures any Location headers are followed
-    if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
+    if (ini_get('open_basedir') == '') {
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     }
 
@@ -201,8 +216,8 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
         $trxn_id = (string) CRM_Core_DAO::singleValueQuery($query);
         $trxn_id = (int) str_replace('test', '', $trxn_id);
         ++$trxn_id;
-        $params['trxn_id'] = sprintf('test%08d', $trxn_id);
-        return $params;
+        $result['trxn_id'] = sprintf('test%08d', $trxn_id);
+        return $result;
       }
       throw new PaymentProcessorException('Error: [approval code related to test transaction but mode was ' . $this->_mode, 9099);
     }
@@ -215,12 +230,13 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
       // Success !
       if ($this->_mode !== 'test') {
         // 'trxn_id' is varchar(255) field. returned value is length 37
-        $params['trxn_id'] = $processorResponse['ssl_txn_id'];
+        $result['trxn_id'] = $processorResponse['ssl_txn_id'];
       }
 
       $params['trxn_result_code'] = $processorResponse['ssl_approval_code'] . "-Cvv2:" . $processorResponse['ssl_cvv2_response'] . "-avs:" . $processorResponse['ssl_avs_response'];
+      $result = $this->setStatusPaymentCompleted($result);
 
-      return $params;
+      return $result;
     }
   }