merchant-frontend-examples

ZZZ: Inactive/Deprecated
Log | Files | Refs

commit 9ea1d14d36e96bab9ebef689ce26223000aa2c2b
parent 9e2283eb0445b6f63379f87a1488ece8a606a972
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Mon, 21 Nov 2016 01:40:09 +0100

Adding /history handler

Diffstat:
Mphp/doc/tutorial.texi | 14+++++++-------
Mphp/history.php | 20+++++++++++++++++++-
2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/php/doc/tutorial.texi b/php/doc/tutorial.texi @@ -514,16 +514,16 @@ Our example frontend, implements this feature by orchestrating two parts: @itemize -@item The @code{history.php?days=<DAYSAGO>} script, whose @emph{<DAYSAGO>} +@item The @code{history.php?days=<DAYSAGO>} script, whose @code{days} parameter indicates how old the oldest returned transaction should - be in terms of days. This script, will then translate @emph{<DAYSAGO>} - in a timestamp, and issue the call to backend's @code{/history?date=<TIMESTAMP>}. - The data it receives from the backend is finally returned in - JSON format to the caller. + be in terms of days. The script will then translate @emph{<DAYSAGO>} + in a timestamp, and issue the call to backend's + @code{/history?date=<TIMESTAMP>}. The data it receives from the + backend is finally returned in JSON format to the caller. @item A JavaScript function, imported within @code{backoffice.html}, - that triggers @code{history.php} and modifies the current page - by adding a table showing what is returned. + that issues the HTTP GET to @code{/history.php?days=<DAYSAGO>} + and modifies the current page by adding a table showing the result. @end itemize See below both parts: diff --git a/php/history.php b/php/history.php @@ -1,5 +1,23 @@ <?php - // FIXME + include 'helpers.php'; + include 'backend.php'; + if (!isset($_GET['days'])) { + echo "<p>Please give 'days' parameter.</p>"; + return; + } + + $now = new DateTime(); + $now->subtract(new DateInterval(sprintf("P%sD", $_GET['days'])); + $response = get_to_backend("/history", + array("date"=>$now->getTimestamp())); + if (200 != $response["status_code"]){ + echo build_error($response, + "Backend error", + $response["status_code"]); + return; + } + + echo $response["body"]; ?>