tuna.js Library#
The Tuna JavaScript libraries will allow you to tokenize customer information, collect sensitive card data and accept payments on your website. In this section, you will find all details, features and configurations to run these libraries at your web page.
To start using Tuna JavaScript library is as easy as including the tuna.js file in your checkout page. It is highly recommended that you do not store the js file at your server, for security reasons.
npm
It can also be added to your Node.js project with the npm package, which supports both JavaScript and TypeScript.
Integration methods#
You can choose between using tuna.js to generate a complete payment form with tokenization and payment in a transparent way, or you can use it to just render the form and take care of tokenization while handling the payment API calls yourself at your backend system. Optionally you can use tuna.js solely to handle tokenization(in that case you need to be carefull not to send sensitive credit card data to your backend).
When you create a sessionID on your backend, you can choose to associate this session with just customer data or customer + order. This choice will vary according to the type of integration you'll use to connect to our Payment API, which can be either through backend or using Tuna JS.
When your backend places the payment API calls#
Here you only need to send customer data when creating the sessionID.

When tuna.js places the payment API calls#
Here the sessionID must have been generated including the order identifier. Keep in mind that since the payment is done before submitting the order to your backend, you must check that the order total matches with the total paid amount by either using a webhook or polling the payment status.

Getting started: Adding tuna.js#
You can choose to use tuna.js to create a brand new checkout page or to link your checkout with Tuna connections. Below you'll see how to do the second option. To use the tuna.js to create a new checkout page and enjoy all facilities we provide, check it out here.
1<script src="https://js.tuna.uy/tuna-essentials.js"></script>tuna.js V2
1<script src="https://storage.googleapis.com/tuna-statics/tuna-v2.js"></script>tuna.js V2 CSS file
1<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/tuna-statics/components.min.css">Initializing Tuna#
Use the session ID generated by you backend to start Tuna.
Use keys with only lowercase alphanumeric characters
Configuring antifrauds#
Injects at the page the data collection scripts of all antifrauds providers linked to your Tuna account. You should use the antifraudConfig parameter at Tuna initialization to provide the following information about the customer session for each anti-fraud provider you use.
| ClearSale | SiftScience | Konduto | CyberSource |
|---|---|---|---|
| sessionid | userid, sessionid | customerid | sessionid |
Aditionally, you need to choose wich antifraud scripts you will inject. Do that by adding a another { key, value } object using the antifraud name as key and the antifraud public key as value. Look to the example bellow:
1const tuna = Tuna(sessionId, [
2 { key: "sessionid", value: "6de61205-00ad-4068-b8bd-25a12ab9b305" },
3 { key: "customerid", value: "321" },
4 { key: "konduto", value: "konduto_key" },
5 { key: "cybersource", value: "cybersource_key" },
6]);
In the example above, were filled the requirements to inject the data collection scripts of Konduto and CyberSource antifraud
Initializing Click to Pay#
Before using Click to Pay methods, you need to initialize the Click to Pay service. This method must be called before any other Click to Pay operations.
Authenticating with Click to Pay#
Use this method to authenticate a user with Click to Pay using their email address or mobile phone number.
Accessing the Tuna tokenization connection#
Use the Tuna tokenization connection through the tuna.js library to create PCI compliant card tokens.
1const tuna = Tuna(sessionId);
2const tokenizator = tuna.tokenizator();