Exemple #1
0
 /**
  * This function sends request and receives response from
  * the processor
  */
 public function doDirectPayment(&$params)
 {
     if ($params['is_recur'] == TRUE) {
         CRM_Core_Error::fatal(ts('%1 - recurring payments not implemented', array(1 => $paymentProcessor)));
     }
     if (!defined('CURLOPT_SSLCERT')) {
         CRM_Core_Error::fatal(ts('%1 - Gateway requires curl with SSL support', array(1 => $paymentProcessor)));
     }
     /**********************************************************
      * Create the array of variables to be sent to the processor from the $params array
      * passed into this function
      **********************************************************/
     $requestFields = self::mapProcessorFieldstoParams($params);
     /**********************************************************
      * create FirstData request object
      **********************************************************/
     require_once 'FirstData/lphp.php';
     //  $mylphp=new lphp;
     /**********************************************************
      * define variables for connecting with the gateway
      **********************************************************/
     # Name and location of certificate file
     $key = $this->_paymentProcessor['password'];
     # Your store number
     $requestFields["configfile"] = $this->_paymentProcessor['user_name'];
     $port = "1129";
     $host = $this->_paymentProcessor['url_site'] . ":" . $port . "/LSGSXML";
     //----------------------------------------------------------------------------------------------------
     // Check to see if we have a duplicate before we send
     //----------------------------------------------------------------------------------------------------
     if ($this->checkDupe($params['invoiceID'], CRM_Utils_Array::value('contributionID', $params))) {
         return self::errorExit(9003, 'It appears that this transaction is a duplicate.  Have you already submitted the form once?  If so there may have been a connection problem.  Check your email for a receipt from eWAY.  If you do not receive a receipt within 2 hours you can try your transaction again.  If you continue to have problems please contact the site administrator.');
     }
     //----------------------------------------------------------------------------------------------------
     // Convert to XML using function provided by payment processor
     //----------------------------------------------------------------------------------------------------
     $requestxml = lphp::buildXML($requestFields);
     /*----------------------------------------------------------------------------------------------------
       // Send to the payment information using cURL
       /----------------------------------------------------------------------------------------------------
        */
     $ch = curl_init($host);
     if (!$ch) {
         return self::errorExit(9004, 'Could not initiate connection to payment gateway');
     }
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $requestxml);
     curl_setopt($ch, CURLOPT_SSLCERT, $key);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL') ? 2 : 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'));
     // return the result on success, FALSE on failure
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 36000);
     // ensures any Location headers are followed
     if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     }
     // Send the data out over the wire
     //--------------------------------
     $responseData = curl_exec($ch);
     //----------------------------------------------------------------------------------------------------
     // See if we had a curl error - if so tell 'em and bail out
     //
     // NOTE: curl_error does not return a logical value (see its documentation), but
     //       a string, which is empty when there was no error.
     //----------------------------------------------------------------------------------------------------
     if (curl_errno($ch) > 0 || strlen(curl_error($ch)) > 0) {
         $errorNum = curl_errno($ch);
         $errorDesc = curl_error($ch);
         // Paranoia - in the unlikley event that 'curl' errno fails
         if ($errorNum == 0) {
             $errorNum = 9005;
         }
         // Paranoia - in the unlikley event that 'curl' error fails
         if (strlen($errorDesc) == 0) {
             $errorDesc = "Connection to payment gateway failed";
         }
         if ($errorNum == 60) {
             return self::errorExit($errorNum, "Curl error - " . $errorDesc . " Try this link for more information http://curl.haxx.se/docs/sslcerts.html");
         }
         return self::errorExit($errorNum, "Curl error - " . $errorDesc . " your key is located at " . $key . " the url is " . $host . " xml is " . $requestxml . " processor response = " . $processorResponse);
     }
     //----------------------------------------------------------------------------------------------------
     // If null data returned - tell 'em and bail out
     //
     // NOTE: You will not necessarily get a string back, if the request failed for
     //       any reason, the return value will be the boolean false.
     //----------------------------------------------------------------------------------------------------
     if ($responseData === FALSE || strlen($responseData) == 0) {
         return self::errorExit(9006, "Error: Connection to payment gateway failed - no data returned.");
     }
     //----------------------------------------------------------------------------------------------------
     // If gateway returned no data - tell 'em and bail out
     //----------------------------------------------------------------------------------------------------
     if (empty($responseData)) {
         return self::errorExit(9007, "Error: No data returned from payment gateway.");
     }
     //----------------------------------------------------------------------------------------------------
     // Success so far - close the curl and check the data
     //----------------------------------------------------------------------------------------------------
     curl_close($ch);
     //----------------------------------------------------------------------------------------------------
     // Payment successfully sent to gateway - process the response now
     //----------------------------------------------------------------------------------------------------
     //
     $processorResponse = lphp::decodeXML($responseData);
     // transaction failed, print the reason
     if ($processorResponse["r_approved"] != "APPROVED") {
         return self::errorExit(9009, "Error: [" . $processorResponse['r_error'] . "] - from payment processor");
     } else {
         //-----------------------------------------------------------------------------------------------------
         // Cross-Check - the unique 'TrxnReference' we sent out should match the just received 'TrxnReference'
         //
         // this section not used as the processor doesn't appear to pass back our invoice no. Code in eWay model if
         // used later
         //-----------------------------------------------------------------------------------------------------
         //=============
         // Success !
         //=============
         $params['trxn_result_code'] = $processorResponse['r_message'];
         $params['trxn_id'] = $processorResponse['r_ref'];
         CRM_Core_Error::debug_log_message("r_authresponse " . $processorResponse['r_authresponse']);
         CRM_Core_Error::debug_log_message("r_code " . $processorResponse['r_code']);
         CRM_Core_Error::debug_log_message("r_tdate " . $processorResponse['r_tdate']);
         CRM_Core_Error::debug_log_message("r_avs " . $processorResponse['r_avs']);
         CRM_Core_Error::debug_log_message("r_ordernum " . $processorResponse['r_ordernum']);
         CRM_Core_Error::debug_log_message("r_error " . $processorResponse['r_error']);
         CRM_Core_Error::debug_log_message("csp " . $processorResponse['r_csp']);
         CRM_Core_Error::debug_log_message("r_message " . $processorResponse['r_message']);
         CRM_Core_Error::debug_log_message("r_ref " . $processorResponse['r_ref']);
         CRM_Core_Error::debug_log_message("r_time " . $processorResponse['r_time']);
         return $params;
     }
 }
 /**
  *
  * @param string $action
  * @param number $money
  * @param array  $parameters
  *
  * @return Merchant_Billing_Response
  */
 private function commit($action, $money, $parameters = array())
 {
     $url = $this->is_test() ? self::TEST_URL : self::LIVE_URL;
     if ($action != 'VOID') {
         $parameters['chargetotal'] = $money;
     }
     /* Request a test response */
     $parameters['result'] = $this->is_test() ? 'GOOD' : 'LIVE';
     $mylphp = new lphp();
     $post_data = $this->post_data($action, $parameters);
     $post_data = $mylphp->buildXML($post_data);
     $response = $this->parse($this->ssl_post($url, $post_data, array('pem' => $this->options['pem'])));
     $test_mode = $this->is_test();
     return new Merchant_Billing_Response($this->success_from($response), $this->message_from($response), get_object_vars($response), array('test' => $test_mode, 'avs_result' => $this->avs_result_from($response), 'cvv_result' => $response->r_avs));
 }
    $myorder["email"] = $_SESSION['provider']['contactemailaddress'];
}
$myorder["zip"] = $_POST["zip"];
$myorder["sstate"] = "";
if (isset($_SESSION['consumer']['itconsumer_id'])) {
    $consumer_id = $_SESSION['consumer']['itconsumer_id'];
} else {
    $consumer_id = $_SESSION['provider']['serviceprovider_id'];
}
$packageTypeName = getSubsTypeDetail($_POST["address_types"]);
$subscriptiontype_id = $packageTypeName[0];
$subscribertype_id = $packageTypeName[1];
$subscriptiondesc = $packageTypeName[2];
$subDay = $packageTypeName[3];
// building request xml
$xml = $mylphp->buildXML($myorder);
$requestXML = htmlspecialchars($xml);
//requestxml
// if debugging enabled
if (isset($_POST["debugging"])) {
    $myorder["debugging"] = "true";
}
//
//  # Send transaction. Use one of two possible methods  #
//  $result = $mylphp->process($myorder);       # use shared library model
$result = $mylphp->curl_process($myorder);
# use curl methods
//responsexml
$returnString = displayString($result);
// extracting AVS code from result XML
$avs_code = substr($result["r_avs"], 0, 3);
 public function run(Am_Paysystem_Result $result)
 {
     require_once dirname(__FILE__) . "/lphp.php";
     $mylphp = new lphp();
     $myorder["host"] = $this->getPlugin()->getConfig('testing') ? "staging.linkpt.net" : "secure.linkpt.net";
     $myorder["port"] = "1129";
     $myorder["keyfile"] = dirname(APPLICATION_CONFIG) . '/' . $this->getPlugin()->getConfig('keyfile');
     $myorder["configfile"] = $this->getPlugin()->getConfig('id');
     $myorder["ordertype"] = "SALE";
     $myorder["result"] = $this->getPlugin()->getConfig('testing') ? "GOOD" : "LIVE";
     # For a test, set result to GOOD, DECLINE, or DUPLICATE
     $myorder["cardnumber"] = $this->cc->cc_number;
     $myorder["cardexpmonth"] = $this->cc->getExpire('%1$02d');
     $myorder["cardexpyear"] = $this->cc->getExpire('%2$02d');
     $myorder["chargetotal"] = $this->doFirst ? $this->invoice->first_total : $this->invoice->second_total;
     $myorder["addrnum"] = preg_replace('/^D/', '', $this->cc->cc_street);
     $myorder["zip"] = $this->cc->cc_zip;
     if ($this->cc->getCvv()) {
         $myorder["cvmindicator"] = "provided";
         $myorder["cvmvalue"] = $this->cc->getCvv();
     }
     //if ($this->getPlugin()->getConfig('testing'))
     //    $myorder["debugging"] = "true";  # for development only - not intended for production use
     // uncomment it to get debug info to screen!
     $log = $this->getInvoiceLog();
     $log->add($mylphp->buildXML($myorder));
     $this->ret = $mylphp->curl_process($myorder);
     $log->add(print_r($this->ret, true));
     if ($this->ret['r_approved'] == 'APPROVED') {
         $result->setSuccess($this);
         $this->processValidated();
     } else {
         $result->setFailed(___("Payment failed") . ":" . $this->ret['r_error']);
     }
 }