diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/merchant.conf | 2 | ||||
-rw-r--r-- | src/frontend_blog/essay_contract.php | 10 | ||||
-rw-r--r-- | src/frontend_blog/essay_fulfillment.php | 28 | ||||
-rw-r--r-- | src/frontend_blog/essay_offer.php | 53 | ||||
-rw-r--r-- | src/frontend_blog/essay_pay.php | 3 | ||||
-rw-r--r-- | src/frontend_blog/index.html | 2 |
6 files changed, 72 insertions, 26 deletions
diff --git a/src/backend/merchant.conf b/src/backend/merchant.conf index 93d9fbba..b7e92e89 100644 --- a/src/backend/merchant.conf +++ b/src/backend/merchant.conf @@ -25,7 +25,7 @@ EDATE = 3 week DB = postgres [mint-taler] -URI = http://mint.demo.taler.net/ +URI = http://mint.test.taler.net/ MASTER_KEY = Q1WVGRGC1F4W7RYC6M23AEGFEXQEHQ730K3GG0B67VPHQSRR75H0 # Auditors must be in sections "auditor-", the rest of the section diff --git a/src/frontend_blog/essay_contract.php b/src/frontend_blog/essay_contract.php index 5c6d3b41..71872d25 100644 --- a/src/frontend_blog/essay_contract.php +++ b/src/frontend_blog/essay_contract.php @@ -27,11 +27,11 @@ include("../frontend_lib/merchants.php"); include("../frontend_lib/util.php"); include("./blog_lib.php"); session_start(); -if (!isset($_GET['article'])){ +$article = get($_GET['article']); +if (null == $article){ echo "Please land here just to buy articles"; die(); } -$article = $_GET['article']; // send contract $transaction_id = rand(0, 1001); @@ -49,11 +49,7 @@ $transaction_id = rand(0, 1001); // Include all information so we can // restore the contract without storing it $fulfillment_url = url_rel("essay_fulfillment.php") - . '&uuid=${H_contract}' //<= super weird: that should be a '?', not '&', but works - . '&aval=' . urlencode($amount_value) - . '&afrac=' . urlencode($amount_fraction) - . '&acurr=' . urlencode($currency) - . '&tid=' . $transaction_id; + . '&uuid=${H_contract}'; //<= super weird: that should be a '?', not '&', but works //file_put_contents("/tmp/debg1", $fulfillment_url); $contract_json = generate_contract($amount_value, $amount_fraction, diff --git a/src/frontend_blog/essay_fulfillment.php b/src/frontend_blog/essay_fulfillment.php index 2559ffb0..a0581de5 100644 --- a/src/frontend_blog/essay_fulfillment.php +++ b/src/frontend_blog/essay_fulfillment.php @@ -63,6 +63,13 @@ if (empty($hc)) return; } +$article = get($_GET["article"]); +if (null == $article){ + http_response_code(400); + echo "<p>Bad request (article missing)</p>"; + return; +} + session_start(); $payments = get($_SESSION['payments'], array()); @@ -70,28 +77,17 @@ $my_payment = get($payments[$hc]); // This will keep the query parameters. $pay_url = url_rel("essay_pay.php"); +$offering_url = url_rel("essay_offer.php"); +$offering_url .= "?article=" . $_GET["article"]; -/* -FIXME: in the blog's case, that should be just the homepage -$offering_url = url_rel("checkout.php", true); - -if (null === $my_payment) +if (true !== get($my_payment["is_payed"], false) || null === $my_payment) { - echo "<p>you do not have the session state for this contract: " . $hc . "</p>"; - echo "<p>Asking the wallet to re-execute it ... </p>"; + echo "<p>Paying ... at $pay_url </p>"; echo "<script>executePayment('$hc', '$pay_url', '$offering_url');</script>"; return; -}*/ - -if (true !== get($my_payment["is_payed"], false)) -{ - echo "<p>you have not payed for this contract: " . $hc . "</p>"; - echo "<p>Asking the wallet to re-execute it ... at $pay_url </p>"; - echo "<script>executePayment('$hc', '$pay_url');</script>"; - return; } -// control here = article payed +// control here == article payed $article = $my_payment["article"]; diff --git a/src/frontend_blog/essay_offer.php b/src/frontend_blog/essay_offer.php new file mode 100644 index 00000000..7377a4b3 --- /dev/null +++ b/src/frontend_blog/essay_offer.php @@ -0,0 +1,53 @@ +<!DOCTYPE html> +<html> +<head> +<script type="text/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(); +} +</script> +</head> +<body> +<?php + + include("../frontend_lib/merchants.php"); + include("../frontend_lib/util.php"); + include("./blog_lib.php"); + session_start(); + $article = get($_GET['article']); + if (null == $article){ + echo "Please land here just to buy articles"; + die(); + } + echo "<script>get_contract('$article');</script>" +?> +</body> +</html> diff --git a/src/frontend_blog/essay_pay.php b/src/frontend_blog/essay_pay.php index 33280f40..e36b072c 100644 --- a/src/frontend_blog/essay_pay.php +++ b/src/frontend_blog/essay_pay.php @@ -52,10 +52,11 @@ if (empty($article)) } $deposit_permission = file_get_contents('php://input'); -file_put_contents('/tmp/pay.dbg', 'about to pay', FILE_APPEND); +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: diff --git a/src/frontend_blog/index.html b/src/frontend_blog/index.html index c7141b44..d0e5b4ae 100644 --- a/src/frontend_blog/index.html +++ b/src/frontend_blog/index.html @@ -139,7 +139,7 @@ function has_taler_wallet_cb(aEvent) var articles_links = document.getElementsByClassName("read-more"); for(var i=0; i < articles_links.length; i++) //console.log(link); - articles_links[i].setAttribute("href", "javascript:taler_pay(\"" + articles_links[i].id + "\")"); + articles_links[i].setAttribute("href", "/essay_offer.php?article=" + articles_links[i].id); }; /* Function called when the Taler extension was unloaded; |