CRM/Core/Payment add missing code blocks (autogenerated)
[civicrm-core.git] / CRM / Core / Payment / Elavon.php
index b56ef330a7868b78a890cf4faceb1f0874c96bb2..72e041207b56b69d4f94fab9542128f746d19c19 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +----------------------------------------------------------------------------+
- | Elavon (Nova) Virtual Merchant Core Payment Module for CiviCRM version 4.3 |
+ | Elavon (Nova) Virtual Merchant Core Payment Module for CiviCRM version 4.5 |
  +----------------------------------------------------------------------------+
  | Licensed to CiviCRM under the Academic Free License version 3.0            |
  |                                                                            |
@@ -42,8 +42,11 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
    *
    * @param string $mode the mode of operation: live or test
    *
-   * @return void
-   **********************************************************/ function __construct($mode, &$paymentProcessor) {
+   * @param $paymentProcessor
+   *
+   * @return \CRM_Core_Payment_Elavon *******************************************************
+   */
+  function __construct($mode, &$paymentProcessor) {
     // live or test
     $this->_mode = $mode;
     $this->_paymentProcessor = $paymentProcessor;
@@ -55,9 +58,10 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
    *
    * @param string $mode the mode of operation: live or test
    *
+   * @param object $paymentProcessor
+   *
    * @return object
    * @static
-   *
    */
   static function &singleton($mode, &$paymentProcessor) {
     $processorName = $paymentProcessor['name'];
@@ -90,7 +94,7 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
     // contact name
     $requestFields['ssl_ship_to_last_name'] = $params['last_name'];
     $requestFields['ssl_card_number'] = $params['credit_card_number'];
-    $requestFields['ssl_amount'] = $params['amount'];
+    $requestFields['ssl_amount'] = trim($params['amount']);
     $requestFields['ssl_exp_date'] = sprintf('%02d', (int) $params['month']) . substr($params['year'], 2, 2);;
     $requestFields['ssl_cvv2cvc2'] = $params['cvv2'];
     // CVV field passed to processor
@@ -106,6 +110,10 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
     $requestFields['ssl_transaction_type'] = "CCSALE";
     $requestFields['ssl_description'] = empty($params['description']) ? "backoffice payment" : $params['description'];
     $requestFields['ssl_customer_number'] = substr($params['credit_card_number'], -4);
+    // Added two lines below to allow commercial cards to go through as per page 15 of Elavon developer guide
+    $requestFields['ssl_customer_code'] = '1111';
+    $requestFields['ssl_salestax'] = 0.0;
+
 
     /************************************************************************************
      *  Fields available from civiCRM not implemented for Elavon
@@ -127,7 +135,7 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
    * the processor
    **********************************************************/
   function doDirectPayment(&$params) {
-    if ($params['is_recur'] == TRUE) {
+    if (isset($params['is_recur']) && $params['is_recur'] == TRUE) {
       CRM_Core_Error::fatal(ts('Elavon - recurring payments not implemented'));
     }
 
@@ -147,7 +155,7 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
          */
 
     $requestFields['ssl_merchant_id'] = $this->_paymentProcessor['user_name'];
-    $requestFields['user_id'] = $this->_paymentProcessor['password'];
+    $requestFields['ssl_user_id'] = $this->_paymentProcessor['password'];
     $requestFields['ssl_pin'] = $this->_paymentProcessor['signature'];
     $host = $this->_paymentProcessor['url_site'];
 
@@ -189,7 +197,9 @@ 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
-    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+    if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
+      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+    }
 
     /**********************************************************
      * Send the data out over the wire
@@ -336,11 +346,13 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
    * NOTE: Called by Events and Contribute to check config params are set prior to trying
    *  register any credit card details
    *
-   * @param string $mode the mode we are operating in (live or test) - not used
+   * @return null|string
+   * @internal param string $mode the mode we are operating in (live or test) - not used
    *
    * returns string $errorMsg if any errors found - null if OK
    *
-   ********************************************************************************************/
+   ******************************************************************************************
+   */
   //  function checkConfig( $mode )          // CiviCRM V1.9 Declaration
   // CiviCRM V2.0 Declaration
   function checkConfig() {
@@ -362,6 +374,11 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
     }
   }
   //end check config
+  /**
+   * @param $requestFields
+   *
+   * @return string
+   */
   function buildXML($requestFields) {
     $xmlFieldLength['ssl_first_name'] = 15;
     // credit card name
@@ -386,21 +403,27 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
     $xmlFieldLength['ssl_transaction_type'] = 20;
     $xmlFieldLength['ssl_description'] = 255;
     $xmlFieldLength['ssl_merchant_id'] = 15;
-    $xmlFieldLength['user_id'] = 15;
-    $xmlFieldLength['ssl_pin'] = 6;
+    $xmlFieldLength['ssl_user_id'] = 15;
+    $xmlFieldLength['ssl_pin'] = 128;
     $xmlFieldLength['ssl_test_mode'] = 5;
+    $xmlFieldLength['ssl_salestax'] = 10;
+    $xmlFieldLength['ssl_customer_code'] = 17;
+    $xmlFieldLength['ssl_customer_number'] = 25;
 
     $xml = '<txn>';
     foreach ($requestFields as $key => $value) {
       $xml .= '<' . $key . '>' . self::tidyStringforXML($value, $xmlFieldLength[$key]) . '</' . $key . '>';
-
-      //  $xml .= '<' . $key . '>' . rawurlencode($value) . '</' . $key . '>';
     }
-    // sales tax appears to be required even though the dev guide says it isn't - not used by civi
-    $xml .= '<ssl_salestax>0.00</ssl_salestax></txn>';
+    $xml .= '</txn>';
     return $xml;
   }
 
+  /**
+   * @param $value
+   * @param $fieldlength
+   *
+   * @return string
+   */
   function tidyStringforXML($value, $fieldlength) {
     // the xml is posted to a url so must not contain spaces etc. It also needs to be cut off at a certain
     // length to match the processor's field length. The cut needs to be made after spaces etc are
@@ -441,6 +464,11 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
     return ($return);
   }
 
+  /**
+   * @param $Xml
+   *
+   * @return mixed
+   */
   function decodeXMLresponse($Xml) {
 
     /**