summaryrefslogtreecommitdiff
path: root/src/frontend/cert.php
blob: 9f0af3502d2830dea8cc9cff7e79fed2c845121a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php 

/*

  This file is part of TALER
  Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU General Public License as published by the Free Software
  Foundation; either version 3, 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 General Public License for more details.

  You should have received a copy of the GNU General Public License along with
  TALER; see the file COPYING.  If not, If not, see <http://www.gnu.org/licenses/>

*/

/*  

  Here goes all the Taler paying logic. The steps are

  1. recover the session

  2. generate the JSON to forward to the backend

  3. route back to the wallet the certificate just gotten

*/


// recover the session
session_start();
if(!isset($_SESSION['maydonate'])){
  http_response_code(404);
  echo "Please try to donate before getting to this page :)";
}

else{
  // fake product id
  $p_id = rand(0,1001);
  // generate a transaction/certificate id. In production context, it's wishable to
  // record this value
  $trans_cert_id = rand(0, 1001);
  // fake a human readable description of this deal
  $desc = "donation aimed to stop the ants' massacre on hicking paths";
  // fake the price's integer (actually, the system is testishly suited for just 10 EUR coins)
  $value = 10;
  // fake the price's fractional
  $fraction = 0;
  // hardcode the currency
  $currency = "EUR";

  // pack the JSON
  $json  = json_encode (array ('desc' => $desc, 'product' => $p_id, 'cid' => $trans_cert_id,
                               'price' => array ('value' => $value,
			                         'fraction' => $fraction,
						 'currency' => $currency)));
  // test
  // echo $json;
  
  //echo phpinfo ();
  
  // crafting the request
  $req = new http\Client\Request ("POST",
                                  "http://" . $SERVER["SERVER_NAME"] . "/backend" . "/contract",
                                  //"http://localhost:9898/",
				  array ("Content-Type" => "application/json"));
  $req->getBody()->append ($json);

  $client = new http\Client;
  $client->enqueue($req)->send ();
  $resp = $client->getResponse ();
  $status_code = $resp->getResponseCode ();
  http_response_code ($status_code);
  

  if ($status_code != 200){
    echo "Error while generating the certificate, response code : " . $status_code;
  }
  // send the contract back to the wallet without touching it
  else{
    echo $resp->body->toString ();
  }

}


?>