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

@companyio/payments

v0.3.1

Published

Universal settlement payments for multi-tenant CompanyIO products

Readme

@companyio/payments

Universal payment infrastructure for CompanyIO products (Fuel, POS, School, ERP).

Payments owns generic payment transactions, allocations, refunds, and idempotent settlement posting.

Payments does not own:

  • invoice / bill / expense balances (Sales, Purchasing, Expenses)
  • customers or suppliers (@companyio/contacts)
  • the chart of accounts or journals (@companyio/accounting)
  • Fuel day closing, cash drawers, or meter cash reconciliation (@companyio/fuel)
  • CompanyIO SaaS subscription billing (plans, entitlements, JazzCash/Easypaisa collection for the product itself) — that is a separate planned package; see ADR-PLAT-001

Business fact vs infrastructure

SalesPayment / PurchasingPayment / ExpensesPayment
        = domain business fact (what was settled on a document)

PaymentsPayment
        = generic payment transaction (how money moved)

Do not merge these. Connect them with IDs:

Payments.createPayment(...)
        ↓
Sales.applyExternalSettlement({ externalPaymentId, amount })
Purchasing.applyExternalSettlement(...)
Expenses.applyExternalSettlement(...)

Domain packages still keep their own pay() that writes a local payment row and may post via their Accounting adapter. That path remains valid for simple in-domain collection.

Install

The host owns PostgreSQL, Prisma Client, and migrations.

pnpm exec payments init --schema apps/api/prisma/schema.prisma
pnpm exec payments status
pnpm --filter @companyio/api exec prisma migrate deploy --config prisma7.config.ts

payments init copies prisma/migrations/0001_payments_baseline when missing (20260926000500_payments_baseline). Idempotency is unique per (main_business_id, branch_id, idempotencyKey).

Fastify

attachPayments(app, {
  store: createPrismaPaymentsStore(prisma),
  prefix: '/api/v1/payments',
  books: createAccountingPaymentsAdapter(accounting),
  contacts: createContactsPaymentsAdapter(contacts),
  authenticate,
  getContext,
});

Tenant ids come from the session. Creation is immediately POSTED (or returned unchanged on idempotent retry). Cancel and refund do not rewrite the original amount.

Frontend adapter

The browser UI ships from two subpaths — never import the package root in a bundle:

  • @companyio/payments/client — HTTP client + contracts (createPaymentsApi, PAYMENT_METHOD_OPTIONS).
  • @companyio/payments/react — PaymentsProvider, hooks, Platform-UI screens (PaymentsListPage, AddPaymentModal, PaymentDetail, PaymentStatusBadge), and paymentsQueryKeys.

A host wires its authed requester into the package contract and renders the shared pages:

// 1. createApi — map the host's authed requester into the package contract
const api = createPaymentsApi({
  request: async (path, init) => myAuthedJson(path, init), // throws PaymentsApiError on failure
  basePath: '/payments',
});

// 2. Provider — api + presentation config
<PaymentsProvider
  api={api}
  config={{
    currencyDisplay: 'PKR',
    defaultDirection: 'IN',
    canEditPayments, // host RBAC gate for create/cancel/refund
    // methodOptions — optional override of PAYMENT_METHOD_OPTIONS
  }}
>
  <PaymentsListPage
    documentTitle="Payments"
    listFilter={{
      sourceModule: 'fuel',
      sourceType: 'customer-payment',
      status: 'POSTED',
      direction: 'IN',
    }}
    createDefaults={{ sourceModule: 'fuel', sourceType: 'customer-payment', sourceId: stationId }}
    partyOptions={partyOptions}
  />
</PaymentsProvider>;

Direction is applied client-side (the list API has no direction param). Mutations invalidate paymentsQueryKeys.all; dual-invalidate the host's own caches (e.g. ['accounts']) after create/cancel.

Canonical UI labels (shared screens): Add payment, Cancel payment, Refund payment, Allocate payment. Direction options use Received (in) / Paid (out); method labels come from PAYMENT_METHOD_OPTIONS (e.g. Online transfer, Bank deposit). Destructive cancel uses ConfirmDialog from @companyio/platform-ui.

Reference adapters: Fuel Management (products/fuel-management/frontend/src/features/payments) and ContractFlow (products/contractflow/frontend/src/features/finance).

API Routes

Mounted at /api/v1/payments. Full detail: docs/API_ROUTE_INVENTORY.md.

| Method | Route | Auth | Purpose | | -------- | ------------------------- | ------- | ----------- | | GET | /payments/health | Public | Health | | GET/POST | /payments | Session | List/create | | GET | /payments/:id | Session | Get | | POST | /payments/:id/cancel | Session | Cancel | | GET/POST | /payments/:id/allocations | Session | Allocations | | POST | /payments/:id/refunds | Session | Refund |

Known gaps

  • Not a SaaS billing / entitlements package — keep separate from future pricing/billing work.
  • Domain document balances stay in Sales/Purchasing/Expenses; Payments is settlement infrastructure only.
  • Multi-currency FX and payment-provider adapters are deferred.

Build / test

pnpm --filter @companyio/payments test
pnpm --filter @companyio/payments build

Package tests cover CLI init, integration flows, external settlement, receivables mapping, and HTTP routes with session-scoped tenant isolation (in-memory store).