summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2016-11-16 13:44:07 +0100
committerMarcello Stanisci <marcello.stanisci@inria.fr>2016-11-16 13:44:07 +0100
commit5ab43610c68dfecaa34fc13ad7017cb025f1e32c (patch)
tree069c1d4bdd0c2822beb0250286616cebbe23989c
parent07ea3d666e572fa2a2bdc8dfdf3b7a40a32487bb (diff)
downloadmerchant-frontend-examples-5ab43610c68dfecaa34fc13ad7017cb025f1e32c.tar.gz
merchant-frontend-examples-5ab43610c68dfecaa34fc13ad7017cb025f1e32c.tar.bz2
merchant-frontend-examples-5ab43610c68dfecaa34fc13ad7017cb025f1e32c.zip
Finishing with payment
-rw-r--r--php/backend.php3
-rw-r--r--php/config.php4
-rw-r--r--php/contract.php10
-rw-r--r--php/doc/tutorial.texi52
-rw-r--r--php/donate.php (renamed from php/donate-handler.php)0
-rw-r--r--php/fulfillment.php1
-rw-r--r--php/helpers.php6
-rw-r--r--php/index.php2
-rw-r--r--php/pay.php2
9 files changed, 50 insertions, 30 deletions
diff --git a/php/backend.php b/php/backend.php
index 68065df..418da95 100644
--- a/php/backend.php
+++ b/php/backend.php
@@ -1,6 +1,8 @@
<?php
include 'copying.php';
+ include_once 'config.php';
+ include_once 'helpers.php';
/**
* 'body' is an object, representing the JSON to POST. NOTE: we do NOT
@@ -22,6 +24,7 @@
array('Content-Type: application/json'));
curl_setopt_array($c, $options);
$r = curl_exec($c);
+ file_put_contents("/tmp/php.out", print_r($r, true));
return array("status_code" => curl_getinfo($c, CURLINFO_HTTP_CODE),
"body" => $r);
}
diff --git a/php/config.php b/php/config.php
index 39ea8dd..034ece9 100644
--- a/php/config.php
+++ b/php/config.php
@@ -1,5 +1,9 @@
<?php
+ // This config file is in the public domain.
+
$BACKEND = "https://backend.test.taler.net/";
+ // The currency must match the one used by the backend.
+ $CURRENCY = "PUDOS";
?>
diff --git a/php/contract.php b/php/contract.php
index a7b2069..b522a94 100644
--- a/php/contract.php
+++ b/php/contract.php
@@ -1,16 +1,18 @@
<?php
include 'copying.php';
+ include_once 'helpers.php';
+ include_once 'config.php';
function make_contract($transaction_id, $now){
$contract = array ('amount' =>
array ('value' => 1,
'fraction' => 0,
- 'currency' => "KUDOS"),
+ 'currency' => $GLOBALS['CURRENCY']),
'max_fee' =>
array ('value' => 0,
'fraction' => 50000,
- 'currency' => "KUDOS"),
+ 'currency' => $GLOBALS['CURRENCY']),
'transaction_id' => $transaction_id,
'products' => array (
array ('description' => "Donation to charity program",
@@ -18,7 +20,7 @@
'price' =>
array ('value' => 1,
'fraction' => 0,
- 'currency' => "KUDOS"),
+ 'currency' => $GLOBALS['CURRENCY']),
'product_id' => 0,
'taxes' => array(),
'delivery_date' => "/Date(" . $now->getTimestamp() . ")/",
@@ -29,7 +31,7 @@
. "transaction_id=$transaction_id&timestamp="
. $now->getTimestamp()),
'repurchase_correlation_id' => '',
- 'expiry' =>
+ 'pay_deadline' =>
"/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/",
'refund_deadline' =>
"/Date(" . $now->add(new DateInterval('P3M'))->getTimestamp() . ")/",
diff --git a/php/doc/tutorial.texi b/php/doc/tutorial.texi
index d10441a..41293f8 100644
--- a/php/doc/tutorial.texi
+++ b/php/doc/tutorial.texi
@@ -1,8 +1,8 @@
\input texinfo @c -*-texinfo-*-
@c %**start of header
-@setfilename manual.info
+@setfilename tutorial.info
@include version.texi
-@settitle The GNU Taler manual for Web shop operators @value{VERSION}
+@settitle The GNU Taler tutorial for Web shop developers @value{VERSION}
@c Define a new index for options.
@defcodeindex op
@@ -12,7 +12,8 @@
@c %**end of header
@copying
-This manual is for the GNU Taler merchant backend (version @value{VERSION}, @value{UPDATED}),
+This tutorial is about implementing a merchant frontend to run against a
+GNU Taler merchant backend (version @value{VERSION}, @value{UPDATED}),
Copyright @copyright{} 2016 INRIA
@@ -25,14 +26,14 @@ Texts. A copy of the license is included in the section entitled
``GNU Free Documentation License''.
@end quotation
@end copying
-@c If your manual is published on paper by the FSF, it should include
+@c If your tutorial is published on paper by the FSF, it should include
@c The standard FSF Front-Cover and Back-Cover Texts, as given in
@c maintain.texi.
@c
@c Titlepage
@c
@titlepage
-@title The GNU Taler manual for Web shops
+@title The GNU Taler tutorial for Web shops
@subtitle Version @value{VERSION}
@subtitle @value{UPDATED}
@author Marcello Stanisci (@email{marcello.stanisci@@inria.fr})
@@ -47,12 +48,12 @@ Texts. A copy of the license is included in the section entitled
@ifnottex
@node Top
-@top The GNU Taler manual for Web shops
+@top The GNU Taler tutorial for Web shops
@insertcopying
@end ifnottex
@menu
-* Introduction:: Whom this manual is addressed to
+* Introduction:: Whom this tutorial is addressed to
* Hello-world:: How to set up a minimalistic shop
* Back-office-integration:: How to integrate with the back office
* Advanced topics:: Detailed solutions to specific issues
@@ -74,9 +75,9 @@ know-your-customer (KYC) regulation, as well as data protection
regulation (such as GDPR).
-@section About this manual
+@section About this tutorial
-This manual is for Web developers and addresses how to integrate GNU Taler
+This tutorial is for Web developers and addresses how to integrate GNU Taler
with Web shops. It describes how to create a Web shop that cooperates with
a GNU Taler merchant @emph{backend}.
@@ -95,18 +96,26 @@ The Taler software stack for a merchant consists of four main components:
frontend enables the customer to build a shopping cart and place
an order. Upon payment, it triggers the respective business logic
to satisfy the order. This component is not included with Taler,
- but rather assumed to exist at the merchant. This manual
- describes how to integrate Taler with Web shop frontends.
+ but rather assumed to exist at the merchant. This tutorial
+ describes how to develop a Taler frontend.
@item A back office application that enables the shop operators to
view customer orders, match them to financial transfers, and possibly
approve refunds if an order cannot be satisfied. This component is
again not included with Taler, but rather assumed to exist at the
- merchant. This manual will describe how to integrate such a component
- to handle payments managed by Taler.
+ merchant. This tutorial will describe how to integrate such a component
+ to handle payments managed by Taler. Such integration is shown by
+ adding the back office functionality to the frontend implemented
+ in the first part of this tutorial.
@item A Taler-specific payment backend which makes it easy for the
- frontend to process financial transactions with Taler. The
- next two chapters will describe how to install and configure
- this backend.
+ frontend to process financial transactions with Taler. Note that
+ the frontend implemented in this tutorial is configured by default
+ to run against a public backend, which has been set-up at
+ @code{http://backend.demo.taler.net/} for testing frontends.
+ In order to point the frontend being developed in this tutorial
+ to some other backend, it suffices to set the variable @code{$BACKEND}
+ in @code{php/config.php} to the desired backend's base URL.
+
+
@item A DBMS which stores the transaction history for the Taler backend.
For now, the GNU Taler reference implemenation only supports Postgres,
but the code could be easily extended to support another DBMS.
@@ -135,6 +144,9 @@ the ``donate'' button is clicked, the customer will receive a Taler
contract offering him the opportunity to make a fixed donation,
for example to donate 1 KUDOS to the charity operating the shop.
+Please note the all the code samples shown below in the tutorial
+are contained in @code{php/doc/samples.zip}.
+
@c NOTE: include explaining wallet installation to Web developer here!
Note that if the customer does not have the Taler wallet installed,
@@ -150,7 +162,7 @@ to the frontend @code{/donate} URL. For this, the HTML would be as
follows:
@smallexample
-<form action="/donate-handler.php">
+<form action="/donate.php">
<input type="submit" value="Donate!"></input>
</form>
@end smallexample
@@ -163,11 +175,11 @@ it will return a HTML page that will take care of:
@item fetching a Taler contract and passing it to the wallet if one is found
@end itemize
-A minimalistic @code{/donate-handler.php} implementation is shown below (in PHP):
+A minimalistic @code{donate.php} implementation is shown below (in PHP):
@smallexample
-// php/donate-handler.php
-@include ../donate-handler.php
+// php/donate.php
+@include ../donate.php
@end smallexample
Given this response, the Taler wallet will fetch the contract from
diff --git a/php/donate-handler.php b/php/donate.php
index 82c10ab..82c10ab 100644
--- a/php/donate-handler.php
+++ b/php/donate.php
diff --git a/php/fulfillment.php b/php/fulfillment.php
index 19be498..62d9510 100644
--- a/php/fulfillment.php
+++ b/php/fulfillment.php
@@ -3,7 +3,6 @@
include 'copying.php';
include 'contract.php';
include 'backend.php';
- include 'helpers.php';
include 'error.php';
session_start();
diff --git a/php/helpers.php b/php/helpers.php
index 38cf1fc..dafaef2 100644
--- a/php/helpers.php
+++ b/php/helpers.php
@@ -10,9 +10,9 @@
}
function url_join($base, $path) {
- // Please note that this trivial way of joining URLs is
- // dur to avoiding using pecl_http and to NOT bloat too
- // much tutorial code.
+ // Please note that this simplistic way of joining URLs is
+ // to avoiding using pecl_http (painful installation!) and
+ // to NOT bloat too much tutorial code.
return $base . $path;
}
diff --git a/php/index.php b/php/index.php
index e8e105a..6a16803 100644
--- a/php/index.php
+++ b/php/index.php
@@ -7,7 +7,7 @@
<title>Taler tutorial</title>
</head>
<body>
- <form action='/donate-handler.php' method='GET'>
+ <form action='/donate.php' method='GET'>
<input type='submit' value='Donate!'></input>
</form>
</body>
diff --git a/php/pay.php b/php/pay.php
index f0bbe65..702769c 100644
--- a/php/pay.php
+++ b/php/pay.php
@@ -11,7 +11,7 @@
// Get coins.
$body = file_get_contents('php://input');
$response = post_to_backend("/pay", json_decode($body));
- http_response_header($response['status_code']);
+ http_response_code($response['status_code']);
if (200 != $response['status_code']){
echo build_error($response, "Could not send paymnet to backend");
return;