Skip to main content

Overview

The Akatus.Carrinho.Carrinho class is the core component for processing transactions. It handles both credit card and boleto payments, managing cart setup, customer information, products, and transaction processing.

Setting Up a Transaction

Initialize the Cart

Start by creating a new instance of the Carrinho class:
Akatus.Carrinho.Carrinho carrinho = new Akatus.Carrinho.Carrinho();

Customer Information (Pagador)

Add the customer’s basic information:
// Customer name and email
carrinho.Pagador.Nome = "NOME CLIENTE";
carrinho.Pagador.Email = "[email protected]";

Customer Address (PagadorEndereco)

Add the customer’s address details:
Akatus.Carrinho.PagadorEndereco endereco = new Akatus.Carrinho.PagadorEndereco();
endereco.Tipo = Akatus.Enums.TipoEndereco.entrega;
endereco.Logradouro = "Rua Teste da Silva";
endereco.Numero = 0;
endereco.Bairro = "CENTRO";
endereco.Cidade = "Salvador";
endereco.Estado = "BA";
endereco.Pais = "BRA";
endereco.CEP = "40000000";

carrinho.Pagador.Enderecos.Add(endereco);
Address Types:
  • TipoEndereco.entrega - Delivery address
  • TipoEndereco.comercial - Commercial address

Customer Phone (PagadorTelefone)

Add the customer’s phone number:
Akatus.Carrinho.PagadorTelefone telefone = new Akatus.Carrinho.PagadorTelefone();
telefone.Tipo = Akatus.Enums.TipoTelefone.celular;
telefone.Numero = "7199990000";

carrinho.Pagador.Telefones.Add(telefone);
Phone Types:
  • TipoTelefone.celular - Mobile phone
  • TipoTelefone.comercial - Business phone
  • TipoTelefone.residencial - Residential phone

Adding Products

Add products to the cart:
Akatus.Carrinho.Produto produto = new Akatus.Carrinho.Produto();
produto.Codigo = "ABC1234567";
produto.Descricao = "Caixa de bombons sortidos";
produto.Quantidade = 1;
produto.Preco = 32.25m;
produto.Frete = 0;
produto.Peso = 0;
produto.Desconto = 0;

carrinho.Produtos.Add(produto);

Payment Methods

Processing Credit Card Payments

Configure the transaction for credit card payment:
carrinho.Transacao.MeioDePagamento = Akatus.Enums.MeioDePagamento.cartao_master;
carrinho.Transacao.Referencia = "OFP12345";
carrinho.Transacao.Moeda = "BRL";
carrinho.Transacao.DescontoTotal = 0;
carrinho.Transacao.PesoTotal = 0;
carrinho.Transacao.FreteTotal = 0;

// Credit card details
carrinho.Transacao.Cartao.Numero = "5453010000066167";
carrinho.Transacao.Cartao.NumeroParcelas = 2;
carrinho.Transacao.Cartao.CodigoSeguranca = "123";
carrinho.Transacao.Cartao.Expiracao = "05/2018";

// Cardholder information
carrinho.Transacao.Cartao.Portador.Nome = "AUTORIZAR";
carrinho.Transacao.Cartao.Portador.CPF = "721.726.663-78";
carrinho.Transacao.Cartao.Portador.Telefone = "7199990000";
Available Credit Cards:
  • MeioDePagamento.cartao_visa - Visa
  • MeioDePagamento.cartao_master - Mastercard
  • MeioDePagamento.cartao_amex - American Express
  • MeioDePagamento.cartao_elo - Elo
  • MeioDePagamento.cartao_diners - Diners Club

Processing the Transaction

Once all information is configured, process the transaction:
try
{
    // Send the cart and process the transaction
    Akatus.Carrinho.Retorno retorno = carrinho.processaTransacao();

    // Check if data was posted successfully
    if (retorno != null)
    {
        Console.WriteLine($"Carrinho: {retorno.Carrinho}");
        Console.WriteLine($"Status: {retorno.Status}");
        Console.WriteLine($"Transaction ID: {retorno.Transacao}");
        Console.WriteLine($"Return URL: {retorno.UrlRetorno}");
        Console.WriteLine($"Reference: {retorno.Referencia}");
    }
}
catch (Akatus.RestExcepction ex)
{
    // Handle Akatus API errors
    Console.WriteLine($"Status Code: {ex.StatusCode}");
    Console.WriteLine($"Status Description: {ex.StatusDesciption}");
    
    foreach (string error in ex.ErrorMessages)
    {
        Console.WriteLine($"Error: {error}");
    }
}
catch (Exception ex)
{
    // Handle general exceptions
    Console.WriteLine($"Exception: {ex.Message}");
}

Response Properties

The Akatus.Carrinho.Retorno object contains:
PropertyDescription
CarrinhoCart identifier
StatusTransaction status
TransacaoUnique transaction ID
UrlRetornoURL for payment completion
ReferenciaYour reference code for the transaction

Complete Example

using Akatus;
using Akatus.Carrinho;
using Akatus.Enums;

public class PaymentProcessor
{
    public void ProcessCreditCardPayment()
    {
        Carrinho carrinho = new Carrinho();
        
        // Customer info
        carrinho.Pagador.Nome = "João Silva";
        carrinho.Pagador.Email = "[email protected]";
        
        // Address
        PagadorEndereco endereco = new PagadorEndereco
        {
            Tipo = TipoEndereco.entrega,
            Logradouro = "Rua das Flores",
            Numero = 123,
            Bairro = "Centro",
            Cidade = "São Paulo",
            Estado = "SP",
            Pais = "BRA",
            CEP = "01000000"
        };
        carrinho.Pagador.Enderecos.Add(endereco);
        
        // Phone
        PagadorTelefone telefone = new PagadorTelefone
        {
            Tipo = TipoTelefone.celular,
            Numero = "11999990000"
        };
        carrinho.Pagador.Telefones.Add(telefone);
        
        // Product
        Produto produto = new Produto
        {
            Codigo = "PROD001",
            Descricao = "Premium Product",
            Quantidade = 1,
            Preco = 99.90m,
            Frete = 10.00m,
            Peso = 500,
            Desconto = 0
        };
        carrinho.Produtos.Add(produto);
        
        // Credit card transaction
        carrinho.Transacao.MeioDePagamento = MeioDePagamento.cartao_visa;
        carrinho.Transacao.Referencia = "ORD-2024-001";
        carrinho.Transacao.Moeda = "BRL";
        carrinho.Transacao.Cartao.Numero = "4111111111111111";
        carrinho.Transacao.Cartao.NumeroParcelas = 3;
        carrinho.Transacao.Cartao.CodigoSeguranca = "123";
        carrinho.Transacao.Cartao.Expiracao = "12/2025";
        carrinho.Transacao.Cartao.Portador.Nome = "JOAO SILVA";
        carrinho.Transacao.Cartao.Portador.CPF = "123.456.789-00";
        carrinho.Transacao.Cartao.Portador.Telefone = "11999990000";
        
        try
        {
            Retorno retorno = carrinho.processaTransacao();
            // Handle success
        }
        catch (RestExcepction ex)
        {
            // Handle error
        }
    }
}

Next Steps

Payment Methods

Learn how to query available payment methods

Transaction Status

Check the status of your transactions

Payment Notifications

Receive real-time payment notifications

Error Handling

Handle errors and exceptions properly

Build docs developers (and LLMs) love