SDKs

Official libraries for Node.js and TypeScript, Python and Go. Generated from the same contract as this documentation.

The SDKs do for you what every integration must get right:

  • They pick the environment from your key: psp_test_… goes to sandbox, psp_live_… to live.
  • They retry without duplicating: on a network failure, a 429, a 500 or a 503, they retry with the same Idempotency-Key. If you pass none, they generate one per call.
  • They honor Retry-After when the API asks to wait.
  • Typed errors, with type, code, param and request_id.
  • Auto-pagination: walk a whole list with a for loop.
  • Webhook verification: signature, timestamp and event parsing in one function.
  • Complete types for every resource, generated from the OpenAPI contract. Every endpoint of the reference shows its example in all three languages.

Install

npm install caibopay

Node.js 18 or later. No dependencies. ESM and CommonJS, with TypeScript types included.

Your first call

import { Caibo } from "caibopay";

const caibo = new Caibo(process.env.CAIBO_API_KEY!);

const account = await caibo.account.retrieve();
console.log(account.environment); // "sandbox"

Collect an exact amount

const fa = await caibo.fundingAccounts.create(
  { method: "pix", currency: "BRL", amount: "250.00", payer: { "payer.name": "Ana Souza" } },
  { idempotencyKey: "payin-order-8812" },
);

Pay out

const quote = await caibo.quotes.create(
  { source_currency: "USDT", destination_currency: "PEN", method: "bank_transfer", amount: "350.00", amount_side: "destination" },
  { idempotencyKey: "quote-order-5531" },
);
const payout = await caibo.payouts.create(
  { beneficiary_id: "ben_01m3sgazybenxvqfw0h5bnszk4", quote_id: quote.id },
  { idempotencyKey: "payout-order-5531" },
);

Walk a list

for await (const payout of caibo.payouts.list({ status: "completed" })) {
  console.log(payout.id, payout.destination.amount);
}

Errors

import { CaiboError } from "caibopay";

try {
  await caibo.payouts.create({ beneficiary_id: "ben_...", quote_id: "quo_..." });
} catch (err) {
  if (err instanceof CaiboError && err.code === "quote_expired") {
    // get a new quote
  }
  throw err;
}

Webhooks

import express from "express";
import { constructEvent } from "caibopay";

app.post("/webhooks/caibo", express.raw({ type: "application/json" }), (req, res) => {
  try {
    const event = constructEvent(req.body, req.get("Psp-Signature"), process.env.CAIBO_WEBHOOK_SECRET!);
    queue.push(event); // process later; dedupe on event.id
    res.sendStatus(200);
  } catch {
    res.sendStatus(400);
  }
});

Options

Node.jsPythonGo
Retries (2 by default){ maxRetries }max_retries=WithMaxRetries(n)
Timeout per attempt (30 s){ timeout }timeout=WithHTTPClient(...)
Another host{ baseUrl }base_url=WithBaseURL(u)
Your Idempotency-Key{ idempotencyKey }idempotency_key=WithIdempotencyKey(k)
Your trace id{ correlationId }request_options={"correlation_id": …}WithCorrelationID(id)

Another language?

Any language can use the API over HTTP and JSON, or generate its own client from /openapi.json. Write to us if you need an official SDK for another language.

Sur cette page