Skip to content

Colectiva Payment API

Colectiva is the central payment and billing hub for the RBS ecosystem.

Base URL: https://colectiva.redbroomsoftware.com


Overview

Colectiva provides:

  • Payment Processing: Cards, OXXO, SPEI via MercadoPago
  • Subscription Management: Recurring billing, trials, upgrades
  • Wallet System: MXC credits for ecosystem services
  • Trust Accounts: Segregated client funds (law firms)
  • AI Billing: Usage-based AI service metering
  • Ecosystem Registry: Organization and API key management

Authentication

http
Authorization: Bearer <api_key>
Content-Type: application/json

API Key Permissions

PermissionAccess
payments:readView payment status
payments:writeCreate payments
subscriptions:*Full subscription management
wallet:*Wallet operations
trust:*Trust account management
ecosystem:*Organization management
developer_accessGenerate support access tokens
*Full access (admin)

Key Endpoints

Payments

EndpointMethodDescription
/api/paymentsPOSTCreate payment
/api/payments/:idGETGet payment status
/api/payments/:id/refundPOSTRefund payment

Subscriptions

EndpointMethodDescription
/api/subscriptionsPOSTCreate subscription
/api/subscriptions/:idGETGet subscription
/api/subscriptions/:idPUTUpdate (upgrade/downgrade)
/api/subscriptions/:id/cancelPOSTCancel subscription
/api/subscriptions/:id/pausePOSTPause billing

Wallet

EndpointMethodDescription
/api/wallet/balanceGETGet current balance
/api/wallet/creditPOSTAdd credits
/api/wallet/debitPOSTDeduct credits
/api/wallet/transactionsGETTransaction history

Trust Accounts

EndpointMethodDescription
/api/trustGETList trust accounts
/api/trust/:idGETAccount details
/api/trust/:id/depositPOSTClient deposit
/api/trust/:id/withdrawPOSTAuthorized withdrawal
/api/trust/:id/statementGETGenerate statement

Ecosystem

EndpointMethodDescription
/api/ecosystem/orgsGETList organizations
/api/ecosystem/orgs/:idGETOrganization details
/api/developer-accessPOSTGenerate dev access token

Code Examples

Create a Card Payment

typescript
const response = await fetch('https://colectiva.redbroomsoftware.com/api/payments', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    amount: 1500.00,
    currency: 'MXN',
    method: 'card',
    description: 'Monthly subscription - Pro Plan',
    customer: {
      email: 'cliente@example.com',
      name: 'María García'
    },
    metadata: {
      subscription_id: 'sub_123',
      plan: 'pro'
    },
    return_url: 'https://myapp.com/payment/complete',
    webhook_url: 'https://myapp.com/api/webhooks/colectiva'
  })
});

const { payment_id, status, checkout_url } = await response.json();

if (status === 'pending') {
  // Redirect customer to checkout
  window.location.href = checkout_url;
}

Create OXXO Payment

typescript
const response = await fetch('https://colectiva.redbroomsoftware.com/api/payments', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    amount: 500.00,
    currency: 'MXN',
    method: 'oxxo',
    description: 'Order #12345',
    customer: {
      email: 'cliente@example.com',
      name: 'Juan Pérez'
    },
    expires_in_hours: 72  // OXXO voucher expiry
  })
});

const { payment_id, oxxo_reference, oxxo_barcode, expires_at } = await response.json();
// Display OXXO reference number to customer

Create Subscription

typescript
const response = await fetch('https://colectiva.redbroomsoftware.com/api/subscriptions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    plan_id: 'plan_pro_monthly',
    customer: {
      email: 'business@example.com',
      name: 'Empresa ABC',
      rfc: 'EAB123456789'
    },
    billing_cycle: 'monthly',
    trial_days: 14,
    payment_method_id: 'pm_card_xxx',  // From saved card
    metadata: {
      org_id: 'org_123',
      app: 'cosmos-pet'
    }
  })
});

const { subscription_id, status, trial_end, next_billing_date } = await response.json();

Wallet Operations

typescript
// Check balance
const balanceRes = await fetch('https://colectiva.redbroomsoftware.com/api/wallet/balance', {
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'X-Ecosystem-Org-ID': 'eco_123'
  }
});
const { balance, currency, pending } = await balanceRes.json();

// Add credits (after receiving payment)
const creditRes = await fetch('https://colectiva.redbroomsoftware.com/api/wallet/credit', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    org_id: 'eco_123',
    amount: 1000,  // MXC credits
    reference: 'payment_xyz',
    description: 'Credit top-up'
  })
});

// Debit for service usage
const debitRes = await fetch('https://colectiva.redbroomsoftware.com/api/wallet/debit', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    org_id: 'eco_123',
    amount: 50,
    service: 'ai_classification',
    reference: 'txn_abc123',
    description: 'AI expense classification (10 items)'
  })
});

AI Service Billing

typescript
// Record AI usage
const response = await fetch('https://colectiva.redbroomsoftware.com/api/ai/usage', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    org_id: 'eco_123',
    service: 'expense_classification',
    units: 25,  // Number of classifications
    model: 'gemini-1.5-flash',
    tokens_used: 15000,
    metadata: {
      batch_id: 'batch_xyz'
    }
  })
});

// Check quota
const quotaRes = await fetch('https://colectiva.redbroomsoftware.com/api/ai/quota?org_id=eco_123', {
  headers: { 'Authorization': `Bearer ${API_KEY}` }
});
const { used, limit, remaining, resets_at } = await quotaRes.json();

Webhooks Sent

Colectiva sends webhooks for payment and subscription events:

EventTrigger
payment.createdPayment initiated
payment.completedPayment successful
payment.failedPayment failed
payment.refundedRefund processed
subscription.createdNew subscription
subscription.activatedTrial ended, billing started
subscription.renewedSuccessful renewal
subscription.payment_failedRenewal payment failed
subscription.cancelledSubscription cancelled
wallet.creditedCredits added
wallet.debitedCredits deducted
wallet.low_balanceBalance below threshold

Webhook Payload Example

json
{
  "event": "payment.completed",
  "timestamp": "2026-01-26T12:00:00Z",
  "data": {
    "payment_id": "pay_abc123",
    "amount": 1500.00,
    "currency": "MXN",
    "method": "card",
    "customer_email": "cliente@example.com",
    "metadata": {
      "subscription_id": "sub_123"
    }
  },
  "signature": "sha256=abc123..."
}

Verify Webhook Signature

typescript
import crypto from 'crypto';

function verifyWebhook(payload: string, signature: string, secret: string): boolean {
  const expected = crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex');

  return crypto.timingSafeEqual(
    Buffer.from(signature.replace('sha256=', '')),
    Buffer.from(expected)
  );
}

Error Responses

json
{
  "error": "insufficient_funds",
  "message": "Wallet balance insufficient for this operation",
  "details": {
    "required": 500,
    "available": 350
  }
}
Error CodeHTTP StatusDescription
invalid_request400Malformed request
authentication_failed401Invalid API key
permission_denied403Missing required permission
not_found404Resource doesn't exist
insufficient_funds402Wallet balance too low
payment_declined402Card/payment declined
rate_limited429Too many requests

Rate Limits

Endpoint TypeLimit
Payment creation100/min
Read operations300/min
Wallet operations60/min

Red Broom Software Ecosystem