merchant-frontend-examples

ZZZ: Inactive/Deprecated
Log | Files | Refs

js-payments.texi (2240B)


      1 @c Section about triggering payments via JavaScript, currently not used!
      2 
      3 @node Payments using JavaScript
      4 @section Triggering payments using JavaScript
      5 @c
      6 Please note that the following examples are purely instructional and NOT TESTED
      7 along with the tutorial code.
      8 @c
      9 @cindex JavaScript
     10 @c
     11 @subsection Offering contracts
     12 @c
     13 Offering contracts the JavaScript way doesn't require us to set HTTP
     14 headers, and so -- in a minimalistic implementation -- the donation button
     15 should just hit a HTML page that invokes the @code{offerContractFrom} function,
     16 from the @code{taler-wallet-lib.js} library.
     17 @c
     18 Thus our homepage can now look as follows
     19 @c
     20 @smallexample
     21 // ../index-js.html
     22 @verbatiminclude ../index-js.html
     23 @end smallexample
     24 @c
     25 @code{donate-js.html} is now in charge of calling @code{offerContractFrom}
     26 passing the contract URL to it, which is @code{"/generate-order.php"} in
     27 our example.  See below.
     28 
     29 @c
     30 @smallexample
     31 // ../donate-js.html
     32 @verbatiminclude ../donate-js.html
     33 @end smallexample
     34 @c
     35 Please make sure that @code{taler-wallet-lib.js} location is valid.
     36 @c
     37 @subsection Receiving payments
     38 @cindex payment
     39 @c
     40 In the example in section @ref{Initiating the payment process}, the fulfillment
     41 handler @code{/fulfillment.php} triggers the payment in the wallet by returing
     42 the three needed values (contract hashcode, pay URL, offer URL) via HTTP headers.
     43 @c
     44 The same action can be accomplished @emph{with} JavaScript, thanks to
     45 @code{taler-wallet-lib.js} of @emph{web-common} repository.
     46 The fulfillment handler needs just to call the function @code{executePayment}, feeding it
     47 with the three needed parameters.  The wallet will then get triggered and proceed with the
     48 payment.  See below a full example:
     49 @c
     50 @smallexample
     51 // ../fulfillment-js.php
     52 @verbatiminclude ../fulfillment-js.php
     53 @end smallexample
     54 @c
     55 Note that, in order to use this fulfillment handler for the tutorial, you need to
     56 specify it in the contract's ``fulfillment_url'' field:
     57 @c
     58 @smallexample
     59 @{
     60 ... contract fields ..
     61 @c
     62 "fulfillment_url": "/fulfillment-js.php?transaction_id=<TRANSACTION_ID>& \
     63                    timestamp=<CONTRACTTIMESTAMP>"
     64 ...
     65 @}
     66 @end smallexample
     67 @c
     68 Additionally, you should also make sure that @code{taler-wallet-lib.js} location
     69 is valid.