commit b28cadd945c1d02f33afdc8feaa03a08565d59b2
parent ffe29907989526a94d1131eddbf18dc9309ad524
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Mon, 27 Mar 2017 00:55:14 +0200
updating php logic to latest protocol
Diffstat:
6 files changed, 37 insertions(+), 45 deletions(-)
diff --git a/php/donate.php b/php/donate.php
@@ -3,7 +3,7 @@
// Next two lines offer Taler payment option for Taler wallets:
http_response_code(402); // 402: Payment required
- header ('X-Taler-Contract-Url: /generate-contract.php');
+ header ('X-Taler-Contract-Url: /generate-order.php');
?>
<!DOCTYPE html>
<html lang="en">
diff --git a/php/fulfillment.php b/php/fulfillment.php
@@ -1,42 +1,24 @@
<?php
// This file is in the public domain.
- include 'contract.php';
- include 'backend.php';
- include 'error.php';
+ include 'helpers.php';
session_start();
if(pull($_SESSION, 'paid', false)){
echo sprintf("<p>Thanks for your donation!</p>
- <br>
- <p>The transaction ID was: %s; use it to
+ <br><p>The order ID is: %s; use it to
<a href=\"backoffice.html\">track</a> your money,
or make <a href=\"/\">another donation!</a></p>",
- $_SESSION['transaction_id']);
+ $_SESSION['order_id']);
session_destroy();
return;
}
- $_SESSION['transaction_id'] = $_GET['transaction_id'];
-
- $now = new DateTime();
- $now->setTimestamp(intval($_GET["timestamp"]));
-
- $rec_proposal = make_contract(intval($_GET['transaction_id']), $now);
- $response = post_to_backend("/contract", $rec_proposal);
- http_response_code($response["status_code"]);
- if (200 != $response["status_code"]) {
- echo build_error($response,
- "Failed to reconstruct the contract",
- $response['code']);
- return;
- }
// The user needs to pay, instruct the wallet to send the payment.
- $body = json_decode($response['body']);
http_response_code(402);
- header('X-Taler-Contract-Hash: ' . $body->H_contract);
- header('X-Taler-Pay-Url: ' . url_rel("/pay.php"));
- header('X-Taler-Offer-Url: ' . url_rel('/generate-contract.php'));
+ header('X-Taler-Contract-Url: ' . url_rel('/generate-order.php'));
+ header('X-Taler-Contract-Query: ' . "fulfillment_url");
+ header('X-Taler-Offer-Url: ' . url_rel('/donate.php'));
return;
?>
diff --git a/php/generate-order.php b/php/generate-order.php
@@ -1,16 +1,24 @@
<?php
// This file is in the public domain.
- include 'contract.php';
+ include 'order.php';
include 'backend.php';
include 'error.php';
- $transaction_id = rand(1,90000); // simplified, do not do this!
+ $order_id = rand(1,90000); // simplified, do not do this!
+ session_start();
+ $_SESSION["order_id"] = $order_id;
// this variable is the JSON of a contract proposal,
// see https://api.taler.net/api-merchant.html#post--contract
- $proposal = make_contract($transaction_id, new DateTime('now'));
+ if(!isset($_GET["nonce"]))
+ return build_error(array("body" => null),
+ "no nonce given",
+ 400);
+ $order = make_order($_GET["nonce"],
+ $order_id,
+ new DateTime('now'));
// Here the frontend POSTs the proposal to the backend
- $response = post_to_backend("/contract", $proposal);
+ $response = post_to_backend("/proposal", $order);
// We always return verbatim what the backend returned
http_response_code($response["status_code"]);
if (200 != $response["status_code"]) {
diff --git a/php/inline.php b/php/inline.php
@@ -3,10 +3,10 @@
include 'contract.php';
- $transaction_id = rand(1,90000); // simplified, do not do this!
- $proposal = make_contract($transaction_id, new DateTime('now'));
+ $order_id = rand(1,90000); // simplified, do not do this!
+ $order = make_order($order_id, new DateTime('now'));
- $response = post_to_backend("/contract", $proposal);
+ $response = post_to_backend("/proposal", $order);
$ret = $response["body"];
if (200 != $response["status_code"]) {
diff --git a/php/order.php b/php/order.php
@@ -4,26 +4,27 @@
include_once 'config.php';
include_once 'helpers.php';
- function make_order($transaction_id, $now){
+ function make_order($nonce,
+ $order_id,
+ $now){
$contract
= array(
+ 'nonce' => $nonce,
'amount' =>
- array('value' => 1,
- 'fraction' => 0,
+ array('value' => 0,
+ 'fraction' => 10000000,
'currency' => $GLOBALS['CURRENCY']),
'max_fee' =>
array('value' => 0,
- 'fraction' => 50000,
+ 'fraction' => 5000000,
'currency' => $GLOBALS['CURRENCY']),
- 'transaction_id' =>
- $transaction_id,
'products' =>
array(array('description' =>
"Donation to charity program",
'quantity' => 1,
'price' =>
- array ('value' => 1,
- 'fraction' => 0,
+ array ('value' => 0,
+ 'fraction' => 10000000,
'currency' => $GLOBALS['CURRENCY']),
'product_id' => 0,
'taxes' =>
@@ -36,12 +37,13 @@
),
'summary' =>
"Personal donation to charity program",
+ 'order_id' => $order_id,
'timestamp' =>
"/Date(" . $now->getTimestamp() . ")/",
'fulfillment_url' =>
- url_rel("/fulfillment.php?"
- . "transaction_id=$transaction_id×tamp="
- . $now->getTimestamp()),
+ url_rel("/fulfillment.php"),
+ 'pay_url' =>
+ url_rel("/pay.php"),
'refund_deadline' =>
"/Date(" . $now->getTimestamp() . ")/",
'pay_deadline' =>
@@ -73,6 +75,6 @@
'street' => 'test street 2',
'street number' => 202)
));
- return array ('contract' => $contract);
+ return array ('order' => $contract);
}
?>
diff --git a/php/pay.php b/php/pay.php
@@ -15,7 +15,7 @@
http_response_code($response['status_code']);
if (200 != $response['status_code']){
echo build_error($response,
- "Could not send paymnet to backend",
+ "Could not send payment to backend",
$response['status_code']);
return;
}