@zanii/payments
v0.2.0
Published
Correct, verifiable money for Zanii payment receipts - integer minor units (bigint), per-currency precision, never a float. Builds the validated payload for recordPayment.
Readme
@zanii/payments
Correct, verifiable money for Zanii payment receipts. The SDK's
recordPayment takes a rail + reference + freeform details; this package supplies
the part that's easy to get wrong — integer minor units (bigint), per-currency
precision, and never a float. A payment proof then means the same thing to
everyone who reconciles it.
npm install @zanii/paymentsUsage
import { buildPayment } from '@zanii/payments';
import { ZaniiAgent } from '@zanii/sdk';
const agent = new ZaniiAgent({ /* … */ });
const p = buildPayment({
rail: 'stripe',
reference: 'ch_3PabcXYZ', // the rail's own settlement id — unprovable without it
amount: '49.99', // pass a STRING; a JS number can carry float error
currency: 'USD',
to: 'acct_merchant_42',
});
await agent.recordPayment({ rail: p.rail, reference: p.reference, details: p });
// p.money = { currency: 'USD', minor: '4999', display: '49.99 USD' }parseMoney('0.00000001', 'BTC') → 1 satoshi; parseMoney('1', 'ETH') →
1000000000000000000 (bigint, exact). Over-precision, zero, negative, and
non-decimal inputs are rejected. Unknown currencies throw until you
registerCurrency(code, decimals).
Changelog
- 0.1.0 — initial release:
parseMoney,formatMoney,buildPayment,verifyPayment,registerCurrency.
License
Apache-2.0.
