Skip to content

TypeScript SDK

@feitpay/sdk is a zero-dependency client built on fetch, with types generated from the OpenAPI contract. It runs on Node.js 20+, Deno, Bun and edge runtimes.

Terminal window
pnpm add @feitpay/sdk
import { FeitPay, FeitPayError } from '@feitpay/sdk';
const gp = new FeitPay({
apiKey: process.env.FEITPAY_API_KEY!, // gp_live_…
baseUrl: 'https://api.feitpay.com',
timeoutMs: 30_000, // per attempt
maxRetries: 2, // GET and idempotent POST only
});
Namespace Methods
paymentIntents create, retrieve, list, cancel, resolve, timeline
checkoutSessions create, retrieve
invoices create, retrieve, list, void
paymentLinks create, retrieve, list, update
transactions list, retrieve
wallets create, retrieve, list, disable, createOwnershipChallenge, submitOwnershipProof
stores, organizations, customers list / retrieve
webhookEndpoints create, list, retrieve, update, rotateSecret, sendTest
webhookDeliveries list, retrieve, retry
events list, retrieve
reports payments (CSV string or JSON), reconciliation
billing invoices, usage
auditEvents list
pix pricing
platform capabilities, networks, assets, health
  • Idempotency — create methods send an Idempotency-Key automatically (gp_sdk_…) and reuse it across retries. Pass { idempotencyKey } to tie it to your own order id.
  • Retries — exponential backoff with full jitter (honouring Retry-After) on network errors, 429 and 5xx, for GET and keyed POST only.
  • Pagination — await gp.invoices.list() returns a page; for await (const inv of gp.invoices.list()) walks all pages; .toArray(max) collects a bounded number.
  • Errors — every failure is a FeitPayError subclass with type, code, param, requestId and status.
  • Money — amounts are strings. formatBaseUnits('99834', 8) === '0.00099834' uses BigInt, never floats.
  • Path safety — ids are encoded as a single path segment.
try {
const intent = await gp.paymentIntents.retrieve('pi_…');
if (intent.fulfillable) ship(intent.merchant_order_id);
} catch (err) {
if (err instanceof FeitPayError && err.type === 'not_found_error') return null;
throw err;
}

Set allowed_methods on a payment in BRL: ['pix'] makes a PIX-only payment, and ['crypto', 'pix'] lets the customer choose at checkout. Payment intents, invoices and payment links take the same field (typed as 'crypto' or 'pix'); leave it out for crypto only.

// A PIX-only payment.
const pixOnly = await gp.paymentIntents.create(
{ store_id: 'store_YOUR_STORE_ID', amount: '59.90', currency: 'BRL', allowed_methods: ['pix'] },
{ idempotencyKey: 'order-1042' },
);
// The customer chooses crypto or PIX at checkout.
const either = await gp.paymentIntents.create(
{ store_id: 'store_YOUR_STORE_ID', amount: '59.90', currency: 'BRL', allowed_methods: ['crypto', 'pix'] },
{ idempotencyKey: 'order-1043' },
);

Read fees, minimums and availability from the API instead of hard-coding them. gp.pix.pricing() calls GET /v1/pix/pricing (API keys need the balances:read scope):

const pricing = await gp.pix.pricing();
if (!pricing.available) {
// PIX is switched off: create crypto-only payments.
}

pricing.tiers (in order; the first tier whose bound holds applies), minimum_fee, minimum_payment and payout_fee are BRL decimal strings, typed as PixPricing and PixPricingTier. Once the PIX charge is open, processor.methods[].pix_copy_paste on the payment intent is its copia e cola code; once the payment is credited, processor.fee is the PIX fee that was deducted. PIX keys appear in gp.payouts.destinations() with asset: 'brl' and a pix object. Checkout, statuses, fees and error codes: PIX (Brazil).