merchant-frontend-examples

ZZZ: Inactive/Deprecated
Log | Files | Refs

commit 3ef039138165bbd8695299429cb45f94a361e8f7
parent 2c25ec25279684d1f2a1b6742dbc184401f5582e
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Tue, 15 Nov 2016 01:17:52 +0100

Debugging the Web site.. Mostly minor fixes

Diffstat:
Dphp/config.php | 3---
Mphp/generate-contract.php | 33+++++++--------------------------
Aphp/helpers.php | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Mphp/index.php | 2+-
4 files changed, 61 insertions(+), 30 deletions(-)

diff --git a/php/config.php b/php/config.php @@ -1,3 +0,0 @@ -<?php - $CONFIG = array("BACKEND_BASEURL" => "https://backend.demo.taler.net/") -?> diff --git a/php/generate-contract.php b/php/generate-contract.php @@ -16,6 +16,7 @@ */ include 'config.php'; + include 'helpers.php'; function make_contract($transaction_id, $now){ $contract = array ('amount' => @@ -43,13 +44,10 @@ "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/", 'refund_deadline' => "/Date(" . $now->add(new DateInterval('P3M'))->getTimestamp() . ")/", - 'repurchase_correlation_id' => $args['correlation_id'], - 'fulfillment_url' => $_SERVER['REQUEST_SCHEME'] - .'://' - .$_SERVER['HTTP_HOST'] - ."/fulfillment.php?" - . "transaction_id=$transaction_id&timestamp" - . $now->getTimestamp(), + 'repurchase_correlation_id' => '', + 'fulfillment_url' => url_rel("/fulfillment.php?" + . "transaction_id=$transaction_id&timestamp=" + . $now->getTimestamp()), 'merchant' => array ('address' => 'LNAME2', 'name' => "Charity donation shop", @@ -61,7 +59,7 @@ 'state' => 'Test State 1', 'region' => 'Test Region 1', 'province' => 'Test Province 1', - 'ZIP code' => 4908 1, + 'ZIP code' => 49081, 'street' => 'test street 1', 'street number' => 201), 'LNAME2' => @@ -70,7 +68,7 @@ 'state' => 'Test State 2', 'region' => 'Test Region 2', 'province' => 'Test Province 2', - 'ZIP code' => 4908 2, + 'ZIP code' => 49082, 'street' => 'test street 2', 'street number' => 202), 'LNAME3' => @@ -85,23 +83,6 @@ } - /** - * Feed `$json` to the backend and return the "(pecl) http response object" - * corresponding to the `$backend_relative_url` call - */ - function post_to_backend($backend_relative_url, $json){ - $url = url_join("http://".$CONFIG["BACKEND_BASEURL"], $backend_relative_url); - $req = new http\Client\Request("POST", - $url, - array ("Content-Type" => "application/json")); - $req->getBody()->append($json); - // Execute the HTTP request - $client = new http\Client; - $client->enqueue($req)->send(); - return $client->getResponse(); - } - - /* this variable is the JSON of a contract proposal, see https://api.taler.net/api-merchant.html#post--contract the second parameter is the transaction id */ diff --git a/php/helpers.php b/php/helpers.php @@ -0,0 +1,53 @@ +<?php + +/* + This file is part of GNU TALER. + Copyright (C) 2014, 2015 INRIA + + 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 + Foundation; either version 2.1, 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 Lesser General Public License for more details. + + 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 'config.php'; + + // Get a url with a path relative to the + // current script's path. + function url_rel($path, $strip=false) { + return url_join( + $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], + $path, + $strip); + } + + function url_join($base, $path, $strip=false) { + $flags = $strip ? (http\Url::STRIP_PATH|http\URL::STRIP_QUERY) : 0; + return (new http\URL($base, null, $flags)) + ->mod(array ("path" => $path), http\Url::JOIN_PATH|http\URL::SANITIZE_PATH) + ->toString(); + } + + /** + * Feed `$json` to the backend and return the "(pecl) http response object" + * corresponding to the `$backend_relative_url` call + */ + function post_to_backend($backend_relative_url, $json){ + $url = url_join("https://backend.demo.taler.net/", $backend_relative_url); + $req = new http\Client\Request("POST", + $url, + array ("Content-Type" => "application/json")); + $req->getBody()->append($json); + // Execute the HTTP request + $client = new http\Client; + $client->enqueue($req)->send(); + return $client->getResponse(); + } + +?> diff --git a/php/index.php b/php/index.php @@ -4,7 +4,7 @@ <title>Taler tutorial</title> </head> <body> - <form action='/php/donate-handler.php'> + <form action='/php/donate-handler.php' method='GET'> <input type='submit' value='Donate!'></input> </form> </body>