merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 69ba9f8107a8bb36989d57c292178b0ab7bb5897
parent 2dd8f39f524af9c7c64538c59fb423549654427d
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Fri, 26 Feb 2016 09:58:28 +0100

contract/pay events triggered regardless of wallet being installed

Diffstat:
Mexamples/blog/essay_cc-form.html | 7+++----
Mexamples/blog/essay_fulfillment.php | 13+++++--------
Mexamples/blog/essay_pay.php | 14++++++++++++++
3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/examples/blog/essay_cc-form.html b/examples/blog/essay_cc-form.html @@ -58,9 +58,7 @@ } function has_taler_wallet_cb(aEvent){ - //var article = document.getElementById('article-name'); - //get_contract(article.value); - get_contract("{article}"); + //{jscode} }; function signal_taler_wallet_onload(){ @@ -90,7 +88,8 @@ </script> <script type="application/javascript" src="taler-presence.js"></script> <script type="application/javascript"> - {jscode} + {jscode} </script> + </body> </html> diff --git a/examples/blog/essay_fulfillment.php b/examples/blog/essay_fulfillment.php @@ -30,27 +30,24 @@ $payments = &pull($_SESSION, 'payments', array()); $my_payment = &pull($payments, $article, false); - // BUGGY - //$payments = &pull($_SESSION, 'payments', array()); - //$my_payment = &pull($payments, $article, array()); - $pay_url = url_rel("essay_pay.php"); $offering_url = url_rel("essay_fulfillment.php", true); $offering_url .= "?article=$article"; - //if (null === get($payments[$article]['ispayed']) || null === $my_payment){ # BUGGY // In PHP false == null if (null == get($payments[$article]['ispayed']) || false == $my_payment){ $tid = get($_GET['tid']); $timestamp = get($_GET['timestamp']); // 1st time if (null == $tid || null == $timestamp){ - $cc_page = template("./essay_cc-form.html", array('article' => $article, 'jscode' => null)); + $js_code = "get_contract(\"$article\");"; + $cc_page = template("./essay_cc-form.html", array('article' => $article, 'jscode' => $js_code)); echo $cc_page; log_string("cnt blog"); return; } log_string("restoring blog"); + //log_string("state: " . print_r($_SESSION, true)); // restore contract $now = new DateTime(); $now->setTimestamp(intval($timestamp)); @@ -91,10 +88,10 @@ } $hc = json_decode($resp->body->toString(), true)['H_contract']; $my_payment['hc'] = $hc; - $js_code = "executePayment('$hc', '$pay_url', '$offering_url')"; + log_string("sending payment event"); + $js_code = "executePayment(\"$hc\", \"$pay_url\", \"$offering_url\");"; $cc_page = template("./essay_cc-form.html", array('article' => $article, 'jscode' => $js_code)); echo $cc_page; - log_string("pay blog"); return; } // control here == article payed diff --git a/examples/blog/essay_pay.php b/examples/blog/essay_pay.php @@ -18,6 +18,9 @@ include("../../copylib/merchants.php"); include("../../copylib/util.php"); include("./blog_lib.php"); + + log_string("paying"); + $article = get($_GET["article"]); if (empty($article)){ http_response_code(400); @@ -30,6 +33,17 @@ $deposit_permission = file_get_contents('php://input'); // FIXME check here if the deposit permission is associated session_start(); + if (!isset($_SESSION["payments"])) { + $json = json_encode( + array( + "error" => "no payments ongoing", + "status" => 500, + "detail" => "the shop has no state for any article" + ) + ); + echo $json; + die(); + } $payments = &pull($_SESSION, "payments", array()); $dec_dep_perm = json_decode($deposit_permission, true); if ($dec_dep_perm['H_contract'] != $payments[$article]['hc']){