summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2016-01-25 14:57:42 +0100
committerMarcello Stanisci <marcello.stanisci@inria.fr>2016-01-25 14:57:42 +0100
commit0af7437d388b3b1106a86b957a1449d7563dd35e (patch)
tree9fa0a4bce284e28a9e76f567a956e61005e9cfe0
parentbdf26f361ae8ee4a77ffed68b39d7578f1a2c34f (diff)
parenta91b81e696dc6581947c1882b565224ed365e16d (diff)
downloadmerchant-0af7437d388b3b1106a86b957a1449d7563dd35e.tar.gz
merchant-0af7437d388b3b1106a86b957a1449d7563dd35e.tar.bz2
merchant-0af7437d388b3b1106a86b957a1449d7563dd35e.zip
Merge branch 'master' of ssh://taler.net/var/git/merchant
Conflicts: src/frontend/pay.php
-rw-r--r--src/frontend/fulfillment.php1
-rw-r--r--src/frontend/generate_taler_contract.php148
-rw-r--r--src/frontend/pay.php47
3 files changed, 97 insertions, 99 deletions
diff --git a/src/frontend/fulfillment.php b/src/frontend/fulfillment.php
index 6d49971b..936329de 100644
--- a/src/frontend/fulfillment.php
+++ b/src/frontend/fulfillment.php
@@ -37,7 +37,6 @@
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/>
-
*/
function generate_msg ($link){
diff --git a/src/frontend/generate_taler_contract.php b/src/frontend/generate_taler_contract.php
index e44a4d9b..c405e818 100644
--- a/src/frontend/generate_taler_contract.php
+++ b/src/frontend/generate_taler_contract.php
@@ -1,7 +1,7 @@
<?php
/*
This file is part of GNU TALER.
- Copyright (C) 2014, 2015 GNUnet e.V.
+ Copyright (C) 2014-2016 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
@@ -13,95 +13,104 @@
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/>
-
*/
-
include 'util.php';
session_start();
if (!isset($_SESSION['receiver']))
{
- http_response_code (400);
+ http_response_code(400);
die();
}
$receiver = $_SESSION['receiver'];
$receiver = $_SESSION['receiver'];
-$amount_value = intval ($_SESSION['amount_value']);
-$amount_fraction = intval ($_SESSION['amount_fraction']);
+$amount_value = intval($_SESSION['amount_value']);
+$amount_fraction = intval($_SESSION['amount_fraction']);
$currency = $_SESSION['currency'];
/* Fill in variables for simple JSON contract */
// fake product id
-// --- FIXME: base on receiver for more realism!
$p_id = rand(0,1001);
+
// generate a front-end transaction id.
// In production context, we might want to
// record this value somewhere together
// with the rest of the contract data.
$transaction_id = rand(0, 1001);
+
// Human-readable description of this deal
$desc = "Donation to " . $receiver;
+
// The tax for this deal
-$teatax = array ('value' => 1,
- 'fraction' => 0,
- 'currency' => $currency);
+$teatax = array('value' => 1,
+ 'fraction' => 0,
+ 'currency' => $currency);
// Take a timestamp
$now = new DateTime('now');
// pack the JSON for the contract
-// --- FIXME: exact format needs review!
-$contract = array ('amount' => array ('value' => $amount_value,
- 'fraction' => $amount_fraction,
- 'currency' => $currency),
- 'max_fee' => array ('value' => 3,
- 'fraction' => 01010,
- 'currency' => $currency),
- 'transaction_id' => $transaction_id,
- 'products' => array (
- array ('description' => $desc,
- 'quantity' => 1,
- 'price' => array ('value' => $amount_value,
- 'fraction' => $amount_fraction,
- 'currency' => $currency),
- 'product_id' => $p_id,
- 'taxes' => array (array ('teatax' => $teatax)),
- 'delivery_date' => "Some Date Format",
- 'delivery_location' => 'LNAME1')),
- 'timestamp' => "/Date(" . $now->getTimestamp() . ")/",
- 'expiry' => "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/",
- 'refund_deadline' => "/Date(" . $now->add(new DateInterval('P3M'))->getTimestamp() . ")/",
- 'merchant' => array ('address' => 'LNAME2',
- 'name' => 'test merchant',
- 'jurisdiction' => 'LNAME3'),
-
- 'locations' => array ('LNAME1' => array ('country' => 'Test Country',
- 'city' => 'Test City',
- 'state' => 'Test State',
- 'region' => 'Test Region',
- 'province' => 'Test Province',
- 'ZIP code' => 4908,
- 'street' => 'test street',
- 'street number' => 20),
- 'LNAME2' => array ('country' => 'Test Country',
- 'city' => 'Test City',
- 'state' => 'Test State',
- 'region' => 'Test Region',
- 'province' => 'Test Province',
- 'ZIP code' => 4908,
- 'street' => 'test street',
- 'street number' => 20),
- 'LNAME3' => array ('country' => 'Test Country',
- 'city' => 'Test City',
- 'state' => 'Test State',
- 'region' => 'Test Region',
- 'province' => 'Test Province',
- 'ZIP code' => 4908)));
-
-$json = json_encode(array('contract' => $contract, JSON_PRETTY_PRINT));
+$contract = array(
+ 'fulfillment_url' => (url_rel("fulfillment.php") . '?uuid=${H_contract}'),
+ 'amount' => array(
+ 'value' => $amount_value,
+ 'fraction' => $amount_fraction,
+ 'currency' => $currency),
+ 'max_fee' => array('value' => 3,
+ 'fraction' => 01010,
+ 'currency' => $currency),
+ 'transaction_id' => $transaction_id,
+ 'products' => array(
+ array(
+ 'description' => $desc,
+ 'quantity' => 1,
+ 'price' => array ('value' => $amount_value,
+ 'fraction' => $amount_fraction,
+ 'currency' => $currency),
+ 'product_id' => $p_id,
+ 'taxes' => array(array('teatax' => $teatax)),
+ 'delivery_date' => "Some Date Format",
+ 'delivery_location' => 'LNAME1')),
+ 'timestamp' => "/Date(" . $now->getTimestamp() . ")/",
+ 'expiry' => "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/",
+ 'refund_deadline' => "/Date(" . $now->add(new DateInterval('P3M'))->getTimestamp() . ")/",
+ 'merchant' => array(
+ 'address' => 'LNAME2',
+ 'name' => 'test merchant',
+ 'jurisdiction' => 'LNAME3'),
+ 'locations' => array(
+ 'LNAME1' => array(
+ 'country' => 'Test Country',
+ 'city' => 'Test City',
+ 'state' => 'Test State',
+ 'region' => 'Test Region',
+ 'province' => 'Test Province',
+ 'ZIP code' => 4908,
+ 'street' => 'test street',
+ 'street number' => 20),
+ 'LNAME2' => array(
+ 'country' => 'Test Country',
+ 'city' => 'Test City',
+ 'state' => 'Test State',
+ 'region' => 'Test Region',
+ 'province' => 'Test Province',
+ 'ZIP code' => 4908,
+ 'street' => 'test street',
+ 'street number' => 20),
+ 'LNAME3' => array(
+ 'country' => 'Test Country',
+ 'city' => 'Test City',
+ 'state' => 'Test State',
+ 'region' => 'Test Region',
+ 'province' => 'Test Province',
+ 'ZIP code' => 4908)));
+
+$json = json_encode(array(
+ 'contract' => $contract
+), JSON_PRETTY_PRINT);
$url = url_join("http://".$_SERVER["HTTP_HOST"], "backend/contract");
@@ -109,30 +118,31 @@ $req = new http\Client\Request("POST",
$url,
array ("Content-Type" => "application/json"));
-$req->getBody()->append ($json);
+$req->getBody()->append($json);
// Execute the HTTP request
$client = new http\Client;
-$client->enqueue($req)->send ();
+$client->enqueue($req)->send();
// Fetch the response
-$resp = $client->getResponse ();
-$status_code = $resp->getResponseCode ();
+$resp = $client->getResponse();
+$status_code = $resp->getResponseCode();
// Our response code is the same we got from the backend:
-http_response_code ($status_code);
+http_response_code($status_code);
// Now generate our body
if ($status_code != 200)
{
- echo "Error while generating the contract";
- echo $resp->body->toString ();
+ echo json_encode(array(
+ 'error' => "internal error",
+ 'hint' => "backend indicated error",
+ 'detail' => $resp->body->toString()
+ ), JSON_PRETTY_PRINT);
}
else
{
- $got_json = json_decode ($resp->body->toString (), true);
- $got_json['pay_url'] = url_rel("pay.php");
- $got_json['exec_url'] = url_rel("execute.php") . "?H_contract=" . $got_json["H_contract"];
+ $got_json = json_decode($resp->body->toString(), true);
$_SESSION['H_contract'] = $got_json["H_contract"];
echo json_encode ($got_json, JSON_PRETTY_PRINT);
}
diff --git a/src/frontend/pay.php b/src/frontend/pay.php
index a843bcc9..6c9497d8 100644
--- a/src/frontend/pay.php
+++ b/src/frontend/pay.php
@@ -16,15 +16,6 @@
*/
-/*
- 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
-
- */
-
include '../frontend_lib/util.php';
function respond_success() {
@@ -42,7 +33,7 @@ if (!isset($_SESSION['H_contract']))
$json = json_encode(
array("error" => "No session active"));
echo $json;
- http_response_code (401);
+ http_response_code(401);
die();
}
@@ -55,17 +46,20 @@ if (isset($_SESSION['payment_ok']) && $_SESSION['payment_ok'] == true)
$post_body = file_get_contents('php://input');
$now = new DateTime('now');
-$edate = array ('edate' =>
- "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/");
+$edate = array (
+ 'edate' =>
+ "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/");
$deposit_permission = json_decode ($post_body, true);
-$to_add = array('max_fee' => array('value' => 3,
- 'fraction' => 8,
- 'currency' => $_SESSION['currency']),
- 'amount' => array('value' => $_SESSION['amount_value'],
- 'fraction' => $_SESSION['amount_fraction'],
- 'currency' => $_SESSION['currency']));
+$to_add = array(
+ 'max_fee' => array(
+ 'value' => 3,
+ 'fraction' => 8,
+ 'currency' => $_SESSION['currency']),
+ 'amount' => array('value' => $_SESSION['amount_value'],
+ 'fraction' => $_SESSION['amount_fraction'],
+ 'currency' => $_SESSION['currency']));
$new_deposit_permission = array_merge($deposit_permission, $to_add);
$new_deposit_permission_edate = array_merge($new_deposit_permission, $edate);
@@ -75,25 +69,20 @@ $new_deposit_permission_edate = array_merge($new_deposit_permission, $edate);
desired. */
// Backend is relative to the shop site.
-/**
- * WARNING: the "shop site" is '"http://".$_SERVER["HTTP_HOST"]'
- * So do not attach $_SERVER["REQUEST_URI"] before proxying requests
- * to the backend
- */
-$url = url_join("http://".$_SERVER["HTTP_HOST"], "backend/pay");
+$url = url_rel("backend/pay");
$req = new http\Client\Request("POST",
$url,
- array ("Content-Type" => "application/json"));
+ array("Content-Type" => "application/json"));
$req->getBody()->append (json_encode ($new_deposit_permission));
// Execute the HTTP request
$client = new http\Client;
-$client->enqueue($req)->send ();
+$client->enqueue($req)->send();
// Fetch the response
-$resp = $client->getResponse ();
-$status_code = $resp->getResponseCode ();
+$resp = $client->getResponse();
+$status_code = $resp->getResponseCode();
// Our response code is the same we got from the backend:
http_response_code ($status_code);
@@ -105,7 +94,7 @@ if ($status_code != 200)
array(
"error" => "backend error",
"status" => $status_code,
- "detail" => $resp->body->toString ()));
+ "detail" => $resp->body->toString()));
echo $json;
}
else