commit 671572312437e8da7ff2099a7f565c177f80767e
parent cac920b79aa3aa5e572ce27b048ded7cf36ba500
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Wed, 16 Nov 2016 18:12:19 +0100
more on track-transactions. Time prettifier.
Diffstat:
4 files changed, 71 insertions(+), 2 deletions(-)
diff --git a/php/backend.php b/php/backend.php
@@ -4,7 +4,7 @@
include_once 'config.php';
include_once 'helpers.php';
-/**
+ /**
* 'body' is an object, representing the JSON to POST. NOTE: we do NOT
* rely on a more structured way of doing HTTP, like the one offered by
* pecl_http, as its installation was NOT always straightforward.
@@ -28,4 +28,21 @@
return array("status_code" => curl_getinfo($c, CURLINFO_HTTP_CODE),
"body" => $r);
}
+
+ function get_to_backend($backend_uri, $args){
+ $path = sprintf("%s?%s", $backend_url, http_build_query($args));
+ $c = curl_init(url_join ($GLOBALS['BACKEND'], $path));
+
+ $options = array(CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_CUSTOMREQUEST => "GET",
+ CURLOPT_SSL_VERIFYHOST => false,
+ CURLOPT_SSL_VERIFYPEER => false);
+ curl_setopt_array($c, $options);
+ $r = curl_exec($c);
+ file_put_contents("/tmp/php.out", print_r($r, true));
+ return array("status_code" => curl_getinfo($c, CURLINFO_HTTP_CODE),
+ "body" => $r);
+ }
+
+
?>
diff --git a/php/config.php b/php/config.php
@@ -2,7 +2,7 @@
// This config file is in the public domain.
- $BACKEND = "http://localshop/";
+ $BACKEND = "http://backend.demo.taler.net/";
// The currency must match the one used by the backend.
$CURRENCY = "KUDOS";
diff --git a/php/helpers.php b/php/helpers.php
@@ -22,4 +22,14 @@
// be "HTTP/1.1".
return $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$path;
}
+
+
+ function get_pretty_date($taler_date){
+ $match = array();
+ $timestamp = preg_match('/\/Date\(([0-9]+)\)\//', $taler_date, $match);
+ $date = new DateTime();
+ $date->setTimestamp(intval($match[1]));
+ return $date->format('d/M/Y H:i:s');
+
+ }
?>
diff --git a/php/track-transaction.php b/php/track-transaction.php
@@ -0,0 +1,42 @@
+<?php
+
+ include 'copying.php';
+ include 'error.php';
+ include 'backend.php';
+
+
+ if (!isset($_GET['tid'])){
+ build_error(array("body" => "No transaction ID given"),
+ "tid argument missing",
+ 400);
+ return;
+ }
+
+ $response = get_to_backend("/track/transaction",
+ array("id" => intval($_GET['id'])));
+ if (!in_array(array(200, 202)) $response["status_code"]){
+ echo build_error($response,
+ "Backend error",
+ $response["status_code"]);
+ return;
+ }
+
+ // Render HTML
+ http_response_code($response["status_code"]);
+ if (202 == $response["status_code"]){
+ echo "<p>The exchange accepted the transactioin.
+ The estimated time for when the related wire transfer
+ is to be performed is: $pretty_time</p>";
+ return;
+ }
+
+ echo "<ul>";
+ foreach (json_decode($response["body"]) as $entry){
+ $pretty_date = get_pretty_date($entry->date);
+ echo sprintf("<li>Wire transfer ID: %s, date: %s</li>",
+ $entry->wtid,
+ $pretty_date);
+ }
+ echo "</ul>";
+
+?>