Tutorials

Tutorials 

This chapter describes the primary JavaScript pre-processing features that are available. Runtime includes a Duktape JS engine based processor supporting JavaScript/ECMAScript 5.1. More information available at www.duktape.org. 

ECMAScript5.1 specification is fully supported. Related JS functionality is documented at http://www.ecma-international.org/ecma-262/5.1/


The use of JavaScript is comparable to server side scripting; the script terminates before the dialog is displayed at all. Therefore, it has no access to the HTML DOM and cannot update elements while a dialog is shown. 

JavaScript scripts can be provided inside the <?js  … ?> XML processing instruction:


JavaScript Extensions

The following APIs have been added to JavaScript for Commerce Platform:

The ARGV object. Used to pass data into the Terminal Commerce application and is maintained during page transitions. Also, data passed as URL parameter during page transition is automatically added to ARGV array and is available on the next page. Additional data can be added to the ARGV container at any time using JavaScript, the same way data can be changed or deleted using JavaScript.
The ARGV object used for passing a flat map of key-value pairs. Values are restricted to basic types, objects cannot be passed.

Persistent Data. Terminal Commerce applications can store data persistently on flash drive.

Interacting with External Servers. XMLHTTPRequest class is provided for sending HTTP POST/GET requests. A TLS1.2 secured connection to VFI cloud is provided transparently to Terminal Commerce applications by the runtime proxy.

Sending and Receiving Notifications. Terminal Commerce applications can send out notifications with a JSON payload to:

  • Request service from a payment application (send and wait synchronously for answer)
  • Provide result data to payment application (asynchronously send and exit application)

Printing to Buffer. Terminal Commerce applications can also print to a buffer and send this buffer to the payment application to either forward it to a connected ECR or print as an addendum to the payment receipt. The provided functions generate an HTML document with images and barcodes included as inline images, so that the returned document is self-contained.

Using Text Catalogs. The runtime supports text catalogs to store texts that can be looked up from the HTML documents when using <?text ... ?> preprocessing instructions. The texts are stored in catalog files. By using catalog files, an application is able to separate texts from the HTML code, making it possible to create language independent HTML and template files.

Console Logs. For development purposes, a log call is provided that logs application output to the JavaScript console window in the Commerce Applications SDK simulator.
 

Try Catch -loop for the JS functionality

Good development practice is to use try – catch exception handling

• Include JS code within a try-block
• In case of runtime error (example: wrongly built payload for the notification function), the catch –block provides the exception-handling code
• Do not forget the proper app exit, and maybe a notification to the user as well