I created a test account at
https://demo.globalgatewaye4.firstdata.com/main
account: epiphany515
password: ed123456
HMAC Key: nI1DP44IWQqLPRZfj0NGe19OISSRLvsP
Key Id: 268922
Gateway ID: AJ4853-01
Password: 57zg482f7h03ppwq592ii00i5dpddbf2
Here is my code:
=================================================================================================================
firstData.php
<?php
class FirstData {
protected $host = "api.demo.globalgatewaye4.firstdata.com";
// protected $host = "api.globalgatewaye4.firstdata.com";
protected $protocol = "https://";
protected $uri = "/transaction/v12";
/* Modify this acording to your firstdata api stuff */
//test
protected $hmackey = "nI1DP44IWQqLPRZfj0NGe19OISSRLvsP";
protected $keyid = "268922";
protected $gatewayid = "AJ4853-01";
protected $password = "57zg482f7h03ppwq592ii00i5dpddbf2";
//live
/*
protected $hmackey = "A3Rh6ArAVY7tetLmyy1TE8jfWxS89qQJ";
protected $keyid = "395933";
protected $gatewayid = "D60515-01";
protected $password = "25gil1mlju92w1j8m8qh6b223l905j1p";
*/
public function request() {
$location = $this->protocol . $this->host . $this->uri;
$request = array(
'transaction_type' => "00",
'amount' => 10.00,
'cc_expiry' => "0419",
'cc_number' => '4111111111111111',
'cardholder_name' => 'Test',
'reference_no' => '23',
'customer_ref' => '11',
'reference_3' => '234',
'gateway_id' => $this->gatewayid,
'password' => $this->password,
);
$content = json_encode($request);
// var_dump($content);
$gge4Date = strftime("%Y-%m-%dT%H:%M:%S", time()) . 'Z';
$contentType = "application/json";
$contentDigest = sha1($content);
$contentSize = sizeof($content);
$method = "POST";
$hashstr = "$method\n$contentType\n$contentDigest\n$gge4Date\n$this->uri";
$authstr = 'GGE4_API ' . $this->keyid . ':' . base64_encode(hash_hmac("sha1", $hashstr, $this->hmackey, true));
$headers = array(
"Content-Type: $contentType",
"X-GGe4-Content-SHA1: $contentDigest",
"X-GGe4-Date: $gge4Date",
"Authorization: $authstr",
"Accept: $contentType"
);
//Print the headers we area sending
// var_dump($headers);
//CURL stuff
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $location);
//Warning ->>>>>>>>>>>>>>>>>>>>
/* Hardcoded for easier implementation, DO NOT USE THIS ON PRODUCTION!! */
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//Warning ->>>>>>>>>>>>>>>>>>>>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
//This guy does the job
$output = curl_exec($ch);
//echo curl_error($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = $this->parseHeader(substr($output, 0, $header_size));
$body = substr($output, $header_size);
curl_close($ch);
//Print the response header
var_dump($body);
/* If we get any of this X-GGe4-Content-SHA1 X-GGe4-Date Authorization
* then the API call is valid */
if (isset($header['authorization'])) {
//Ovbiously before we do anything we should validate the hash
var_dump(json_decode($body));
}
//Otherwise just debug the error response, which is just plain text
else {
echo $body;
}
}
private function parseHeader($rawHeader) {
$header = array();
//http://blog.motane.lu/2009/02/16/exploding-new-lines-in-php/
$lines = preg_split('/\r\n|\r|\n/', $rawHeader);
foreach ($lines as $key => $line) {
$keyval = explode(': ', $line, 2);
if (isset($keyval[0]) && isset($keyval[1])) {
$header[strtolower($keyval[0])] = $keyval[1];
}
}
return $header;
}
}
$firstdata = new FirstData();
$firstdata->request();
=================================================================================================================
test.php
<?php
$gatewayid = "AJ4853-01"; // insert gateway_id
$password = "57zg482f7h03ppwq592ii00i5dpddbf2"; // insert password
$transactionType = "00"; // transaction type
$amount = "900.00"; // amount to charge
$cardnumber = "4111111111111111"; //test creditcard number
$expiration = "1118"; // any expiration date
$name = ""; // insert card holder name
$HMAC_KEY = "nI1DP44IWQqLPRZfj0NGe19OISSRLvsP"; // insert HMAC key
$KEY_ID = "268922"; // insert key id;
$url = "https://api.demo.globalgatewaye4.firstdata.com/transaction/v14";
$data = array(
"gateway_id" => $gatewayid,
"password" => $password,
"transaction_type" => $transactionType,
"amount" => $amount,
"cc_number" => $cardnumber,
"cc_expiry" => $expiration,
"cardholder_name" => $name
);
$data_string = json_encode($data);
$content_type = 'application/json; charset=UTF-8';
$hashtime = gmdate("c");
$content_digest = sha1($data_string);
$api_uri = '/transaction/v14';
$hashstr = "POST\n" . $content_type . "\n" . $content_digest . "\n" . $hashtime . "\n" . $api_uri;
$authstr = base64_encode(hash_hmac("sha1", $hashstr, $HMAC_KEY, TRUE));
$options = array(
'http' => array(
'header' => "Content-Type:" . $content_type . "\r\n" .
"Accept: application/json\r\n" .
"Authorization: GGE4_API " . $KEY_ID . ":" . $authstr . "\r\n" .
"X-GGe4-Date:" . $hashtime . "\r\n" .
"X-GGe4-Content-SHA1:" . $content_digest,
'method' => 'POST',
'content' => $data_string
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$data = json_decode($result);
print_r($data);
Hi Tan,
Since this question is related to Payeezy gateway, please send this query to payeezy.gateway.support@firstdata.com also.
Regards,
Rohit
Hi,
I register a sandbox merchant. But I cannot find the "Gateway ID".
I want to use First Data Payeezy for my WooCommerce.
Please help
Hi Nguyen,
Login to https://globalgatewaye4.firstdata.com --> go to Administration --> Terminals --> click on the terminal --> you will see the Gateway ID.
Regards,
Payeezy team