i am using WAMP on Windows 2003 server, i am having problem in retreiving response from the https url by sending Post data to it using php curl.
i have turned on the mod_ssl module from php.ini for both php and apache.
Here is my code:
Code: Select all
$VPSProtocol = $_REQUEST['VPSProtocol'];
$TxType = $_REQUEST['TxType'];
$Vendor = $_REQUEST['Vendor'];
$VendorTxCode = $_REQUEST['VendorTxCode'];
$Description = $_REQUEST['Description'];
$Amount = $_REQUEST['Amount'];
$Currency = $_REQUEST['Currency'];
$CardHolder = $_REQUEST['CardHolder'];
$CardNumber = $_REQUEST['CardNumber'];
$ExpiryDate = $_REQUEST['ExpiryDate'];
$CardType = $_REQUEST['CardType'];
$CV2 = $_REQUEST['CV2'];
$BillingSurname = $_REQUEST['BillingSurname'];
$BillingFirstname = $_REQUEST['BillingFirstnames'];
$BillingAddress = $_REQUEST['BillingAddress1'];
$BillingCity = $_REQUEST['BillingCity'];
$BillingPostCode = $_REQUEST['BillingPostCode'];
$BillingCountry = $_REQUEST['BillingCountry'];
$BillingState = $_REQUEST['BillingState'];
$DeliverySurname = $_REQUEST['DeliverySurname'];
$DeliveryFirstname = $_REQUEST['DeliveryFirstnames'];
$DeliveryAddress = $_REQUEST['DeliveryAddress1'];
$DeliveryCity = $_REQUEST['DeliveryCity'];
$DeliveryPostCode = $_REQUEST['DeliveryPostCode'];
$DeliveryCountry = $_REQUEST['DeliveryCountry'];
$DeliveryState = $_REQUEST['DeliveryState'];
//set POST variables
$url = 'https://test.sagepay.com/gateway/service/vspdirect-register.vsp?';
$fields = array(
'VPSProtocol'=>urlencode($VPSProtocol),
'TxType'=>urlencode($TxType),
'Vendor'=>urlencode($Vendor),
'VendorTxCode'=>urlencode($VendorTxCode),
'Description'=>urlencode($Description),
'Amount'=>urlencode($Amount),
'Currency'=>urlencode($Currency),
'CardHolder'=>urlencode($CardHolder),
'CardNumber'=>urlencode($CardNumber),
'ExpiryDate'=>urlencode($ExpiryDate),
'CardType'=>urlencode($CardType),
'CV2'=>urlencode($CV2),
'BillingSurname'=>urlencode($BillingSurname),
'BillingFirstnames'=>urlencode($BillingFirstname),
'BillingAddress1'=>urlencode($BillingAddress),
'BillingCity'=>urlencode($BillingCity),
'BillingPostCode'=>urlencode($BillingPostCode),
'BillingCountry'=>urlencode($BillingCountry),
'BillingState'=>urlencode($BillingState),
'DeliverySurname'=>urlencode($DeliverySurname),
'DeliveryFirstnames'=>urlencode($DeliveryFirstname),
'DeliveryAddress1'=>urlencode($DeliveryAddress),
'DeliveryCity'=>urlencode($DeliveryCity),
'DeliveryPostCode'=>urlencode($DeliveryPostCode),
'DeliveryCountry'=>urlencode($DeliveryCountry),
'DeliveryState'=>urlencode($DeliveryState)
);
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string,'&');
$curl = curl_init();
$header[] = "Content-Type: application/x-www-form-URLEncoded";
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSLVERSION,3);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
$data = curl_exec($curl);
echo $data;
curl_close($curl);
Many Thanks in advance
maani