function _commerce_amex_get_request in Commerce American Express Payment Gateway (Amex) 7
A wrapper for curl to be reused for Amex requests.
Parameters
string $url:
string $password:
array $data:
Return value
multitype:string
1 call to _commerce_amex_get_request()
- commerce_amex_update_transaction in includes/
commerce_amex.admin.inc - Menu callback.
File
- ./
commerce_amex.module, line 1733 - Implements American Express payment gateway for use in Drupal Commerce.
Code
function _commerce_amex_get_request($url, $merchant_id, $password, $data = array()) {
// Set a one-minute timeout for this script
set_time_limit(60);
$output = array();
$data_string = json_encode($data);
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_HEADER, 0);
curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
));
// Return it direct, don't print it out
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
// This connection will timeout in 30 seconds
curl_setopt($curlSession, CURLOPT_TIMEOUT, 30);
//The next two lines must be present for the kit to work with newer version of cURL
//You should remove them if you have any problems in earlier versions of cURL
curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curlSession, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curlSession, CURLOPT_USERPWD, ":" . $password);
//Send the request and store the result in an array
$rawresponse = curl_exec($curlSession);
$response = json_decode($rawresponse);
// Close the cURL session
curl_close($curlSession);
// Return the output
return $response;
}