summaryrefslogtreecommitdiff
path: root/src/frontend_blog
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2016-02-18 18:25:11 +0100
committerMarcello Stanisci <marcello.stanisci@inria.fr>2016-02-18 18:25:11 +0100
commit274723e3f9d02aaf5355724cdd05c75fb3f0738c (patch)
tree3bae7e5522e3ffe711fbe9b030f01409202dca14 /src/frontend_blog
parentf1e49844fd16dc55247ad716a21b961b2e4ddfc3 (diff)
downloadmerchant-274723e3f9d02aaf5355724cdd05c75fb3f0738c.tar.gz
merchant-274723e3f9d02aaf5355724cdd05c75fb3f0738c.tar.bz2
merchant-274723e3f9d02aaf5355724cdd05c75fb3f0738c.zip
Unifying blog's _offer and _fulfillment sources
Diffstat (limited to 'src/frontend_blog')
-rw-r--r--src/frontend_blog/articles/fs-essay.html8
-rw-r--r--src/frontend_blog/essay_cc-fulfillment.php14
-rw-r--r--src/frontend_blog/essay_cc-payment.html11
-rw-r--r--src/frontend_blog/essay_contract.php15
-rw-r--r--src/frontend_blog/essay_fulfillment.php131
-rw-r--r--src/frontend_blog/essay_pay.php18
6 files changed, 129 insertions, 68 deletions
diff --git a/src/frontend_blog/articles/fs-essay.html b/src/frontend_blog/articles/fs-essay.html
index b0bce3a5..1c79c7f8 100644
--- a/src/frontend_blog/articles/fs-essay.html
+++ b/src/frontend_blog/articles/fs-essay.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html>
+<!--DOCTYPE html>
<html lang="en">
<head>
<title>Blog site demonstration</title>
@@ -6,7 +6,7 @@
</head>
<body>
<header>
- <div id="logo">
+ <-div id="logo">
<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="darkcyan" stroke-width="6" fill="white" />
<text x="19" y="82" font-family="Verdana" font-size="90" fill="darkcyan">B</text>
@@ -16,8 +16,10 @@
</header>
<aside class="sidebar" id="left">
- </aside>
+ </aside-->
+<html>
+<body>
<div id="teaser" style="display: none;">
<p>
What is Free Software
diff --git a/src/frontend_blog/essay_cc-fulfillment.php b/src/frontend_blog/essay_cc-fulfillment.php
index 5026c2a9..ff154806 100644
--- a/src/frontend_blog/essay_cc-fulfillment.php
+++ b/src/frontend_blog/essay_cc-fulfillment.php
@@ -3,12 +3,6 @@
include '../frontend_lib/util.php';
include './blog_lib.php';
-session_start();
-if (!$_SESSION['cc_payment'])
-{
- echo "No session active";
- die();
-}
$article = get($_GET['article']);
if (null == $article)
{
@@ -16,7 +10,11 @@ if (null == $article)
echo "Bad request (no article specified)";
return;
}
-$article_doc = get_article($article);
-echo $article_doc->saveHTML();
+session_start();
+$payments = &pull($_SESSION, "payments", array());
+$payments[$article] = "payed";
+$fulfillment_url = url_rel("essay_fulfillment.php");
+header("Location: $fulfillment_url");
+die();
?>
diff --git a/src/frontend_blog/essay_cc-payment.html b/src/frontend_blog/essay_cc-payment.html
index d9cbd7c9..fe20fb4a 100644
--- a/src/frontend_blog/essay_cc-payment.html
+++ b/src/frontend_blog/essay_cc-payment.html
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html lang="en">
+<!--html lang="en">
<head>
<title>Enter your details</title>
<link rel="stylesheet" type="text/css" href="style.css">
@@ -20,7 +20,7 @@
</aside>
<section id="main">
- <article>
+ <article-->
<h1>Enter your details</h1>
<p>We need a few details before proceeding with credit card payment</p>
<form>
@@ -35,7 +35,10 @@
<form method="post" action="essay_cc-fulfillment.php?article={article}">
<input type="submit"></input>
</form>
- </article>
+ <script type="text/javascript">
+ {jscode}
+ </script>
+ <!--/article>
</section>
</body>
-</html>
+</html-->
diff --git a/src/frontend_blog/essay_contract.php b/src/frontend_blog/essay_contract.php
index d4a2e990..e813d91b 100644
--- a/src/frontend_blog/essay_contract.php
+++ b/src/frontend_blog/essay_contract.php
@@ -39,11 +39,18 @@ $teatax = array ();
$transaction_id = rand(0, 1001);
$fulfillment_url = url_rel("essay_fulfillment.php")
- . '&uuid=${H_contract}'
. '&timestamp=' . $now->getTimestamp()
. '&tid=' . $transaction_id;
file_put_contents("/tmp/ffil", $fulfillment_url);
+
+ $dump = "curr: " . $MERCHANT_CURRENCY . " tid: " . $transaction_id
+ . " desc: " . trim($teaser->nodeValue)
+ . " article: " . $article . " now: " . $now->getTimestamp()
+ . " ffil: " . $fulfillment_url . "\n";
+
+file_put_contents("/tmp/dumpster_contr", $dump, FILE_APPEND);
+
$contract_json = generate_contract($amount_value,
$amount_fraction,
$MERCHANT_CURRENCY,
@@ -54,7 +61,7 @@ $contract_json = generate_contract($amount_value,
$teatax,
$now,
$fulfillment_url);
-$resp = give_to_backend($_SERVER["HTTP_HOST"],
+$resp = give_to_backend($_SERVER['HTTP_HOST'],
"backend/contract",
$contract_json);
@@ -77,9 +84,7 @@ else
$hc = $got_json["H_contract"];
session_start();
$payments = &pull($_SESSION, "payments", array());
- $payments[$hc] = array(
- 'article' => $article,
- );
+ $payments[$article] = "inprogress";
echo $resp->body->toString();
}
?>
diff --git a/src/frontend_blog/essay_fulfillment.php b/src/frontend_blog/essay_fulfillment.php
index 21ee281a..d172b2b5 100644
--- a/src/frontend_blog/essay_fulfillment.php
+++ b/src/frontend_blog/essay_fulfillment.php
@@ -16,10 +16,67 @@
-->
<html lang="en">
<head>
- <title>Taler's "Demo" Shop</title>
- <link rel="stylesheet" type="text/css" href="style.css">
+ <title>Taler's "Demo" Blog</title>
+ <link rel="stylesheet" type="text/css" href="style.css"-->
<script type="application/javascript" src="taler-presence.js"></script>
<script type="application/javascript">
+ function handle_contract(json_contract) {
+ var cEvent = new CustomEvent('taler-contract',
+ {detail: json_contract});
+ document.dispatchEvent(cEvent);
+ };
+
+ function get_contract(article) {
+ var contract_request = new XMLHttpRequest();
+
+ contract_request.open("GET",
+ "essay_contract.php?article=" + article,
+ true);
+ contract_request.onload = function (e) {
+ if (contract_request.readyState == 4) {
+ if (contract_request.status == 200) {
+ console.log("response text:",
+ contract_request.responseText);
+ handle_contract(contract_request.responseText);
+ } else {
+ alert("Failure to download contract from merchant " +
+ "(" + contract_request.status + "):\n" +
+ contract_request.responseText);
+ }
+ }
+ };
+ contract_request.onerror = function (e) {
+ alert("Failure requesting the contract:\n"
+ + contract_request.statusText);
+ };
+ contract_request.send();
+ }
+
+ function has_taler_wallet_cb(aEvent)
+ {
+ var article = document.getElementById('article-name');
+ get_contract(article.value);
+ };
+
+ function signal_taler_wallet_onload()
+ {
+ var eve = new Event('taler-probe');
+ document.dispatchEvent(eve);
+ };
+
+ document.addEventListener("taler-wallet-present",
+ has_taler_wallet_cb,
+ false);
+
+ // Register event to be triggered by the wallet when it gets enabled while
+ // the user is on the payment page
+ document.addEventListener("taler-load",
+ signal_taler_wallet_onload,
+ false);
+
+
+
+
function executePayment(H_contract, pay_url, offering_url) {
var detail = {
H_contract: H_contract,
@@ -32,16 +89,15 @@
</script>
</head>
<body>
-<!--
<header>
<div id="logo">
<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="darkcyan" stroke-width="6" fill="white" />
- <text x="19" y="82" font-family="Verdana" font-size="90" fill="darkcyan">S</text>
+ <text x="19" y="82" font-family="Verdana" font-size="90" fill="darkcyan">B</text>
</svg>
</div>
- <h3>Toy Store - Product Page</h3>
+ <h1>Taler's "Demo" Blog</h1>
</header>
<aside class="sidebar" id="left">
@@ -49,10 +105,10 @@
<section id="main">
<article>
- -->
<?php
-// TODO return a mock CC payment page if no wallet in place
include '../frontend_lib/util.php';
+include '../frontend_lib/merchants.php';
+include '../frontend_lib/config.php';
include './blog_lib.php';
$article = get($_GET['article']);
@@ -61,54 +117,67 @@ if (null == $article){
echo "<p>Bad request (article missing)</p>";
return;
}
-$hc = get($_GET['uuid']);
-if (null == $article){
- http_response_code(400);
- echo "<p>Bad request (UUID missing)</p>";
- return;
-}
session_start();
$payments = get($_SESSION['payments'], array());
-$my_payment = get($payments[$hc]);
+$my_payment = get($payments[$article]);
$pay_url = url_rel("essay_pay.php");
$offering_url = url_rel("essay_offer.php", true);
$offering_url .= "?article=$article";
-file_put_contents("/tmp/essay_pay-offer", "pay URL:" . $payurl . "\noffer URL:" . $offering_url);
-if (true !== get($my_payment["is_payed"], false) || null === $my_payment)
+if ("payed" != $my_payment || null === $my_payment)
{
$tid = get($_GET['tid']);
$timestamp = get($_GET['timestamp']);
- // FIXME article name should be "melted" in the hash
- // TODO reconstruct *here* the contract, hash it, and save it in the state
-
+ // 1st time
if (null == $tid || null == $timestamp){
- // CC case
- $_SESSION['cc_payment'] = true;
- $cc_page = template("./essay_cc-payment.html", array('article' => $article));
+ $js_code = "get_contract(\"$article\")";
+ $cc_page = template("./essay_cc-payment.html", array('article' => $article, 'jscode' => $js_code));
echo $cc_page;
die();
+ }
+ // restore
+ $now = new DateTime();
+ $now->setTimestamp(intval($timestamp));
+ $contract_rec = generate_contract(0,
+ 50000,
+ $MERCHANT_CURRENCY,
+ intval($tid),
+ trim(get_teaser($article)->nodeValue),
+ $article,
+ $article,
+ array(),
+ $now,
+ get_full_uri());
+
+ $resp = give_to_backend($_SERVER['HTTP_HOST'],
+ "backend/contract",
+ $contract_rec);
+ if ($resp->getResponseCode() != 200)
+ {
+ echo json_encode(array(
+ 'error' => "internal error",
+ 'hint' => "non hashable contract",
+ 'detail' => $resp->body->toString()
+ ), JSON_PRETTY_PRINT);
+ die();
}
- echo "<p>Paying ... at $pay_url </p>";
- echo "<script>executePayment('$hc', '$pay_url', '$offering_url');</script>";
+ $hc = json_decode($resp->body->toString(), true)['H_contract'];
+ $js_code = "executePayment('$hc', '$pay_url', '$offering_url')";
+ $cc_page = template("./essay_cc-payment.html", array('article' => $article, 'jscode' => $js_code));
+ echo $cc_page;
return;
-}
+ }
// control here == article payed
-$article = $my_payment["article"];
-
$article_doc = get_article($article);
-echo $article_doc->saveHTML();
-
+echo $article_doc->saveHTML($article_doc->getElementById("full-article"));
?>
- <!--
</article>
</section>
- -->
</body>
</html>
diff --git a/src/frontend_blog/essay_pay.php b/src/frontend_blog/essay_pay.php
index e84e3597..9c711bbf 100644
--- a/src/frontend_blog/essay_pay.php
+++ b/src/frontend_blog/essay_pay.php
@@ -23,17 +23,6 @@ include("../frontend_lib/merchants.php");
include("../frontend_lib/util.php");
include("./blog_lib.php");
-$hc = get($_GET["uuid"]);
-if (empty($hc))
-{
- http_response_code(400);
- echo json_encode(array(
- "error" => "missing parameter",
- "parameter" => "uuid"
- ));
- return;
-}
-
$article = get($_GET["article"]);
if (empty($article))
{
@@ -46,11 +35,9 @@ if (empty($article))
}
$deposit_permission = file_get_contents('php://input');
-file_put_contents('/tmp/pay.dbg', 'about to pay\n', FILE_APPEND);
$resp = give_to_backend($_SERVER['HTTP_HOST'],
"backend/pay",
$deposit_permission);
-file_put_contents('/tmp/pay.dbg', 'backend respd\n', FILE_APPEND);
$status_code = $resp->getResponseCode();
// Our response code is the same we got from the backend:
@@ -70,8 +57,5 @@ if ($status_code != 200)
session_start();
$payments = &pull($_SESSION, "payments", array());
-$payments[$hc] = array(
- 'article' => $article,
- 'is_payed' => true
-);
+$payments[$article] = "payed";
?>