summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2016-11-30 14:30:11 +0100
committerMarcello Stanisci <marcello.stanisci@inria.fr>2016-11-30 14:30:11 +0100
commit092b003a090bb5cdbe00e55eaa49ea00027e28d9 (patch)
tree2a43e02d9ceadb2fff865f47888ce3567908a579 /doc
parente3e4043ffa294f41e57c84927ea4267b2ded756b (diff)
downloadmerchant-092b003a090bb5cdbe00e55eaa49ea00027e28d9.tar.gz
merchant-092b003a090bb5cdbe00e55eaa49ea00027e28d9.tar.bz2
merchant-092b003a090bb5cdbe00e55eaa49ea00027e28d9.zip
Removing tutorial leftovers
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/donate_handler.php12
-rw-r--r--doc/examples/fulfillment_handler.php46
-rw-r--r--doc/examples/generate_contract.php76
-rw-r--r--doc/examples/pay_handler.php20
-rw-r--r--doc/examples/post_to_backend.php14
5 files changed, 0 insertions, 168 deletions
diff --git a/doc/examples/donate_handler.php b/doc/examples/donate_handler.php
deleted file mode 100644
index 32775869..00000000
--- a/doc/examples/donate_handler.php
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
- http_response_code (402); // 402: Payment required
- header ('X-Taler-Contract-Url: /generate-contract');
-?>
-<html>
- <head>
- <title>Select payment method</title>
- </head>
- <body>
- Here you should put the HTML for the non-Taler (credit card) payment.
- </body>
-</html>
diff --git a/doc/examples/fulfillment_handler.php b/doc/examples/fulfillment_handler.php
deleted file mode 100644
index 6f091785..00000000
--- a/doc/examples/fulfillment_handler.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<html>
- <head>
- <title>Donation Fulfillment</titile>
- </head>
- <body>
- <?php
- # At first, check if the user has already paid for the product.
- # If so, deliver the product.
- session_start();
- if (! isset($_SESSION['paid']))@{
- # set as pending
- $_SESSION['paid'] = false;
- @}
- else@{
- if($_SESSION['paid'])@{
- echo "<p>Thanks for your donation!</p>";
- return;
- @}
- else@{
- # Generate page to show for payments with credit cards instead.
- echo '<form action="/cc-payment">
- Name<br> <input type="text"></input><br>
- CC number<br> <input type="text"></input><br>
- Cvv2 code<br> <input type="text"></input><br>
- <input type="submit"></input>
- </form>';
- return;
- @}
- @}
-
- # Reconstruct the contract
- $rec_proposal = make_contract($_GET['transaction_id'], $_GET['timestamp']);
- # $response corresponds to the specification at:
- # https://api.taler.net/api-merchant.html#offer
- $response = post_to_backend("/contract", $rec_proposal);
-
- http_response_code (402);
-# FIXME: this can't be right, you want to call "json_deocde", not
-# return it as a literal string in the header! (i.e. insert '. before json_decode and remove ' at the end)?
-# All this code should be tested!
- header ('X-Taler-Contract-Hash: ' . json_decode($response)["H_contract"]);
- header ('X-Taler-Offer-Url: /donate');
- header ('X-Taler-Pay-Url: /pay'); ?>
- </body>
-</html>
-
diff --git a/doc/examples/generate_contract.php b/doc/examples/generate_contract.php
deleted file mode 100644
index de9770f5..00000000
--- a/doc/examples/generate_contract.php
+++ /dev/null
@@ -1,76 +0,0 @@
-function make_contract($transaction_id, $now) @{
- $contract =
- array (
- 'amount' => array (
- 'value' => 1,
- 'fraction' => 0,
- 'currency' => "KUDOS"),
- 'max_fee' => array (
- 'value' => 0,
- 'fraction' => 50000,
- 'currency' => "KUDOS"),
- 'transaction_id' => $transaction_id,
- 'products' => array (
- array (
- 'description' => "Donation to charity program",
- 'quantity' => 1,
- 'price' => array (
- 'value' => 1,
- 'fraction' => 0,
- 'currency' => "KUDOS"),
- 'product_id' => 0,
- 'taxes' => array(), // No taxes for donations
- 'delivery_date' => "/Date(" . $now->getTimestamp() . ")/",
- 'delivery_location' => 'LNAME1')),
- 'timestamp' => "/Date(" . $now->getTimestamp() . ")/",
- 'expiry' =>
- "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/",
- 'refund_deadline' =>
- "/Date(" . $now->add(new DateInterval('P3M'))->getTimestamp() . ")/",
- 'repurchase_correlation_id' => '',
- 'fulfillment_url' =>
- "https://shop.com/fulfillment?"
- . "transaction_id=$transaction_id&timestamp=$now",
- 'merchant' => array (
- 'address' => 'LNAME1',
- 'name' => "Charity donations shop",
- 'jurisdiction' => 'LNAME2'),
- 'locations' => array (
- 'LNAME1' =>
- array (
- 'country' => 'Shop Country',
- 'city' => 'Shop City',
- 'state' => 'Shop State',
- 'region' => 'Shop Region',
- 'province' => 'Shop Province',
- 'ZIP code' => 4908,
- 'street' => 'Shop street',
- 'street number' => 20),
- 'LNAME2' => array (
- 'country' => 'Legal Country',
- 'city' => Legal City',
- 'state' => 'Legal State',
- 'region' => 'Legal Region',
- 'province' => 'Legal Province',
- 'ZIP code' => 4908)));
-@}
-
-
-/* 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 */
-$transaction_id = rand(1,90000); // simplified, do not do this!
-$proposal = make_contract($transaction_id, new DateTime('now'));
-
-# Here the frontend POSTs the proposal to the backend
-$response = post_to_backend("/contract", $proposal);
-
-if (200 != $response->getResponseCode()) @{
- echo json_encode(array(
- 'error' => "internal error",
- 'hint' => "failed to generate contract",
- 'detail' => $resp->body->toString()
- ), JSON_PRETTY_PRINT);
- return;
-@}
-echo $response->body;
diff --git a/doc/examples/pay_handler.php b/doc/examples/pay_handler.php
deleted file mode 100644
index 3b10b0c2..00000000
--- a/doc/examples/pay_handler.php
+++ /dev/null
@@ -1,20 +0,0 @@
-# Check if a session exists already
-session_start();
-if (! isset($_SESSION['paid'])) @{
- echo "<p>There is no session for this purchase. Something is wrong.</p>";
- return;
-@}
-# Get the HTTP POST body
-$payment = file_get_contents('php://input');
-$response = post_to_backend("/pay", $payment);
-if (200 != $response->getResponseCode())@{
- echo json_encode(array(
- 'error' => "internal error",
- 'hint' => "failed to POST coins to the backend",
- 'detail' => $response->body->toString()
- ), JSON_PRETTY_PRINT);
- return;
-@}
-$_SESSION['paid'] = true;
-return $response->body;
-
diff --git a/doc/examples/post_to_backend.php b/doc/examples/post_to_backend.php
deleted file mode 100644
index e89b5283..00000000
--- a/doc/examples/post_to_backend.php
+++ /dev/null
@@ -1,14 +0,0 @@
-function post_to_backend($backend_relative_url, $json)@{
- $url = "https://shop.com$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();
-@}