commit 66bfaf5cd16bad25d87f65900b570d126bb6a5eb
parent 0380bbaab8fd98735f980df160faec5b32782b59
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Fri, 30 Oct 2015 06:28:18 +0100
Adding new test samples. Fixing minor problems in the frontend
"/pay" handler.
Diffstat:
5 files changed, 93 insertions(+), 102 deletions(-)
diff --git a/src/frontend/deposit.php b/src/frontend/deposit.php
@@ -1,80 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-
-*/
-
-/*
- This serving module adds the 'max_fee' field to the object which
- sends to the backend, and optionally the field 'edate' (indicating
- to the mint the tollerated deadline to receive funds for this payment)
- NOTE: 'max_fee' must be consistent with the same value indicated within
- the contract; thus, a "real" merchant must implement such a mapping
-
-*/
-
-$post_body = file_get_contents('php://input');
-
-
-$now = new DateTime('now');
-$edate = array ('edate' =>
- "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/");
-
-$deposit_permission = json_decode ($post_body);
-$max_fee = array ('max_fee' => array ('value' => 3,
- 'fraction' => 01010,
- 'currency' => $currency));
-
-$new_deposit_permission = array_merge ($deposit_permission, $max_fee);
-$new_deposit_permission_edate = array_merge ($new_deposit_permission, $edate);
-
-// Craft the HTTP request, note that the backend
-// could be on an entirely different machine if
-// desired.
-file_put_contents('/tmp/deposit_permission_maxfee.sample', json_encode($new_deposit_permission, JSON_PRETTY_PRINT));
-
-return;
-
-$req = new http\Client\Request ("GET",
- "http://" . $_SERVER["SERVER_NAME"] . "/backend/pay",
- array ("Content-Type" => "application/json"));
-$req->getBody()->append ($json);
-
-// Execute the HTTP request
-$client = new http\Client;
-$client->enqueue($req)->send ();
-
-// Fetch the response
-$resp = $client->getResponse ();
-$status_code = $resp->getResponseCode ();
-
-// Our response code is the same we got from the backend:
-http_response_code ($status_code);
-
-// Now generate our body
-if ($status_code != 200)
-{
- /* error: just forwarding to the wallet what
- gotten from the backend (which is forwarding 'as is'
- the error gotten from the mint) */
- echo $resp->body->toString ();
-
-}
-else
-{
- echo "Payment succedeed!\n";
-}
-
-?>
diff --git a/src/frontend/generate_taler_contract.php b/src/frontend/generate_taler_contract.php
@@ -142,7 +142,6 @@ $json = json_encode (array ('amount' => array ('value' => $value,
'region' => 'Test Region',
'province' => 'Test Province',
'ZIP code' => 4908))), JSON_PRETTY_PRINT);
-
if ($cli_debug && !$backend_test)
{
echo $json . "\n";
diff --git a/src/frontend/pay.php b/src/frontend/pay.php
@@ -1,13 +1,6 @@
-<!DOCTYPE html>
-<html>
-<head>
-<title>Fullfillment page</title>
-</head>
-<body>
-
<?php
/*
- This file is part of TALER
+ This file is part of GNU TALER.
Copyright (C) 2014, 2015 GNUnet e.V.
TALER is free software; you can redistribute it and/or modify it under the
@@ -23,8 +16,82 @@
*/
-?>
+/*
+ This serving module adds the 'max_fee' field to the object which
+ sends to the backend, and optionally the field 'edate' (indicating
+ to the mint the tollerated deadline to receive funds for this payment)
+ NOTE: 'max_fee' must be consistent with the same value indicated within
+ the contract; thus, a "real" merchant must implement such a mapping
+
+*/
+
+$cli_debug = false;
+$backend_test = true;
+
+if ($_GET['cli_debug'] == 'yes')
+ $cli_debug = true;
+
+if ($_GET['backend_test'] == 'no')
+{
+ $cli_debug = true;
+ $backend_test = false;
+}
+
+$post_body = file_get_contents('php://input');
+
+$now = new DateTime('now');
+$edate = array ('edate' =>
+ "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/");
+
+$deposit_permission = json_decode ($post_body, true);
-</body>
-</html>
+$max_fee = array ('max_fee' => array ('value' => 3,
+ 'fraction' => 8,
+ 'currency' => "KUDOS"));
+$new_deposit_permission = array_merge ($deposit_permission, $max_fee);
+$new_deposit_permission_edate = array_merge ($new_deposit_permission, $edate);
+
+/* Craft the HTTP request, note that the backend
+ could be on an entirely different machine if
+ desired. */
+
+if ($cli_debug && !$backend_test)
+{
+ file_put_contents('/tmp/noedate', json_encode ($new_deposit_permission, JSON_PRETTY_PRINT));
+ file_put_contents('/tmp/yesedate', json_encode ($new_deposit_permission_edate, JSON_PRETTY_PRINT));
+
+ exit;
+}
+
+$req = new http\Client\Request ("POST",
+ "http://" . $_SERVER["SERVER_NAME"] . "/backend/pay",
+ array ("Content-Type" => "application/json"));
+$req->getBody()->append ($new_deposit_permission);
+
+// Execute the HTTP request
+$client = new http\Client;
+$client->enqueue($req)->send ();
+
+// Fetch the response
+$resp = $client->getResponse ();
+$status_code = $resp->getResponseCode ();
+
+// Our response code is the same we got from the backend:
+http_response_code ($status_code);
+
+// Now generate our body
+if ($status_code != 200)
+{
+ /* error: just forwarding to the wallet what
+ gotten from the backend (which is forwarding 'as is'
+ the error gotten from the mint) */
+ echo $resp->body->toString ();
+
+}
+else
+{
+ echo "Payment succedeed!\n";
+}
+
+?>
diff --git a/src/tests/deposit_permission.sample b/src/tests/deposit_permission.sample
@@ -1,6 +1,6 @@
{
- "H_wire": "X3E6RM65VAWNS1H01SNJ80QBNJ97YDQD2Y6VXBH57WNGAXCF6HNP94T217WZN4MCFSVJF14BZHMNZ24JVGN52PRZF0S2EXGEKRS6DA0",
- "merchant_pub": "SGRZA7R2FGDA5Z44FZ5ZN65TN5SCJB199VPNKET21BH4MZQPE7V0",
+ "H_wire": "V1F0F5AWSNX60E6TXZEYDZRE84J8HMBGXEM09AEVV3N97MM75P6JQRSWR5KQVC1RBBF2SRXY7P10H0ZM0VETWPFAJJRBVJSXNMDWTYR",
+ "merchant_pub": "BQ0TMTBV2XEJ8G2PXA9KRDD5WDT5EV29KPVS6J9RBQJCS8BCPQ70",
"mint": "localmint",
"coins": [
{
@@ -9,10 +9,10 @@
"fraction": 100000,
"currency": "KUDOS"
},
- "coin_pub": "V7TPHXYX9P52YEX4NQB41FPJC6HC0PGEH72JHVP5SP9Y2J4SA8G0",
+ "coin_pub": "AH86D5WV9G6RT0A3CHYJW598BNMH8848GAKYTEH1JX6X2BKZWTX0",
"denom_pub": "51R7ARKCD5HJTTV5F4G0M818E9SP280A40G2GVH04CR30HHG74SM8GSM6D33EGSR84R46E246H23GCHK690M4G9R8GS4CD9S8GRMCDSP64T34GA56GV34DA3851M6H9S6MWK8H9K8D13CD1M85344GSP61244GT28N132HA56N1MCHA56513AD2160RK2CSN6D23AGJ56X33AGSM68W4CH1S88WK4D1H68SMACHJ88TM2CA28MRM4D248GS4ADHR8GSM4C2364V38E1N88S30HA564TKJE1N750KGC9R6RTKJE2370R4AC268D0MACHN6N242D1N68TKAC1M65234DJ26CRK4D9M8MSK6C9J64R32D1R70VKEE25852MCG9N84W32GJ68914CD1J691M6GA360S3GCHP8GWK8HHH68TK8CSK70S4AE9N712K0H9K6X34AC9354520818CMG26C1H60R30C935452081918G2J2G0",
- "ub_sig": "51SPJSSDESGPR80A40M74WV140520818ECG26H9N71346D1R6MW46D228N334E1G60W32HJ374VKAC2660S3GGSJ691KEHA570V44CSP70RMCGHR8MV46GJ66MS44CT170R4CHHN752M8DHS68WKAD9G6WR3ACT66GRM6H216CSM6H9R88VKCH9Q8MWK8E226H2K6CT16CW4AHHG6N238HA26X2KGD1Q8GRMADJ5712KEEA470TKGC9S8MWKGGHP64W46E1N6N336C2365136CHM8RT3CCHH6MV34GSR60S3CCHR8S0K0HHN8RWKGGHK6MS4CH1K8MS38E1G88RMCDA384T44DHJ6534CD9M6N0M6GT58RTM6GA26N24CGHQ8N0MACJ68S2K4E9P74S48DHS6RR3JGA38N0K4E9P6X23ACA684WKAH1H8RSK4CH35452081918G2J2G0",
- "coin_sig": 5326752
+ "ub_sig": "51SPJSSDESGPR80A40M74WV140520818ECG26C9J8D1MCHHJ84S34H1K8H1M6HHN60V3GH9S84R3GH9K6MVM6GSM70RKCDT188VM4CHM74RM8GSN6GSKEHHS6CT44H9Q8CWKCD1P68SK2G9S8GR34D1P60T4CCJ67523EDJ28S1KJD9N8H330CT58RS38CSM8H346GT58N13CGJ16GS34CHQ6GT42CSS6CTM4C9H8N1KCG9G74T36C1K8GT44E1N8RRK0D218GV46G9R6CT4CHA4890M6H1H8GV34E1Q8N244DHM8CRK2H1R8CV3ADA37113JDHR88W36E9R61242GT5752KEE9R84WK8H9G8GT34GT26S2MAE1P70RMAGSK74W30C1J60S32GSK64WKAC218MWM6GHM8S332DSN70SM2DHR6H146E228CTM8D135452081918G2J2G0",
+ "coin_sig": "MFTHC54GFYHA3CGKHC8SSDSTYX8YMEJDNQA7AEY5M7JBK3WPDQ9NCJ54ZSPQRZ4QCJC0CPREP0XRWH9JQ509ENSEXWKNNM5FEVRG238"
},
{
"f": {
@@ -20,10 +20,15 @@
"fraction": 100000,
"currency": "KUDOS"
},
- "coin_pub": "5PZKEGB0G7QYEAZAE0WWEPNN7EEK91Y4S8XSQGQ14GXXK481C01G",
+ "coin_pub": "MQY067A8AGG90TSH11C8JNRW8P1R669JAAQX4V2HGFHGJ2WY4ZA0",
"denom_pub": "51R7ARKCD5HJTTV5F4G0M818E9SP280A40G2GVH04CR30HHG74SM8GSM6D33EGSR84R46E246H23GCHK690M4G9R8GS4CD9S8GRMCDSP64T34GA56GV34DA3851M6H9S6MWK8H9K8D13CD1M85344GSP61244GT28N132HA56N1MCHA56513AD2160RK2CSN6D23AGJ56X33AGSM68W4CH1S88WK4D1H68SMACHJ88TM2CA28MRM4D248GS4ADHR8GSM4C2364V38E1N88S30HA564TKJE1N750KGC9R6RTKJE2370R4AC268D0MACHN6N242D1N68TKAC1M65234DJ26CRK4D9M8MSK6C9J64R32D1R70VKEE25852MCG9N84W32GJ68914CD1J691M6GA360S3GCHP8GWK8HHH68TK8CSK70S4AE9N712K0H9K6X34AC9354520818CMG26C1H60R30C935452081918G2J2G0",
- "ub_sig": "51SPJSSDESGPR80A40M74WV140520818ECG26C1R6GR38H227524CCSS6X0K8GHS691K8G9J6RWK4H1G8S23AD1Q88W4CH2560T3EC226S1K6DA68N346C258CVKEC9M8H344HHP6RT44HJ56123ADHN8N1K0DHJ6933CD1M6X142CHM8RS4AD9M8GV30D1M6X14CE1P74TKAC9P8GWMAH9M750K0E9N8S34CCSR61136H9H6X0K0GT68RSM8CSH8N1K8HHJ8CSM4DT58H24AEA16CR3EH268CR30E1H8N1KGH9P8RS44HJ18RRK4CT46WSK4HHN8GSMADT38MTM2E1R8CR3EH1P6S2KGE1G8D342DHS88TKGCT66N0K8G9N752K6CHN70V3EH9H651M2H1M8N132E9J64S42DT668T3GG9H74S3JDJ68D13CH135452081918G2J2G0",
- "coin_sig": 5326752
+ "ub_sig": "51SPJSSDESGPR80A40M74WV140520818ECG26H1J60R4AHHG6N1KEC268N23ECT664VKAGSJ8GRK4CA56H2KAH1H8CS4AHA188SKJE266RR3EDA58N148DSS74TM6CA58N24AC9K6X1M4C9Q6RW48CT674SMCE2264V42CSH8D336GSQ84SM6CT564TKECSR8MRMAGHG8GW3JEA56WT32D9S8H334DJ564SK8GSS60WM6E1P8S346H238GRM8DSN6MR36C256GVM8H9M6WV30C246X0MCH9R84TK2D1M70V44CA260VKJGHN6RR4ACT488R3GCA46MW3GDHK6GWMAHHP6S242H9G6D134D9N8RV32DSJ8GSKGC1J6RTK2GHQ8H0K2DHH6WT38GSH74WM4EA574RKEE1M6D0M4DHK8MW4ACT68CT4CE236H236GH35452081918G2J2G0",
+ "coin_sig": "K9S5273GT4QKF5Y9FYJ62BV710WGEFE1DSXV75A37X272ADWBCV0ERZV9TF2VYTCSH1837R3F7A39R5QEPCC0NYW3JQ5S70X8MJG008"
}
- ]
+ ],
+ "max_fee": {
+ "value": 3,
+ "fraction": 8,
+ "currency": "KUDOS"
+ }
}
\ No newline at end of file
diff --git a/src/tests/test_contract_README b/src/tests/test_contract_README
@@ -4,7 +4,7 @@
- curl http://merchant-url/generate_taler_contract.php?cli_debug=yes
(this form tests the whole communication between frontend and backend)
- - curl http://merchant-url/generate_taler_contract.php?cli_debug=yes
+ - curl http://merchant-url/generate_taler_contract.php?backend_test=no
(this form test only the contract proposition generation of the frontend,
so it doesn't further connect to the backend to get the proposition JSON
enhanced)