function checkfermopoint_merchant_callback()
{
echo "<h1>Riepilogo ticket Fermo!Point</h1>";
$shippings_wc = new WC_Shipping();
$shippings = $shippings_wc->load_shipping_methods();
$fermopoint = $shippings["Fermo!Point"];
//echo json_encode($fermopoint->settings);
$fermopoint_settings = $fermopoint->settings;
$account_id = $fermopoint_settings["FERMOPOINT_ACCOUNT_ID"];
$account_secret = $fermopoint_settings["FERMOPOINT_ACCOUNT_SECRET"];
$sandbox = $fermopoint_settings["sandbox"];
$url = $sandbox == "yes" ? "http://www.sandbox.fermopoint.it/api/v1.2/merchant" : "http://api.fermopoint.it/api/v1.2/merchant";
$ts = gmdate('Y-m-d\\TH:i:s.u\\Z');
$auth_token = hash_hmac("sha256", (string) $ts, (string) $account_id . $account_secret, false);
$request_url = '{
"client_id": "' . $account_id . '",
"ts": "' . $ts . '",
"auth_token": "' . $auth_token . '",
"data":{}
}';
$request = json_encode(array("client_id" => $account_id, "auth_token" => $auth_token, "ts" => $ts, "data" => array()));
$httpHeader = array("Content-Type: application/json; charset=\"utf-8\"", "Accept: text/json");
$ch = curl_init();
$connect_timeout = 5;
//sec
$base_time_limit = (int) ini_get('max_execution_time');
if ($base_time_limit < 0) {
$base_time_limit = 0;
}
$time_limit = $base_time_limit - $connect_timeout - 2;
if ($time_limit <= 0) {
$time_limit = 20;
//default
}
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connect_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $time_limit);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
if (!isset($info['http_code'])) {
$info['http_code'] = '';
}
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if (curl_errno($ch)) {
$result = array('http_code' => $info['http_code'], 'status' => 'ERROR1', 'errno' => $curl_errno, 'error' => $curl_error, 'result' => NULL);
} else {
$ret = json_decode($result);
}
//var_dump($result);
//var_dump($ret);
?>
<h2>Crediti restati: <?php
echo $ret->credits;
?>
</h2>
<h2>Ordini totali: <?php
echo $ret->orders_count;
?>
</h2>
<table>
<?php
$orders = $ret->orders;
if (count($orders) > 0) {
foreach ($orders as $order) {
?>
<tr>
<?php
foreach ($order as $col) {
?>
<td><?php
echo $col;
?>
</td><?php
}
?>
</tr>
<?php
}
}
?>
</table>
<?php
curl_close($ch);
}