merchant-frontend-examples

ZZZ: Inactive/Deprecated
Log | Files | Refs

commit f8c0df8630e2c54f302d988280a666bb703a138f
parent 671572312437e8da7ff2099a7f565c177f80767e
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Wed, 16 Nov 2016 21:54:13 +0100

track-transfer

Diffstat:
Mphp/helpers.php | 16+++++++++++-----
Mphp/track-input.php | 1+
Aphp/track-transfer.php | 46++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/php/helpers.php b/php/helpers.php @@ -25,11 +25,17 @@ 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'); + $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'); + } + function get_amount($taler_amount){ + $PRECISION = 100000000; + $fraction = $taler_amount->fraction / $PRECISION; + $number = $taler_amount->value + $fraction; + return sprintf("%s %s", $number, $taler_amount->currency); } ?> diff --git a/php/track-input.php b/php/track-input.php @@ -13,6 +13,7 @@ </form> <form action='/track-transfer.php' method='GET'> <input type='text' name='wtid'><> + <input type='text' name='exchange'><> <input type='submit' value='Track transfer'></input> </form> </body> diff --git a/php/track-transfer.php b/php/track-transfer.php @@ -0,0 +1,46 @@ +<?php + + include 'copying.php'; + include 'error.php'; + include 'backend.php'; + + + if (!isset($_GET['wtid']) or !isset($_GET['exchange']))){ + build_error(array("body" => "Missing parameter"), + "'wtid' or 'exchange' has not been submitted", + 400); + return; + } + + $wtid = $_GET['wtid']; + $response = get_to_backend("/track/transfer", + array("wtid" => $wtid, + "exchange" => $_GET['exchange'])); + if (!in_array(array(200, 402)) $response["status_code"]){ + echo build_error($response, + "Backend error", + $response["status_code"]); + return; + } + + // Render HTML + http_response_code($response["status_code"]); + if (402 == $response["status_code"]){ + echo "<p>The backend detected that exchange provided + conflicting information about WTID $wtid. + Refer to exchange's operator.</p>"; + return; + } + $json_response = json_decode($response["body"]); + + $pretty_date = get_pretty_date($json_response->execution_time); + $amount = get_amount($json_response->total); + echo "<p>$wtid: $amount transferred on $pretty_date. + The list of Taler transactions involved in $wtid is shown below:</p>"; + + echo "<ul>"; + foreach ($json_response->deposits as $entry){ + echo sprintf("<li>Transaction id: %s", $entry->transaction_id); + } + echo "</ul>"; +?>