summaryrefslogtreecommitdiff
path: root/common/texi/js-payments.texi
blob: 6c880692fc7eb75cdb61b7ed3259d0a9d551caa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@c Section about triggering payments via JavaScript, currently not used!

@node Payments using JavaScript
@section Triggering payments using JavaScript
@c
Please note that the following examples are purely instructional and NOT TESTED
along with the tutorial code.
@c
@cindex JavaScript
@c
@subsection Offering contracts
@c
Offering contracts the JavaScript way doesn't require us to set HTTP
headers, and so -- in a minimalistic implementation -- the donation button
should just hit a HTML page that invokes the @code{offerContractFrom} function,
from the @code{taler-wallet-lib.js} library.
@c
Thus our homepage can now look as follows
@c
@smallexample
// ../index-js.html
@verbatiminclude ../index-js.html
@end smallexample
@c
@code{donate-js.html} is now in charge of calling @code{offerContractFrom}
passing the contract URL to it, which is @code{"/generate-order.php"} in
our example.  See below.

@c
@smallexample
// ../donate-js.html
@verbatiminclude ../donate-js.html
@end smallexample
@c
Please make sure that @code{taler-wallet-lib.js} location is valid.
@c
@subsection Receiving payments
@cindex payment
@c
In the example in section @ref{Initiating the payment process}, the fulfillment
handler @code{/fulfillment.php} triggers the payment in the wallet by returing
the three needed values (contract hashcode, pay URL, offer URL) via HTTP headers.
@c
The same action can be accomplished @emph{with} JavaScript, thanks to
@code{taler-wallet-lib.js} of @emph{web-common} repository.
The fulfillment handler needs just to call the function @code{executePayment}, feeding it
with the three needed parameters.  The wallet will then get triggered and proceed with the
payment.  See below a full example:
@c
@smallexample
// ../fulfillment-js.php
@verbatiminclude ../fulfillment-js.php
@end smallexample
@c
Note that, in order to use this fulfillment handler for the tutorial, you need to
specify it in the contract's ``fulfillment_url'' field:
@c
@smallexample
@{
... contract fields ..
@c
"fulfillment_url": "/fulfillment-js.php?transaction_id=<TRANSACTION_ID>& \
                   timestamp=<CONTRACTTIMESTAMP>"
...
@}
@end smallexample
@c
Additionally, you should also make sure that @code{taler-wallet-lib.js} location
is valid.