Ruby client for the Conexa API - Billing and subscription management platform.
Add to your Gemfile:
gem 'conexa'Or install directly:
gem install conexaConexa.configure do |config|
config.subdomain = 'YOUR_SUBDOMAIN' # your-company.conexa.app
config.api_token = 'YOUR_API_TOKEN' # Application Token from Conexa
end- Application Token (recommended): Created in Conexa at Config > Integrações > API / Token
- Username/Password: Use the
/authendpoint to get a JWT token
require 'conexa'
Conexa.configure do |config|
config.subdomain = 'mycompany'
config.api_token = ENV['CONEXA_API_TOKEN']
end
# List customers
customers = Conexa::Customer.list
customers.data.each do |customer|
puts "#{customer.customer_id}: #{customer.name}"
end
# Get a specific customer
customer = Conexa::Customer.retrieve(127)
puts customer.name
puts customer.address.cityThis gem follows Ruby conventions:
- Parameters: Use
snake_casewhen calling methods - the gem automatically converts tocamelCasefor the API - Responses: API responses are converted from
camelCasetosnake_case - Backwards compatibility:
camelCasemethods are aliased (e.g.,customer.customer_idandcustomer.customerIdboth work)
# Create a customer (Legal Person - PJ)
customer = Conexa::Customer.create(
company_id: 3,
name: 'Empresa ABC Ltda',
trade_name: 'ABC',
cell_number: '11999998888',
has_login_access: false,
legal_person: {
cnpj: '99.557.155/0001-90',
foundation_date: '2020-06-12'
},
address: {
zip_code: '13058-111',
state: 'SP',
city: 'Campinas',
street: 'Rua Principal',
number: '100',
neighborhood: 'Centro'
},
phones: ['(11) 3333-4444'],
emails_message: ['contato@empresa.com'],
emails_financial_messages: ['financeiro@empresa.com']
)
puts customer.id # => 114
# Create a customer (Natural Person - PF)
customer = Conexa::Customer.create(
company_id: 3,
name: 'João Silva',
natural_person: {
cpf: '516.079.209-05',
birth_date: '1990-05-15',
profession: 'Developer'
},
has_login_access: true,
login: 'joao.silva',
password: 'SecurePass123!'
)
# Retrieve customer
customer = Conexa::Customer.retrieve(127)
customer.name # => "Empresa ABC Ltda"
customer.company_id # => 3
customer.is_active # => true
customer.address.city # => "Campinas"
customer.legal_person['cnpj'] # => "99.557.155/0001-90"
# Update customer
Conexa::Customer.update(127, name: 'New Name', cell_number: '11888887777')
# List customers with filters
customers = Conexa::Customer.list(
company_id: [3],
is_active: true,
page: 1,
size: 20
)# Create a contract
contract = Conexa::Contract.create(
customer_id: 127,
plan_id: 5,
start_date: '2024-01-01',
payment_day: 10,
invoicing_method_id: 1
)
# Create contract with custom items
contract = Conexa::Contract.create_with_products(
customer_id: 127,
start_date: '2024-01-01',
payment_day: 10,
items: [
{ product_id: 101, quantity: 1, amount: 299.90 },
{ product_id: 102, quantity: 2, amount: 49.90 }
]
)
# Retrieve contract
contract = Conexa::Contract.retrieve(456)
# Cancel contract
Conexa::Contract.cancel(456, cancel_date: '2024-12-31')# Create a one-time sale
sale = Conexa::Sale.create(
customer_id: 450,
requester_id: 458,
product_id: 2521,
quantity: 1,
amount: 80.99,
reference_date: '2024-09-24T17:24:00-03:00',
notes: 'WhatsApp order'
)
puts sale.id # => 188481
# Retrieve sale
sale = Conexa::Sale.retrieve(188510)
sale.status # => "notBilled"
sale.amount # => 80.99
sale.discount_value # => 69.21
# List sales
sales = Conexa::Sale.list(
customer_id: [450, 216],
status: 'notBilled',
date_from: '2024-01-01',
date_to: '2024-12-31',
page: 1,
size: 20
)
# Update sale
Conexa::Sale.update(188510, quantity: 2, amount: 150.00)
# Delete sale (only if not billed)
Conexa::Sale.delete(188510)# Create recurring sale
recurring = Conexa::RecurringSale.create(
customer_id: 127,
product_id: 101,
quantity: 1,
start_date: '2024-01-01'
)
# List recurring sales for a contract
Conexa::RecurringSale.list(contract_id: 456)# Retrieve charge
charge = Conexa::Charge.retrieve(789)
charge.status # => "paid"
charge.amount # => 299.90
charge.due_date # => "2024-02-10"
# List charges
charges = Conexa::Charge.list(
customer_id: [127],
status: 'pending',
due_date_from: '2024-01-01',
due_date_to: '2024-12-31'
)
# Cancel charge
Conexa::Charge.cancel(789)
# Send charge by email
Conexa::Charge.send_email(789)# Retrieve bill
bill = Conexa::Bill.retrieve(101)
# List bills
bills = Conexa::Bill.list(
customer_id: [127],
page: 1,
size: 50
)# List plans
plans = Conexa::Plan.list(company_id: [3])
# Retrieve plan
plan = Conexa::Plan.retrieve(5)
plan.name # => "Plano Básico"
plan.price # => 99.90# List products
products = Conexa::Product.list(company_id: [3])
# Retrieve product
product = Conexa::Product.retrieve(101)# Add credit card to customer
card = Conexa::CreditCard.create(
customer_id: 127,
card_number: '4111111111111111',
cardholder_name: 'JOAO SILVA',
expiration_month: '12',
expiration_year: '2025',
cvv: '123'
)
# List customer's cards
cards = Conexa::CreditCard.list(customer_id: 127)
# Delete card
Conexa::CreditCard.delete(card_id)# List companies/units
companies = Conexa::Company.list
# Retrieve company
company = Conexa::Company.retrieve(3)
company.name # => "Matriz"
company.document # => "12.345.678/0001-90"All list endpoints return paginated results:
result = Conexa::Customer.list(page: 1, size: 20)
result.data # Array of customers
result.pagination.current_page # => 1
result.pagination.total_pages # => 10
result.pagination.total_items # => 195
result.pagination.item_per_page # => 20
# Iterate through pages
loop do
result.data.each { |customer| process(customer) }
break if result.pagination.current_page >= result.pagination.total_pages
result = Conexa::Customer.list(page: result.pagination.current_page + 1)
endbegin
customer = Conexa::Customer.create(name: '')
rescue Conexa::ValidationError => e
# Field validation errors (400)
e.errors.each do |error|
puts "#{error['field']}: #{error['messages'].join(', ')}"
end
rescue Conexa::AuthenticationError => e
# Authentication required (401)
puts e.message
rescue Conexa::AuthorizationError => e
# Not authorized (403)
puts e.message
rescue Conexa::NotFoundError => e
# Resource not found (404)
puts e.message
rescue Conexa::UnprocessableError => e
# Business logic error (422)
e.errors.each do |error|
puts "#{error['code']}: #{error['message']}"
end
rescue Conexa::RateLimitError => e
# Too many requests (429)
puts "Rate limit exceeded. Retry after #{e.retry_after} seconds"
rescue Conexa::ApiError => e
# Generic API error
puts "Error #{e.status}: #{e.message}"
endThe Conexa API has a limit of 100 requests per minute. Response headers include:
X-Rate-Limit-Limit: Maximum requests in 60sX-Rate-Limit-Remaining: Remaining requests in 60sX-Rate-Limit-Reset: Seconds until reset
- Conexa Website
- API Documentation
- Postman Collection
- Discord Community - Conexa for Developers
- REFERENCE.md - Complete API reference for LLMs/AI agents
# Install dependencies
bundle install
# Run tests
bundle exec rspec
# Run linter
bundle exec rubocop- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -am 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Create a Pull Request
MIT License. See LICENSE for details.
See CHANGELOG.md for release history.