PHP Authorization for SecureNet Payment Gateway Using cURL

SecureNet just moved to a REST-based system for their payment system and it looks good and very easy to use, but setting up the initial authorization is a bit confusing based on the lack of documentation.

I used cURL to do the HTTP request and had PHP converted to JSON (unnecessary but helpful here) to send the data.


11.00,
"card" => array(
"number" => "4444 3333 2222 1111",
"cvv" => "999",
"expirationDate" => "04/2016",
"address" => array(
"line1" => "123 Main St.",
"city" => "Austin",
"state" => "TX",
"zip" => "78759"
),
"firstName" => "Jack",
"lastName" => "Test"
),
"extendedInformation" => array(
"typeOfGoods" => "PHYSICAL"),
"developerApplication" => array(
"deverloperId" => "12345678",
"version" => "1.2")
//the developerApplication array was missing from the documentation

);

$data_string = json_encode($data);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
'Authorization: Basic '. base64_encode('**SecurenetID**:**SecureNetKey**'),
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
));
//the HTTP Header is vital and SecureNet won't accept the request if this is incorrect and their error handling isn't explicit.
$response = curl_exec($ch);
curl_close($ch);
?>