There are two ways to perform a payment transaction at Tuna. They are as follows:
- Card Tokenization: mandatory when paying with a credit card;
- Direct Request: for other payment methods, such as Boleto, PIX, Bitcoin and Nupay.
Payment Integration in the Frontend or Backend!?
All requests for Tuna serves must come from a backend application due to security reasons with your production keys. Thus, if a request is handling data that comes from your frontend application, your frontend must request for your backend to communicate with Tuna servers. Finally, your backend will handle the response and pass the result to your frontend.
On this page, it is shown how to perform the integration using Tuna's Sandbox Environment. Let's start it out.
To perform credit card payments, you must use our api/Token. The api/Token is responsible for creating a unique session for your customer at Tuna and the tokenization process of credit card data following Payment Card Industry Data Security Standard ("PCI DSS").
There are three steps in performing a payment transaction with credit card:
- Step 1: start a new session for your customer;
- Step 2: create a valid credit card token. This process can be done in two ways:
- using a new credit card;
- using a stored credit card (from previous sessions).
- Step 3: request for the payment transaction at Tuna's api/Payment/Init endpoint.
In this step, the request is for the endpoint api/Token/NewSession. If you need more information about this endpoint, check it out here.
You can do this step only at the checkout page.
There are two ways to create a valid credit card token:
When you have a new customer, it is the first the credit card is going to be used. So, you need to create the token for the credit card. This is done through the endpoint api/Token/Generate. The exemplary request and response is shown bellow:
If you have a recurring customer, you can ask Tuna for stored credit card tokens. This is performed by making a request for the endpoint api/Token/List, which will respond with a list of available tokens. Then, at your frontend, the customer will select a credit card and confirm its CVV for security reasons. After the confirmation, a request for the api/Token/Bind endpoint is required to validate the token with its CVV. Now, please, check out the examples that follow.
Exemplary request and response for the api/token/List endpoint
Exemplary request and response for the api/Token/Bind endpoint
Once the tokenization process is successful, you can request the payment transaction, which is performed through the endpoint api/Payment/Init. Here is shown a request and response for a credit card transaction:
For other payment methods, such as Boleto, PIX, Bitcoin and Nupay, you can directly request the payment transaction at Tuna's api/Payment/Init endpoint. This is almost the same as Step 3 taken for the Card Tokenization. The only difference is that when performing a direct request, you don't need to send the sessionId used as tokenSession for the request.
Increase your approval rates
If you are implementing a major integration with Tuna, using multiple payment methods, you should perform an extra step to start a new session for your customer. This is the same as Step 1 taken for the Card Tokenization, and it would be already implemented in your backend for credit card payment. Performing this step leverages the increase in your approval rates.
Examples for all payment methods
Check out the documentation of the api/Payment/Init endpoint and look for more examples on the right side of the page. You will find examples of requests and responses for Boleto, PIX, Bitcoin, Split, Gift Card, and much more.