From bfac37697930c75e2cba0180ffcd46345f0eb361 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Fri, 7 Aug 2015 19:40:25 +0200 Subject: adapting the frontend to the new architecture --- src/backend/taler-merchant-httpd.c | 1 + src/frontend/cert.php | 70 +++++++++++++++++-- src/frontend/checkout.php | 137 ++++++++++++++----------------------- src/frontend/shopping.html | 13 ++-- 4 files changed, 123 insertions(+), 98 deletions(-) diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 4dfb71d1..9ac225b5 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -485,6 +485,7 @@ url_handler (void *cls, void **connection_cls) { + printf ("%s\n", url); unsigned int status; unsigned int no_destroy; json_int_t prod_id; diff --git a/src/frontend/cert.php b/src/frontend/cert.php index 3b719b24..a330d76e 100644 --- a/src/frontend/cert.php +++ b/src/frontend/cert.php @@ -18,15 +18,71 @@ */ -// Here goes all the Taler pay logic +/* + + Here goes all the Taler paying logic. The steps are + + 1. recover the session + + 2. generate the JSON to forward to the backend + + 3. route back to the wallet the certificate just gotten + +*/ // recover the session - session_start(); - if(!isset($_SESSION['contract'])){ - http_response_code(404); - echo "Sorry page.."; - } - else echo $_SESSION['contract']; +session_start(); +if(!isset($_SESSION['maydonate'])){ + http_response_code(404); + echo "Please try to donate before getting to this page :)"; +} + +else{ + // fake product id + $p_id = rand(0,1001); + // generate a transaction/certificate id. In production context, it's wishable to + // record this value + $trans_cert_id = rand(0, 1001); + // fake a human readable description of this deal + $desc = "donation aimed to stop the ants' massacre on hicking paths"; + // fake the price's integer (actually, the system is testishly suited for just 10 EUR coins) + $value = 10; + // fake the price's fractional + $fraction = 0; + // hardcode the currency + $currency = "EUR"; + + // pack the JSON + $json = json_encode (array ('desc' => $desc, 'product' => $p_id, 'cid' => $trans_cert_id, + 'price' => array ('value' => $value, + 'fraction' => $fraction, + 'currency' => $currency))); + // test + // echo $json; + // send to backend + /* // _very_ problematic + $http_obj = new HttpRequest; + $http_obj.setMethod (METH_GET); + //$http_obj.setBody ($json); + $http_obj.send (); + $http_obj.setUrl ("http://" . $SERVER["SERVER_NAME"] . "/backend" . "/hello"); + $status = $http_obj.getResponseHeader ('status'); + */ + $client = new http\Client; + $certificate = http_post_data ("http://" . $SERVER["SERVER_NAME"] . "/backend" . "/hello", + null, $response); + $status_code = $response['response_code']; + + set_response_code ($status_code); + + if ($status != 200) + echo "Some error occurred during this operation"; + // send the contract back to the wallet without touching it + else echo $http_obj.getResponseBody (); + + +} + ?> diff --git a/src/frontend/checkout.php b/src/frontend/checkout.php index b2e11ac0..fc11b35a 100644 --- a/src/frontend/checkout.php +++ b/src/frontend/checkout.php @@ -22,46 +22,32 @@ --> - + 1. retrieve the name of who will receive this donation -"; + 3. create a session - // JSON certificate generation matching the product being sold - $item = $_POST['group0']; - - $toJSON = array('vendor' => "$item provider", 'item' => $item, 'price'=> rand(5, 66) . ' €', 'payUrl' => "http://" . $_SERVER['SERVER_NAME'] . "/payler/"); + 4. (JavaScript) implement the "checkout" button for the sole Taler way. + Actually, this button's duty is to notice this web portal that the customer + wants to see a certificate, and optionally to pay. + --> - // save certificate (retrievable through file naming convention) to the disk - // file_put_contents(getcwd() . "/cert." . $transId, json_encode($toJSON)); - - // time-expirable (15') tracking cookie definition - // setcookie("talkie", $transId, time()+ 15*60); - - // create session +You Card
Card Me
Taler
- + - - - - diff --git a/src/frontend/shopping.html b/src/frontend/shopping.html index 07c8a2e4..8853eef8 100644 --- a/src/frontend/shopping.html +++ b/src/frontend/shopping.html @@ -4,6 +4,7 @@ +

Donation Page

-

Please choose a project and an amount you which to donate.

+

Please choose a project and an amount you whish to donate.


- Taler
- Gnunet
- INRIA


+Taler
+Gnunet
+INRIA


EUR

@@ -39,7 +40,7 @@ EUR