function _commerce_amex_request_session 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
2 calls to _commerce_amex_request_session()
- commerce_amex_cardonfile_update_form in ./
commerce_amex.module - Builds the form for updating cardonfile data.
- commerce_amex_hosted_submit_form_submit in ./
commerce_amex.module - Payment method callback: submit form submission.
File
- ./
commerce_amex.module, line 1489 - Implements American Express payment gateway for use in Drupal Commerce.
Code
function _commerce_amex_request_session($payment_method) {
// Set a one-minute timeout for this script
set_time_limit(60);
$url = $payment_method['settings']['txn_url'] . AMEX_TXN_PATH . $payment_method['settings']['merchant_id'] . '/session';
// Open the cURL session
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_HEADER, 0);
curl_setopt($curlSession, CURLOPT_POST, 1);
curl_setopt($curlSession, CURLOPT_POSTFIELDS, '');
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlSession, CURLOPT_TIMEOUT, 30);
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, ":" . $payment_method['settings']['password']);
//Send the request and store the result in an array
$rawresponse = curl_exec($curlSession);
$response = json_decode($rawresponse);
watchdog('commerce_amex', print_r(curl_getinfo($curlSession), TRUE));
// Close the cURL session
curl_close($curlSession);
// Return the output
return $response;
}