You are here

function _commerce_amex_post_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

2 calls to _commerce_amex_post_request()
commerce_amex_3d_secure_callback in ./commerce_amex.module
Process callback response from merchant server
commerce_amex_cardonfile_save in ./commerce_amex.module
Request a token from Amex for a session and save the Card of File entity.

File

./commerce_amex.module, line 1638
Implements American Express payment gateway for use in Drupal Commerce.

Code

function _commerce_amex_post_request($url, $merchant_id, $password, $data = array()) {
  $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_POST, 1);
  curl_setopt($curlSession, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($curlSession, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string),
  ));
  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, ":" . $password);
  $rawresponse = curl_exec($curlSession);
  $response = json_decode($rawresponse);
  curl_close($curlSession);
  return $response;
}