npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@olympio/payment-gateway

v0.2.0

Published

Camada de infraestrutura para gateways de pagamento (Asaas, Stripe, DOM) com contrato comum, capabilities, webhooks e erros normalizados.

Readme

@org/payment-gateway

Camada de infraestrutura para gateways de pagamento (Asaas, Stripe e DOM Pagamentos), com contrato comum, capabilities declaradas, escape hatch tipado, webhooks e erros normalizados.

A lib não contém regra de negócio — ela só fala com o gateway e normaliza dados/eventos/erros. A orquestração e as regras de cada cliente ficam na sua aplicação. Em termos hexagonais: a lib é a porta + os adapters de saída; o core de aplicação é seu.

Instalação

npm install @org/payment-gateway

Uso

import { createGateway, Capability, Money } from '@org/payment-gateway';

const gateway = createGateway({ provider: 'dom', apiKey: process.env.DOM_KEY! });
// ou: createGateway({ provider: 'asaas', apiKey: process.env.ASAAS_KEY! });
// ou: createGateway({ provider: 'stripe', apiKey: process.env.STRIPE_KEY! });

const customer = await gateway.customers.create({
  name: 'Maria Silva',
  email: '[email protected]',
  taxId: '12345678900', // CPF/CNPJ
});

const charge = await gateway.charges.create({
  amount: Money.fromDecimal(199.9, 'BRL'),
  paymentMethod: 'pix',
  customerId: customer.id,
  idempotencyKey: 'pedido-42',
});

console.log(charge.status, charge.amount.cents); // 'pending' 19990

Money é sempre em unidades mínimas (centavos). Use Money.fromDecimal / Money.fromCents e toDecimal() — os adapters cuidam da conversão automática para o formato esperado por cada API (ex: DOM e Asaas em Reais, Stripe em centavos).

Capabilities

Cada gateway declara o que suporta. Cheque antes de chamar; chamar algo não suportado lança UnsupportedCapabilityError.

if (gateway.supports(Capability.PIX)) {
  // ...
}

| Capability | Asaas | Stripe | DOM | | --------------- | :---: | :----: | :-: | | CARD | ✅ | ✅ | ✅ | | PIX | ✅ | ❌ | ✅ | | BOLETO | ✅ | ❌ | ✅ | | REFUND | ✅ | ✅ | ✅ | | SUBSCRIPTIONS | ✅ | ✅ | ❌ |

Escape hatch

Para recursos exclusivos que o contrato comum não cobre, raw() devolve o client nativo, tipado por adapter.

import { StripeGateway } from '@org/payment-gateway';

const stripe = new StripeGateway({ apiKey: process.env.STRIPE_KEY! });
const balance = await stripe.raw().balance.retrieve(); // client `Stripe` nativo

Webhooks

verifyAndParse verifica a assinatura e devolve um WebhookEvent normalizado.

const event = gateway.webhooks.verifyAndParse({
  payload: rawRequestBody,
  headers: req.headers,
  secret: process.env.WEBHOOK_SECRET!,
});

switch (event.type) {
  case 'charge.paid':
    // event.data é um Charge normalizado
    break;
}

Configuração por gateway

// DOM Pagamentos
createGateway({ 
  provider: 'dom', 
  apiKey, 
  baseUrl, // Opcional: use URL de homologação em dev
  webhookToken 
});

// Stripe
createGateway({ provider: 'stripe', apiKey, webhookSecret });

// Asaas
createGateway({ provider: 'asaas', apiKey, baseUrl, webhookToken });

Desenvolvimento

npm test        # roda todos os testes unitários e de contrato
npm run build   # gera os bundles ESM e CJS