Tuna.js Reference
This is the reference for the Javascript tokenization library. You will find all details, objects and configurations needed to run the library from the browser using js. You can use our Plugin Javascript to to tokenize customer information, collect sensitive card data and accept payments on your website.
The information is divided in sections:
Get started: Add tuna.js
To start using tuna.js is easy as including tuna.js in your checkout page. To your own safety, do not store the js file at your server; you should always load it directly from https://js.tuna.uy
<script src="https://js.tuna.uy/tuna.js"></script>
You can choose whether to use your own style components, or ours. To use our default style: you should include the .css classes to your checkout page. Add the file that is bellow
<script src="https://js.tuna.uy/css/components.css"></script>
Accessing the Tuna tokenization service
Use the Tuna Tokenization Service throw the Tuna.js library to create PCI Compliant credit card tokens.
const tuna = Tuna(sessionId);
const tokenizator = tuna.tokenizator();
tokenizator.list ()
List saved card tokens to the given user session id.
object
Token service response object.
tokensarray
The array of tokens.
codenumber
The response code.
messagestring
Response message.
tokenizator.generate ()
Create a new credit card token entry
cardDataobjectOPTIONAL
Object containing the credit card data to be tokenized.
cardHolderNamestring
The credit card holder name.
cardNumberstring
The credit card number.
expirationMonthnumber
The credit card expiration month.
expirationYearnumber
The credit card expiration year.
singleUsebool
Flag to identify if the token needs to be stored or not.
object
Token service response object containing the generated token.
tokenstring
The generated card token.
brandstring
The credit card brand.
codenumber
The response code.
messagestring
Response message.
Using the Piece Manager
The Piece Manager is the object responsible to create, treat and configure the UI elements at screen. You can use it to forge interface pieces as inputs, checkboxes and else elements that you need.
tuna.pieceManager ()
This method create the PieceManager instance which allow to create UI pieces.
object
The pieceManager instance.
let pieceManager = tuna.pieceManager();
pieceManager.forge ()
This method is responsible to create the UI elements.
placestringREQUIRED
The selector that identify the cointainer element where the piece will be placed.
optionsobjectOPTIONAL
The specific piece options for the choosen piece. When null, a empty options object will be used.
groupstringOPTIONALDEFAULT:"default"
The component's group name.
propertyNamestringOPTIONAL
The name of the property at the returned object.
Each piece has its own default name. Use this parameter only when the intention was override the default name or when using the following piece types:
formattedInput,
input.
validationFunctionfunctionOPTIONAL
int
The internal id of the generated piece.
pieceManager.destroy ()
Remove the UI element from the screen
pieceIDintREQUIRED
The id of the piece returned when the piece was forged.
pieceManager.changeGroupEnableStatus ()
Change the status (enabled/disabled) of all components at the given group. Once disabled, the UI elements will not be considered to the checkout proccess and the validation functions will not be triggered.
enabledboolREQUIRED
The enable/disable status to be setted at each group element
pieceManager.destroyGroup ()
Destroy all elements of the given group.
preserveRootboolREQUIRED
Flag to choose if the root element should be preserved or not when destroing the element.
Piece Types
There are 10 different types of UI elements that should be used to create the payment form. Each element accept a set of properties that can be used to configure aspects as: field label, validation message, css classes and so on. You can see all pieces that Tuna implemented and their configurations bellow:
input
A simple input text.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
placeholderstring
The input placeholder.
validationMessageClassstring
The CSS class used in the validation message element.
allowValidationMessagesboolDEFAULT: true
Flag that identify that the field is allowed to show validation messages.
validationMessagestringDEFAULT: "Please use a valid value"
The message that will be displayed when the field value is not valid.
formattedInput
A customizable formatted input text.
patternstringREQUIRED
The pattern used to format the input: use "A" for letters and "9" for numbers. E.g. 999.999.999-99 for brazilian CPF (citizen identification number).
cleanMaskbool
A flag to set up if the inputted value will have the mask cleaned or not when returned.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
placeholderstring
The input placeholder.
validationMessageClassstring
The CSS class used in the validation message element.
allowValidationMessagesboolDEFAULT: true
Flag that identify that the field is allowed to show validation messages.
validationMessagestringDEFAULT: "Please use a valid value"
The message that will be displayed when the field value is not valid.
document
A customizable input text to receive and validate the buyer document data. The inputed value will be returned in the document property.
cleanMaskbool
A flag to set up if the inputted value will have the mask cleaned or not when returned.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
placeholderstring
The input placeholder.
validationMessageClassstring
The CSS class used in the validation message element.
allowValidationMessagesboolDEFAULT: true
Flag that identify that the field is allowed to show validation messages.
validationMessagestringDEFAULT: "Please use a valid value"
The message that will be displayed when the field value is not valid.
button
A simple button that can be used to trigger the checkout process.
titlestring
The title of the button.
buttonClassstring
The CSS class used in the button.
iconClassstring
The CSS class used in the button icon.
showIconbool
A flag to set if the button icon will be showed or not.
onclickfunction
A function that will be called when the button was clicked.
cardHolderName
An input text already setted to keep the card holder name data. The inputed value will be returned in the cardHolderName property.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
placeholderstring
The input placeholder.
validationMessageClassstring
The CSS class used in the validation message element.
allowValidationMessagesboolDEFAULT: true
Flag that identify that the field is allowed to show validation messages.
validationMessagestringDEFAULT: "Please use a valid value"
The message that will be displayed when the field value is not valid.
cardNumber
A formatted input text already setted to keep and treat the credit card number. The inputed value will be returned in the cardNumber property.
showCardBrandbool
A flag to set or not the display of the credit card brand icon.
cardBrandClassstring
The css class name to use in the card brand icon.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
placeholderstring
The input placeholder.
validationMessageClassstring
The CSS class used in the validation message element
allowValidationMessagesboolDEFAULT: true
Flag that identify that the field is allowed to show validation messages.
validationMessagestringDEFAULT: "Please use a valid value"
The message that will be displayed when the field value is not valid.
cardCvv
A formatted input text already setted to keep and treat the credit card cvv. The inputed value will be returned in the cvv property.
showCVVImagebool
A flag to set or not the display of the cvv icon.
cvvImageClassstring
The css class name to use in the cvv icon.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
placeholderstring
The input placeholder.
validationMessageClassstring
The CSS class used in the validation message element.
allowValidationMessagesboolDEFAULT: true
Flag that identify that the field is allowed to show validation messages.
validationMessagestringDEFAULT: "Please use a valid value"
The message that will be displayed when the field value is not valid.
cardValidity
A formatted input text already setted to keep and treat the credit card expiration containing the expiration month and year. The inputed value will be returned in the expirationMonth and expirationYear properties.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
placeholderstring
The input placeholder.
validationMessageClassstring
The CSS class used in the validation message element.
allowValidationMessagesboolDEFAULT: true
This flag identify if the field is allowed to show validation messages
validationMessagestringDEFAULT: "Please use a valid value"
The message that will be displayed when the field value is not valid.
month
A formatted select box already setted to keep the expiration month. The selected value will be returned in the expirationMonth property.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
year
A formatted select box already setted to keep the validity year. The selected value will be returned in the expirationYear property.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
installment
A formatted select box to render the installment options. The selected value will be returned in the selectedInstallmentKey property.
optionsarrayREQUIRED
An array of { key, value } object containing the allowed installment options.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
inputClassstring
The CSS class used in the input.
saveCard
A checkbox that allows the user to save the card data for future transactions.
titlestring
The title of the field.
titleClassstring
The CSS class used in the field title.
checkedboolDEFAULT: true
The default state of the checkbox.
inputClassstring
The CSS class used in the input.
Adding saved card selector
We strongly recomend the saveCard object to increase the conversion rate of your checkout page. By implementing it, you also need to include the Saved Card Selector, so your users can choose the card that have already been saved directly in your checkout page.
async useSavedCardSelector ()
Create the saved card selector component.
placestringREQUIRED
The selector that identify the cointainer element where the piece will be placed.
optionsobjectOPTIONAL
The options to customize the component
onSelectionBeginsfunction
A function that runs when the saved card selection begins
cardCvvobject
The options to customize the cvv input field inside the saved card selector component
groupstringOPTIONAL
The component's group name
int
The number of returned saved cards. If returns 0, then the component will not be rendered.
clearSavedCardSelector ()
Clean all data setted in any saved card selector component. Including the cvv and ID card inputs.
Managing checkout
Tuna has two ways to proceed the checkout.
checkout ()
This method triggers the field validations, and then compile the inputted data in order to generate the payment credit card token. This callback function could also be setted in the Tuna method, as described
herecallbackFunctionfunctionOPTIONAL
The function the will be called after the field validation proccess returnig the tokenizator promisse and the inputed credit card data
tokenizatorPromissefunction
Promise to the tokenizator request response.
creditCardDataobject
The imputed data necessary to proceed with the finalization of the payment.
const response = await tuna.checkout();
async checkoutAsync ()
Similar to
checkout but awaitable.
object
The object containing the tokenizator response and the typed card data necessary to proceed with finalization of the payment.
cardDataobject
The imputed data necessary to proceed with the finalization of the payment.
tokenDataobject
The response object returned bay the tokenization proccess.
successbool
A success flag.
await tuna.checkoutAsync();