gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-merchant-frontend-examples] branch master updated: u


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant-frontend-examples] branch master updated: updating php logic to latest protocol
Date: Mon, 27 Mar 2017 00:55:49 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository merchant-frontend-examples.

The following commit(s) were added to refs/heads/master by this push:
     new b28cadd  updating php logic to latest protocol
b28cadd is described below

commit b28cadd945c1d02f33afdc8feaa03a08565d59b2
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Mar 27 00:55:14 2017 +0200

    updating php logic to latest protocol
---
 php/donate.php         |  2 +-
 php/fulfillment.php    | 30 ++++++------------------------
 php/generate-order.php | 16 ++++++++++++----
 php/inline.php         |  6 +++---
 php/order.php          | 26 ++++++++++++++------------
 php/pay.php            |  2 +-
 6 files changed, 37 insertions(+), 45 deletions(-)

diff --git a/php/donate.php b/php/donate.php
index 7d68717..e22610e 100644
--- 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
index f405b5b..3c0ecef 100644
--- 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
index 20c6331..1a0e4a1 100644
--- 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
index 36ba1da..ce73982 100644
--- 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
index 7582ae7..fdcd228 100644
--- 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&timestamp="
-                 . $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
index 7a07cd7..e5bd268 100644
--- 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;
   }

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]