merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 3659ef6ec1aea6e1812acc3237927ac49211db2d
parent 497452a56803dd861794d477d8861efb594b5c7e
Author: Florian Dold <dold@inria.fr>
Date:   Sun, 20 Dec 2015 01:54:31 +0100

Relative backend URL.

Diffstat:
Msrc/frontend/checkout.php | 5+++--
Msrc/frontend/generate_taler_contract.php | 11+++++++----
Msrc/frontend/pay.php | 31+++++++++++++++++++------------
3 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/src/frontend/checkout.php b/src/frontend/checkout.php @@ -116,7 +116,7 @@ <input type="radio" name="payment_system" value="taler" id="taler-radio-button-id" disabled="true">Taler</input> <br/> - <input type="button" onclick="pay(this.form)" value="Ok"> + <input type="button" onclick="pay(this.form)" value="Ok"></input> </div> </form> @@ -155,7 +155,8 @@ function taler_pay(form) if (contract_request.status == 200) { /* display contract_requestificate (i.e. it sends the JSON string - to the extension) alert (contract_request.responseText); */ + to the extension) alert (contract_request.responseText); */ + console.log("response text:", contract_request.responseText); handle_contract(contract_request.responseText); } else diff --git a/src/frontend/generate_taler_contract.php b/src/frontend/generate_taler_contract.php @@ -155,11 +155,14 @@ if ($cli_debug && !$backend_test) exit; } -// Craft the HTTP request, note that the backend -// could be on an entirely different machine if -// desired. + + +// 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); + $req = new http\Client\Request ("POST", - "http://" . $_SERVER["SERVER_NAME"] . "/backend/contract", + $url, array ("Content-Type" => "application/json")); $req->getBody()->append ($json); diff --git a/src/frontend/pay.php b/src/frontend/pay.php @@ -39,6 +39,13 @@ if (isset($_GET['backend_test']) && $_GET['backend_test'] == 'no') $backend_test = false; } +if (!isset($_SESSION['receiver'])) +{ + echo "No session active."; + http_response_code (301); + return; +} + session_start(); $post_body = file_get_contents('php://input'); @@ -49,15 +56,15 @@ $edate = array ('edate' => $deposit_permission = json_decode ($post_body, true); -$to_add = array ('max_fee' => array ('value' => 3, - 'fraction' => 8, - 'currency' => $_SESSION['currency']), - 'amount' => array ('value' => $_SESSION['amount_value'], - 'fraction' => $_SESSION['amount_fraction'], - 'currency' => $_SESSION['currency'])); +$to_add = array('max_fee' => array('value' => 3, + 'fraction' => 8, + 'currency' => $_SESSION['currency']), + 'amount' => array('value' => $_SESSION['amount_value'], + 'fraction' => $_SESSION['amount_fraction'], + 'currency' => $_SESSION['currency'])); -$new_deposit_permission = array_merge ($deposit_permission, $to_add); -$new_deposit_permission_edate = array_merge ($new_deposit_permission, $edate); +$new_deposit_permission = array_merge($deposit_permission, $to_add); +$new_deposit_permission_edate = array_merge($new_deposit_permission, $edate); /* Craft the HTTP request, note that the backend could be on an entirely different machine if @@ -68,14 +75,14 @@ if ($cli_debug && !$backend_test) /* DO NOTE the newline at the end of 'echo's argument */ //echo json_encode ($new_deposit_permission_edate, JSON_PRETTY_PRINT) - echo json_encode ($new_deposit_permission, JSON_PRETTY_PRINT) + echo json_encode($new_deposit_permission, JSON_PRETTY_PRINT) . "\n"; exit; } -$req = new http\Client\Request ("POST", - "http://" . $_SERVER["SERVER_NAME"] . "/backend/pay", - array ("Content-Type" => "application/json")); +$req = new http\Client\Request("POST", + "http://" . $_SERVER["SERVER_NAME"] . "/backend/pay", + array ("Content-Type" => "application/json")); $req->getBody()->append (json_encode ($new_deposit_permission)); // Execute the HTTP request