I am integrating Payment gateway. For that one if I use the fopen the data returns correctly. I need to use curl instead of fopen. But I am unable to get the result with curl.
fopen code is like this
$url = "https://test.ctpe.net/frontend/GenerateToken";
$data = "SECURITY.SENDER=xxxxxx" .
"&TRANSACTION.CHANNEL=xxx" .
"&TRANSACTION.MODE=xxxx_TEST" .
"&USER.LOGIN=xxxx" .
"&USER.PWD=xxxx" .
"&PAYMENT.TYPE=xxx" .
"&PRESENTATION.AMOUNT=xxxx" .
"&PRESENTATION.CURRENCY=xxxx" .
"&IDENTIFICATION.TRANSACTIONID=xxxxx" ;
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
Here Curl Code
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json','Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
$response = curl_exec($ch);
curl_close($ch);
This will returns Format Error data. Please help me. Thanks in advance.