aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/frontend/generate_taler_contract.php42
1 files changed, 12 insertions, 30 deletions
diff --git a/src/frontend/generate_taler_contract.php b/src/frontend/generate_taler_contract.php
index 7ad0a643..c71542c8 100644
--- a/src/frontend/generate_taler_contract.php
+++ b/src/frontend/generate_taler_contract.php
@@ -30,26 +30,15 @@
if the whole "journey" to the backend is begin tested
- $ curl http://merchant_url/generate_taler_contract.php?backend_test=no
if just the frontend job is being tested
- */
-
-
-register_shutdown_function(function() {
- $lastError = error_get_last();
-
- if (!empty($lastError) && $lastError['type'] == E_ERROR) {
- header('Status: 500 Internal Server Error');
- header('HTTP/1.0 500 Internal Server Error');
- }
-});
-
+*/
$cli_debug = false;
$backend_test = true;
-if (isset($_GET['cli_debug']) && $_GET['cli_debug'] == 'yes')
+if ($_GET['cli_debug'] == 'yes')
$cli_debug = true;
-if (isset($_GET['backend_test']) && $_GET['backend_test'] == 'no')
+if ($_GET['backend_test'] == 'no')
{
$cli_debug = true;
$backend_test = false;
@@ -61,6 +50,7 @@ if (!$cli_debug && (! isset($_SESSION['receiver'])))
{
http_response_code (404);
echo "Please select a contract before getting to this page...";
+ echo "attempted : " . $_SESSION['receiver'];
exit (0);
}
@@ -102,7 +92,7 @@ $now = new DateTime('now');
// pack the JSON for the contract
// --- FIXME: exact format needs review!
-$contract = array ('amount' => array ('value' => $amount_value,
+$json = json_encode (array ('amount' => array ('value' => $amount_value,
'fraction' => $amount_fraction,
'currency' => $currency),
'max_fee' => array ('value' => 3,
@@ -120,6 +110,7 @@ $contract = array ('amount' => array ('value' => $amount_value,
'delivery_date' => "Some Date Format",
'delivery_location' => 'LNAME1')),
'timestamp' => "/Date(" . $now->getTimestamp() . ")/",
+ 'pay_url' => "/taler/pay",
'expiry' => "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/",
'refund_deadline' => "/Date(" . $now->add(new DateInterval('P3M'))->getTimestamp() . ")/",
'merchant' => array ('address' => 'LNAME2',
@@ -147,23 +138,18 @@ $contract = array ('amount' => array ('value' => $amount_value,
'state' => 'Test State',
'region' => 'Test Region',
'province' => 'Test Province',
- 'ZIP code' => 4908)));
-
-$json = json_encode (array ("contract" => $contract, "pay_url" => "pay.php", "exec_url" => "execute.php"));
+ 'ZIP code' => 4908))), JSON_PRETTY_PRINT);
if ($cli_debug && !$backend_test)
{
echo $json . "\n";
exit;
}
-
-
-// Backend is relative to the shop site.
-$url = (new http\URL("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"))
- ->mod(array ("path" => "backend/contract"), http\Url::JOIN_PATH);
-
+// Craft the HTTP request, note that the backend
+// could be on an entirely different machine if
+// desired.
$req = new http\Client\Request ("POST",
- $url,
+ "http://" . $_SERVER["SERVER_NAME"] . "/backend/contract",
array ("Content-Type" => "application/json"));
$req->getBody()->append ($json);
@@ -181,14 +167,10 @@ http_response_code ($status_code);
// Now generate our body
if ($status_code != 200)
{
- echo "Error while generating the contract:";
- echo "$resp";
+ echo "Error while generating the contract";
}
else
{
-
- $json = json_decode($resp->body->toString (), true);
- $_SESSION["H_contract"] = $json["H_contract"];
// send the contract back to the wallet without touching it
echo $resp->body->toString ();
}