1

Currently I am developing a payment gateway and I have to generate a curl request to payment gateway.

Below is my normal php code of curl to which payment gateway approving my request because I have set CURLOPT_INTERFACE option to my server address on which my site is being hosted.

$url = 'https://mypaymentgatewayurl';


//url-ify the data for the POST
$requestQuery = '';
$requestQuery .= '&order_id=ordernumber';
$requestQuery .= '&api_key=myapi';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch,CURLOPT_INTERFACE, $_SERVER['SERVER_ADDR']);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_POST, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS, $requestQuery);

//execute post
$result = curl_exec($ch);
echo 'curl output : <br>';
echo '<pre>';
print_r($result);

above php code is running without any problem and with desired output of approval.

Now problem starts here : I am not able to pass curl option in magento.

public function postBackCall($order_id,Zend_Http_Client_Adapter_Interface $httpAdapter = null) {
$configData = Mage::getStoreConfig('payment/gateway');
$logFileName = 'gateway.log';
$logEnabled = $configData['debug'];
try {
    $apiUrl = $configData['api_url']; //i.e.https://mypaymentgatewayurl
    $requestQuery = '';
    $requestQuery .= '&order_id='.$order_id;
    $requestQuery .= '&api_key='.Mage::helper('core')->decrypt($configData['api_key']);
    $config = array('timeout' => 60,'verifypeer' => FALSE,'verifyhost' => FALSE);
    $httpAdapter->setConfig($config);
    $options = array('CURLOPT_INTERFACE' => $_SERVER['SERVER_ADDR']);
    $httpAdapter->setOptions($options);
    $httpAdapter->write(Zend_Http_Client::POST, $apiUrl, '1.1', array(), $requestQuery);        
    $response = $httpAdapter->read();
    $httpAdapter->close();
} catch(Exception $e) {
    Mage::logException($e);
}
}

This is how my postbackcall method is being called from controller

$gatewaymodule->postBackCall($order_id,new Varien_Http_Adapter_Curl());

Payment gateway is rejecting my request due to CURLOPT_INTERFACE is not being set as option. How can I set option in magento? What have I done wrong? TIA

Regards

4

Try

$httpAdapter->addOption(CURLOPT_INTERFACE, $_SERVER['SERVER_ADDR']);

or as @Kamal mention remove quote from CURLOPT_INTERFACE int constant

$options = array(CURLOPT_INTERFACE => $_SERVER['SERVER_ADDR']); 

See /lib/Varien/Http/Adapter/Curl.php

/**
 * Add additional option to cURL
 *
 * @param  int $option      the CURLOPT_* constants
 * @param  mixed $value
 * @return Varien_Http_Adapter_Curl
 */
public function addOption($option, $value)
{
    $this->_options[$option] = $value;
    return $this;
}
0

A simple quote can give you pain. A silly mistake on line

$options = array(CURLOPT_INTERFACE => $_SERVER['SERVER_ADDR']); //see quote here

I hope this can be helpful to others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.