<?php
// Script to create a signature
define('API_BASE_URL', 'http://api.allopass.com/rest');
define('API_KEY', '01bc7a393c0cb427c0c4d96e5c0d9c65');
//define('API_KEY', '01bc7a393c0cb427c0c4d96e5c0d9c65');
define('API_SECRET_KEY', '4e06989e52c2bd5b569f4c55ac2a4ad4');
//define('API_KEY', '999312cf980c9e913bd75bf3c4f0bbe1');
//define('API_SECRET_KEY', '91c28d91bf037ab762322e898a5a11c1');

define('API_HASH_FUNCTION', 'sha1');
date_default_timezone_set('UTC');
// STEPS 1 and 2: Construction of query parameters
$queryParameters = array(
'site_id' =>222616,
//'category' => array('mobile-payment'),
//'product_id' =>1314200,
//'pricepoint_id' => '25',
'country' => 'ES',
//'amount' => '7.08',
//'format' => 'json',
'api_key' => API_KEY,
'api_hash' => API_HASH_FUNCTION,
//'api_ts' => strtotime("-1 hour")
'api_ts' => time()
);
// STEP 3 : Sort parameters by ascending alphabetical order by name of parameter
ksort($queryParameters);
/* STEP 4
* Prepare a string to hash
* with the hash function "API_HASH_FUNCTION"
*/
$stringToHash = '';
foreach ($queryParameters as $parameter =>$value) {
$stringToHash .= $parameter . (is_array($value) ? implode('', $value) : $value);
}
$stringToHash .= API_SECRET_KEY;
// STEP 5: Creation of signature
$signature = hash(API_HASH_FUNCTION, $stringToHash);
// STEP 6 : Generating URL
$queryParameters['api_sig'] = $signature;
$url = API_BASE_URL . '/onetime/pricing?'. http_build_query($queryParameters);
//$url = API_BASE_URL . '/onetime/discrete-pricing?'. http_build_query($queryParameters);
//$url = API_BASE_URL . '/website/?'. http_build_query($queryParameters);
//$url = API_BASE_URL . '/transaction/prepare'; //. http_build_query($queryParameters);
echo $url;
$sock = curl_init($url);
curl_setopt_array($sock, array(
CURLOPT_HEADER =>true,
CURLOPT_RETURNTRANSFER =>true,
CURLOPT_FOLLOWLOCATION =>false,
CURLOPT_CONNECTTIMEOUT =>10,
CURLOPT_LOW_SPEED_TIME =>10,
CURLOPT_TIMEOUT =>10,
//CURLOPT_POST => true,
//CURLOPT_POSTFIELDS => http_build_query($queryParameters)

));
$response = curl_exec($sock);
//header('Content-Type: text/xml; charset=UTF-8');
echo $response;
if (0< ($curlErrno = curl_errno($sock))) {
trigger_error("CURL Error ($curlErrno): " . curl_error($sock), E_USER_NOTICE);
//header('Location: /error/unavailable.php');
}
exit();