@amboras-dev/money 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -10
- package/dist/ai.cjs +12 -13
- package/dist/ai.d.cts +5 -9
- package/dist/ai.d.ts +5 -9
- package/dist/ai.js +12 -13
- package/dist/{allocate-D7tm_t_o.cjs → allocate-AusholrC.cjs} +3 -4
- package/dist/{allocate-CdnhvAda.js → allocate-BBRfdaSC.js} +3 -4
- package/dist/{amount-DHtvZSSm.cjs → amount-CwFzcxUl.cjs} +29 -12
- package/dist/{amount-D7dj76nH.js → amount-DHFOK2Yd.js} +29 -12
- package/dist/{arithmetic-C-Q_aI49.js → arithmetic-C97-YafD.js} +4 -5
- package/dist/{arithmetic-Bq-8mSal.cjs → arithmetic-D8A6IeZ0.cjs} +4 -5
- package/dist/billing.cjs +5 -8
- package/dist/billing.d.cts +1 -9
- package/dist/billing.d.ts +1 -9
- package/dist/billing.js +5 -8
- package/dist/commerce.cjs +15 -23
- package/dist/commerce.d.cts +2 -16
- package/dist/commerce.d.ts +2 -16
- package/dist/commerce.js +15 -23
- package/dist/{format-BnA1aLJk.cjs → format-92fzvTXY.cjs} +21 -6
- package/dist/{format-BdB7LEIp.js → format-BJC513u4.js} +16 -7
- package/dist/fx.cjs +12 -18
- package/dist/fx.d.cts +5 -15
- package/dist/fx.d.ts +5 -15
- package/dist/fx.js +12 -18
- package/dist/index.cjs +13 -12
- package/dist/index.d.cts +28 -22
- package/dist/index.d.ts +28 -22
- package/dist/index.js +11 -13
- package/dist/input.cjs +7 -10
- package/dist/input.d.cts +9 -16
- package/dist/input.d.ts +9 -16
- package/dist/input.js +7 -10
- package/dist/{iso-minor--gQWI1f2.cjs → iso-minor-DyNjT9A1.cjs} +2 -3
- package/dist/{iso-minor-CtaiIifs.js → iso-minor-odkY-e6I.js} +2 -3
- package/dist/{medusa-OJ2TJOxt.cjs → medusa-CzVK0bth.cjs} +24 -4
- package/dist/{medusa-DuQ3-KoD.d.cts → medusa-DofdvIgQ.d.cts} +11 -4
- package/dist/{medusa-RwqxaDGq.d.ts → medusa-DrbYmD2Y.d.ts} +11 -4
- package/dist/{medusa-CmxCni-G.js → medusa-pKGlImn9.js} +19 -5
- package/dist/{money-CbhsT0fB.d.cts → money-BkMeYDEW.d.cts} +19 -9
- package/dist/{money-CbhsT0fB.d.ts → money-BkMeYDEW.d.ts} +19 -9
- package/dist/{money-CIgELekG.js → money-BxbAw7BP.js} +25 -21
- package/dist/{money-D5-vlv0h.cjs → money-DWBjuuEK.cjs} +42 -20
- package/dist/{number-text-C82oh6JB.js → number-text-Bj-gZXiF.js} +3 -4
- package/dist/{number-text-BpvN6NAo.cjs → number-text-CWuVwrlg.cjs} +3 -4
- package/dist/{own-oP9DXFWv.cjs → own-C5imDkyB.cjs} +1 -2
- package/dist/{own-D7544D3k.js → own-DHxqIYqL.js} +1 -2
- package/dist/{percent-CKVI_c-m.js → percent-CB3Ixjc_.js} +2 -3
- package/dist/{percent-Dt8vNIAW.cjs → percent-DABHiSBs.cjs} +2 -3
- package/dist/{rate-CmeTGNex.d.ts → rate-BvvZUdSu.d.ts} +1 -3
- package/dist/{rate-toyS3EMf.d.cts → rate-CEakW3ia.d.cts} +1 -3
- package/dist/{rate-DGPfB_jc.cjs → rate-CEjWTATc.cjs} +3 -4
- package/dist/{rate-lLPViBuM.js → rate-D6S2_wgZ.js} +3 -4
- package/dist/{reporting-5xby-Zas.d.ts → reporting-DFNyDBdi.d.cts} +2 -4
- package/dist/{reporting-DEM97DhQ.d.cts → reporting-jIBILvnr.d.ts} +2 -4
- package/dist/{retail-BwcFJcVN.d.ts → retail-B04CjW3b.d.ts} +1 -3
- package/dist/{retail-DTk2XAMM.cjs → retail-CYGPU4ea.cjs} +4 -5
- package/dist/{retail-Mqd-sPMF.d.cts → retail-CmEyJQOH.d.cts} +1 -3
- package/dist/{retail-BsvpNv1F.js → retail-DXgs11ov.js} +4 -5
- package/dist/{rounding-oZ832yTD.cjs → rounding-4QKTRbMQ.cjs} +2 -3
- package/dist/{rounding-CVAPEfq_.js → rounding-CA1PVP3b.js} +2 -3
- package/dist/sql.cjs +9 -15
- package/dist/sql.d.cts +2 -12
- package/dist/sql.d.ts +2 -12
- package/dist/sql.js +9 -15
- package/dist/testing.cjs +72675 -12
- package/dist/testing.d.cts +46 -11
- package/dist/testing.d.ts +46 -11
- package/dist/testing.js +72674 -13
- package/dist/{wire-CI3Sm1iC.js → wire-B4QU8O3W.js} +584 -114
- package/dist/wire-CVNicirK.d.ts +428 -0
- package/dist/wire-CtNJmWVP.d.cts +428 -0
- package/dist/{wire-DQZ6fA3c.cjs → wire-u2tmHY0Y.cjs} +649 -113
- package/dist/wire.cjs +12 -1
- package/dist/wire.d.cts +2 -2
- package/dist/wire.d.ts +2 -2
- package/dist/wire.js +1 -2
- package/package.json +4 -3
- package/dist/wire-Cd4Q1Jmm.d.ts +0 -269
- package/dist/wire-hWuixv3w.d.cts +0 -269
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { b as FractionDigits, g as CurrencyCode, i as Money, o as StoredAmount, t as FractionalMoney, z as RoundingMode } from "./money-BkMeYDEW.cjs";
|
|
2
|
+
/** paystack.com/docs/api/#supported-currency (retrieved 2026-10-07): every currency a Paystack account can charge. */
|
|
3
|
+
declare const PAYSTACK_CURRENCIES: readonly ["GHS", "KES", "NGN", "USD", "XOF", "ZAR"];
|
|
4
|
+
declare const IYZICO_CURRENCIES: readonly ["TRY", "USD", "EUR", "GBP", "NOK", "CHF"];
|
|
5
|
+
/** developer.authorize.net createTransactionRequest `currencyCode`, retrieved 2026-10-07. */
|
|
6
|
+
declare const AUTHORIZE_NET_CURRENCIES: readonly ["USD", "CAD", "GBP", "EUR", "AUD", "NZD", "DKK", "NOK", "SEK", "PLN"];
|
|
7
|
+
/**
|
|
8
|
+
* The first `"<field>": <decimal>` (quoted or not) in a raw JSON body, verbatim: `JSON.parse`
|
|
9
|
+
* would turn the gateway's `43.00` into `43`. The value is the whole JSON token, held to
|
|
10
|
+
* `parseDecimal`'s `'plain'` grammar (`1e3` or `"43.10abc"` is not a decimal literal).
|
|
11
|
+
* Undefined when absent; there is no lossy fallback.
|
|
12
|
+
*/
|
|
13
|
+
declare function jsonDecimalLiteral(rawBody: string, field: string): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* What an unsettled Authorize.Net transaction can still be reversed for: the settle amount when
|
|
16
|
+
* present and above zero (exact), else `authAmount ?? settleAmount` (settle is `'0.00'`, not
|
|
17
|
+
* absent, for voided or unsettled transactions). Undefined when both are absent.
|
|
18
|
+
*/
|
|
19
|
+
interface AuthorizeNetAmounts {
|
|
20
|
+
settleAmount?: string | null;
|
|
21
|
+
authAmount?: string | null;
|
|
22
|
+
}
|
|
23
|
+
declare function authorizeNetReversibleAmount(details: AuthorizeNetAmounts): string | undefined;
|
|
24
|
+
type PspId = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo' | 'vnpay' | 'paypal' | 'mollie' | 'airwallex' | 'iyzico' | 'authorize-net' | 'payoo';
|
|
25
|
+
/** ISO minor units, marker-gated decode: a payment created before the cutover holds storage units at the PSP. */
|
|
26
|
+
type GatedPsp = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo';
|
|
27
|
+
/** Gated PSPs whose encode is gated too; MoMo and Paystack always encode ISO minor units. */
|
|
28
|
+
type EncodeGatedPsp = 'stripe' | 'adyen' | 'razorpay';
|
|
29
|
+
type IsoMinorPsp = GatedPsp | 'vnpay';
|
|
30
|
+
type MajorStringPsp = 'paypal' | 'mollie' | 'iyzico' | 'authorize-net';
|
|
31
|
+
type MajorNumberPsp = 'airwallex' | 'payoo';
|
|
32
|
+
/** What a PSP receives: major-unit text for PayPal, Mollie, iyzico and Authorize.Net, a number for the rest. */
|
|
33
|
+
type WireAmount<P extends PspId> = P extends MajorStringPsp ? string : number;
|
|
34
|
+
/** The currencies Authorize.Net settles (createTransactionRequest `currencyCode`). */
|
|
35
|
+
type AuthorizeNetCurrency = (typeof AUTHORIZE_NET_CURRENCIES)[number];
|
|
36
|
+
type IyzicoCurrency = (typeof IYZICO_CURRENCIES)[number];
|
|
37
|
+
type PaystackCurrency = (typeof PAYSTACK_CURRENCIES)[number];
|
|
38
|
+
type VndOnlyPsp = 'momo' | 'vnpay' | 'payoo';
|
|
39
|
+
/**
|
|
40
|
+
* A currency `P` takes, as a type: the literal union for the PSPs with a short fixed list
|
|
41
|
+
* (Authorize.Net, iyzico, Paystack, the VND rails), else any `CurrencyCode`. Always a
|
|
42
|
+
* `CurrencyCode` too, so it can be passed wherever one is wanted.
|
|
43
|
+
*/
|
|
44
|
+
type PspCurrency<P extends PspId> = CurrencyCode & (P extends 'authorize-net' ? AuthorizeNetCurrency : P extends 'iyzico' ? IyzicoCurrency : P extends 'paystack' ? PaystackCurrency : P extends VndOnlyPsp ? 'VND' : string);
|
|
45
|
+
/** Every PSP id, in a stable order. */
|
|
46
|
+
declare const PSP_IDS: readonly PspId[];
|
|
47
|
+
declare const WIRE_SCALE_KEY = "amboras_wire_scale";
|
|
48
|
+
declare const WIRE_SCALE_ISO_MINOR_V2 = "iso-minor-v2";
|
|
49
|
+
declare const WIRE_SCALE_MARKER: Readonly<{
|
|
50
|
+
amboras_wire_scale: 'iso-minor-v2';
|
|
51
|
+
}>;
|
|
52
|
+
/** Which convention a payment was created under. Use the two singletons; build one with `conventionOf`. */
|
|
53
|
+
type Convention = {
|
|
54
|
+
readonly kind: 'iso-minor-v2';
|
|
55
|
+
} | {
|
|
56
|
+
readonly kind: 'pre-cutover';
|
|
57
|
+
};
|
|
58
|
+
declare const ISO_MINOR_V2: Convention;
|
|
59
|
+
declare const PRE_CUTOVER: Convention;
|
|
60
|
+
/**
|
|
61
|
+
* `ISO_MINOR_V2` iff ANY record is a non-null object whose `amboras_wire_scale` is strictly
|
|
62
|
+
* `'iso-minor-v2'` (a Stripe charge OR its PaymentIntent); else `PRE_CUTOVER`. Reads already
|
|
63
|
+
* fetched records only: it never queries (FORCE RLS would hide the row and the marker with it).
|
|
64
|
+
*/
|
|
65
|
+
declare function conventionOf(...records: unknown[]): Convention;
|
|
66
|
+
declare const WIRE_ROUNDING_KEY = "amboras_wire_rounding";
|
|
67
|
+
declare const WIRE_ROUNDING_EXACT = "exact";
|
|
68
|
+
declare const WIRE_ROUNDING_MARKER: Readonly<{
|
|
69
|
+
amboras_wire_rounding: 'exact';
|
|
70
|
+
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Whether a payment may be held at the PSP in Medusa's pre-0.2.0 float spelling: no record is a
|
|
73
|
+
* non-null object whose `amboras_wire_rounding` is strictly `'exact'`. Pass the result as
|
|
74
|
+
* `sameWireAmount`'s `acceptLegacyFloatRounding`, so only sessions created before the deploy get
|
|
75
|
+
* the legacy spelling. Reads already fetched records only.
|
|
76
|
+
*/
|
|
77
|
+
declare function mayHoldLegacyFloatRounding(...records: unknown[]): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* `total` and its `parts` (same currency, non-negative, adding up to `total`) as integer wire
|
|
80
|
+
* amounts whose sum is exactly `encodeWire(psp, total)`: the wire total split by largest
|
|
81
|
+
* remainder over the stored parts. Throws `currency_mismatch`, `amount_invalid` (parts that do not
|
|
82
|
+
* add up, or a negative part) or whatever `encodeWire` refuses.
|
|
83
|
+
*/
|
|
84
|
+
declare function wireBreakdown(psp: IsoMinorPsp, total: Money, parts: Readonly<Record<string, Money>>, convention: Convention): {
|
|
85
|
+
total: number;
|
|
86
|
+
parts: Record<string, number>;
|
|
87
|
+
};
|
|
88
|
+
/** Whether `psp` takes `currency` (any case, historic codes included). Never throws for a bad code. */
|
|
89
|
+
declare function pspSupportsCurrency(psp: PspId, currency: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Every currency `psp` takes. Provider-only codes a PSP table lists (Adyen offshore CNH) are left
|
|
92
|
+
* out: they are not ISO 4217 currencies, no store sells in them and no Money can carry them.
|
|
93
|
+
*/
|
|
94
|
+
declare function pspCurrencies(psp: PspId): ReadonlySet<CurrencyCode>;
|
|
95
|
+
/**
|
|
96
|
+
* `currency` as a CurrencyCode `psp` takes. Empty throws `currency_missing` (`[<Tag>] Cannot
|
|
97
|
+
* scale an amount without a currency code; ...`); anything the PSP does not take throws
|
|
98
|
+
* `wire_unsupported` with the provider's own message. Typed as the PSP's literal union where it
|
|
99
|
+
* has a short fixed list (`assertPspCurrency('authorize-net', c)` is an `AuthorizeNetCurrency`).
|
|
100
|
+
*/
|
|
101
|
+
declare function assertPspCurrency<P extends PspId>(psp: P, currency: unknown): PspCurrency<P>;
|
|
102
|
+
/** `'VND'` for the single-currency providers (MoMo, Payoo, VNPay), else null. */
|
|
103
|
+
declare function pspDefaultCurrency(psp: PspId): CurrencyCode | null;
|
|
104
|
+
/**
|
|
105
|
+
* The currency every account of `psp` charges without enabling anything (any other needs the
|
|
106
|
+
* account's international or multi-currency add-on, or is never taken): Razorpay INR, iyzico TRY,
|
|
107
|
+
* and for the single-currency PSPs their one currency (MoMo, VNPay and Payoo VND). Null for PSPs
|
|
108
|
+
* whose accounts have no single home currency (Stripe, Adyen, PayPal, Mollie, Airwallex, Authorize.Net, and Paystack, whose home currency is the
|
|
109
|
+
* account country's: `pspPresentment('paystack').accountCountries`). Unlike `pspDefaultCurrency`,
|
|
110
|
+
* which is non-null only for the single-currency PSPs, a home currency does not mean the PSP takes
|
|
111
|
+
* nothing else.
|
|
112
|
+
*/
|
|
113
|
+
declare function pspHomeCurrency(psp: PspId): CurrencyCode | null;
|
|
114
|
+
/**
|
|
115
|
+
* The one country (ISO 3166 alpha-2) every account of `psp` is registered in, for PSPs whose
|
|
116
|
+
* accounts are all registered in a single country: iyzico `'TR'`, MoMo, VNPay and Payoo `'VN'`. Null
|
|
117
|
+
* for PSPs available in several countries: Razorpay (India, Malaysia, Singapore, the United States)
|
|
118
|
+
* and Paystack (its country follows the account: `pspAccountCountryForCurrency`).
|
|
119
|
+
*/
|
|
120
|
+
declare function pspHomeCountry(psp: PspId): string | null;
|
|
121
|
+
/**
|
|
122
|
+
* Stored units per wire unit for an ISO-minor PSP: the PSP's override (Stripe ISK/UGX, Adyen
|
|
123
|
+
* ISK/CLP, Razorpay MGA, Paystack XOF, VNPay VND give 1; Adyen IDR/CVE give 100), else
|
|
124
|
+
* `storageScale / 10^storageDigits` (100 for a zero-decimal currency, else 1).
|
|
125
|
+
*/
|
|
126
|
+
declare function wireFactor(psp: IsoMinorPsp, currency: string): 1 | 100;
|
|
127
|
+
/**
|
|
128
|
+
* Fraction digits of `psp`'s wire amount: its digit table, else (ISO-minor PSPs) the digits
|
|
129
|
+
* its factor implies, else (iyzico, Authorize.Net, Payoo) the display digits. Null when the
|
|
130
|
+
* PSP does not take the currency.
|
|
131
|
+
*/
|
|
132
|
+
declare function pspWireDigits(psp: PspId, currency: string): FractionDigits | null;
|
|
133
|
+
/** The PSP's minimum charge in `currency` (Paystack USD 2.00), or null when it has none. */
|
|
134
|
+
declare function pspMinimumAmount(psp: PspId, currency: string): Money | null;
|
|
135
|
+
interface EncodeWireOptions {
|
|
136
|
+
/** Names the amount in refusals: `[<Tag>] Invalid <label>: <amount>`. Default `'amount'`; refunds pass `'refund amount'`. */
|
|
137
|
+
label?: string;
|
|
138
|
+
/** Allow a zero amount (verification, comparisons). Negative amounts are always refused. */
|
|
139
|
+
allowZero?: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A stored amount as `psp` receives it. `m` is a Money or a FractionalMoney (Medusa's unrounded
|
|
143
|
+
* session totals, 107.8175). In order: the currency must pass the PSP's Medusa amount facade
|
|
144
|
+
* (`wire_unsupported` with the facade's message: Razorpay only its exponent table, Paystack no
|
|
145
|
+
* zero-decimal code but XOF, MoMo, Payoo and VNPay only VND; every other PSP scales any currency,
|
|
146
|
+
* so call `assertPspCurrency` for eligibility); the amount must be positive (`wire_refused`
|
|
147
|
+
* `[<Tag>] Invalid <label>: <amount>`, zero allowed with `allowZero`); Stripe and Adyen round a
|
|
148
|
+
* fractional amount half-up to a whole storage unit first; Stripe, Adyen and Razorpay on a
|
|
149
|
+
* pre-cutover payment send the stored integer as is (Razorpay refuses unless its factor is 1, and
|
|
150
|
+
* refuses a fractional amount, which has no stored integer; MoMo and Paystack encode ignore the
|
|
151
|
+
* convention, as today); the whole-unit rules refuse fractions of a dong (MoMo, Payoo, VNPay) or a
|
|
152
|
+
* franc (Paystack XOF), naming the amount as held; then, rounding once and exactly, ISO minor
|
|
153
|
+
* `half-up(S / wireFactor)` (Razorpay three-decimal floored to steps of 10), or major units at the
|
|
154
|
+
* PSP's wire digits, half-up, as fixed-point text (a number for Airwallex and Payoo). A positive
|
|
155
|
+
* amount whose wire rounds to zero is refused (`wire_refused`), with `allowZero` too.
|
|
156
|
+
* This is package policy, safer than Medusa today: Medusa puts 0 on the wire at initiate for
|
|
157
|
+
* Stripe and Adyen, and for Razorpay, PayPal and Airwallex everywhere; it refuses at refund and
|
|
158
|
+
* capture for Stripe and Adyen, and in Mollie, iyzico and Authorize.Net; Razorpay and Paystack
|
|
159
|
+
* read a zero refund as a full one. Otherwise byte-identical to Medusa's codecs for every Money.
|
|
160
|
+
*/
|
|
161
|
+
declare function encodeWire<P extends EncodeGatedPsp>(psp: P, m: Money | FractionalMoney, options: EncodeWireOptions & {
|
|
162
|
+
convention: Convention;
|
|
163
|
+
}): WireAmount<P>;
|
|
164
|
+
declare function encodeWire<P extends Exclude<PspId, EncodeGatedPsp>>(psp: P, m: Money | FractionalMoney, options?: EncodeWireOptions): WireAmount<P>;
|
|
165
|
+
interface DecodeWireOptions {
|
|
166
|
+
/** Required for gated PSPs (Stripe, Adyen, Razorpay, Paystack, MoMo); ignored by the rest. */
|
|
167
|
+
convention?: Convention;
|
|
168
|
+
/**
|
|
169
|
+
* Accept a negative wire amount (signed balance transactions, reversals). Default false, as in
|
|
170
|
+
* `tryDecodeWire`: a negative wire throws `amount_invalid` (`[<Tag>] Negative wire amount: <wire>`).
|
|
171
|
+
* Never for VNPay, whose amounts are positive whole numbers.
|
|
172
|
+
*/
|
|
173
|
+
allowNegative?: boolean;
|
|
174
|
+
}
|
|
175
|
+
/** `tryDecodeWire` takes the same options as `decodeWire`. */
|
|
176
|
+
type TryDecodeWireOptions = DecodeWireOptions;
|
|
177
|
+
/**
|
|
178
|
+
* A PSP wire amount as Money: ISO minor `half-up(w x wireFactor)` (pre-cutover: `half-up(w)`, the
|
|
179
|
+
* PSP already held storage units), major `half-up(w x storageScale)`. `wire` is a finite number
|
|
180
|
+
* or strict decimal text (`/^-?\d+(\.\d+)?$/`: no `''`, exponent or hex), else `amount_invalid`.
|
|
181
|
+
* Gated PSPs need `options.convention` (no hidden default: without it `wire_refused`).
|
|
182
|
+
* A negative wire throws `amount_invalid` unless `allowNegative: true` (checked on the exact wire
|
|
183
|
+
* value before rounding, so `-0.001` is refused too; `-0` is zero), and for VNPay anything but a
|
|
184
|
+
* positive whole number is no amount (`amount_invalid`).
|
|
185
|
+
* The options are one object: anything else as the fourth argument (a positional Convention, as in
|
|
186
|
+
* 0.2.0) or any fifth argument throws `wire_refused`, so no option is ever silently dropped.
|
|
187
|
+
* The currency is required (`currency_missing`), must be known (`currency_invalid`), must not be
|
|
188
|
+
* provider-only (Adyen CNH: `wire_unsupported`), and must pass the PSP's Medusa inbound gate
|
|
189
|
+
* (`wire_unsupported` with its message: Razorpay only its exponent table, Paystack no
|
|
190
|
+
* zero-decimal code but XOF, MoMo, Payoo and VNPay only VND). Other PSPs read any currency (a PSP
|
|
191
|
+
* may report a settlement currency).
|
|
192
|
+
*/
|
|
193
|
+
declare function decodeWire<P extends GatedPsp>(psp: P, wire: unknown, currency: string, options: DecodeWireOptions & {
|
|
194
|
+
convention: Convention;
|
|
195
|
+
}): Money;
|
|
196
|
+
declare function decodeWire<P extends Exclude<PspId, GatedPsp>>(psp: P, wire: unknown, currency: string, options?: DecodeWireOptions): Money;
|
|
197
|
+
/**
|
|
198
|
+
* `decodeWire` that never throws: undefined wherever it would throw (null, undefined, `''`,
|
|
199
|
+
* whitespace, unparseable or unsafe input, a missing, unknown or provider-only currency, one the
|
|
200
|
+
* PSP's inbound gate refuses, VNPay's "no amount", an unknown PSP, a gated PSP without
|
|
201
|
+
* `convention`: no hidden default) and for a negative amount unless `allowNegative`.
|
|
202
|
+
*/
|
|
203
|
+
declare function tryDecodeWire(psp: PspId, wire: unknown, currency: unknown, options?: TryDecodeWireOptions): Money | undefined;
|
|
204
|
+
interface SameWireAmountOptions {
|
|
205
|
+
/** Required for gated PSPs (Stripe, Adyen, Razorpay, Paystack, MoMo); without it the answer is false. */
|
|
206
|
+
convention?: Convention;
|
|
207
|
+
/**
|
|
208
|
+
* Also accept the ISO-digit spelling held by a session created before the PSP digit tables
|
|
209
|
+
* (PayPal, Mollie, Airwallex HUF/TWD...): the expected amount in major units at its display
|
|
210
|
+
* digits, half-up (HUF 44.50 went as `'45'`). Major-unit PSPs only.
|
|
211
|
+
*/
|
|
212
|
+
acceptLegacyIsoDigits?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Also accept the spelling Medusa's pre-0.2.0 float codec sent for a PSP that encoded in
|
|
215
|
+
* floating point (PayPal, Mollie, Airwallex, iyzico, Authorize.Net, Payoo): major units as
|
|
216
|
+
* `(stored / storageScale).toFixed(wireDigits)` on a double. It differs from today's only at an
|
|
217
|
+
* exact tie the double sits just below (USD 1072.5 went as `'10.72'`, 0.2.0 sends `'10.73'`),
|
|
218
|
+
* so a payment created before 0.2.0 still compares. With `acceptLegacyIsoDigits` the float
|
|
219
|
+
* spelling at the display digits is accepted too. Ignored for every other PSP.
|
|
220
|
+
*/
|
|
221
|
+
acceptLegacyFloatRounding?: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* The PSP only ever reports decimal text (Mollie, PayPal): a reported (or `requested`) value
|
|
224
|
+
* that is not a string is not its amount, whatever number it holds.
|
|
225
|
+
*/
|
|
226
|
+
textOnly?: boolean;
|
|
227
|
+
/** When given, it must be the same currency as `expected` (any case). */
|
|
228
|
+
reportedCurrency?: unknown;
|
|
229
|
+
/** Paystack fee pass-through: the amount the buyer was asked for. */
|
|
230
|
+
requested?: unknown;
|
|
231
|
+
/**
|
|
232
|
+
* `'exact'` (default), or `'requested-exact-collected-covers'`: `requested` is exactly the
|
|
233
|
+
* expected amount and the collected `reported` covers it.
|
|
234
|
+
*/
|
|
235
|
+
policy?: 'exact' | 'requested-exact-collected-covers';
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Whether a PSP-reported amount is `expected`, a Money or a FractionalMoney (Medusa's unrounded
|
|
239
|
+
* session total). The expected wire is `encodeWire(psp, expected, { convention, allowZero: true })`
|
|
240
|
+
* (a refusal means false); the reported one must decode exactly (strict like `tryDecodeWire`:
|
|
241
|
+
* never `''` or an exponent, no negatives, and never a fraction of a storage unit) to the same
|
|
242
|
+
* stored amount, so `'44.00'` matches a sent `'44'` and Airwallex `43.004` does not match `43`.
|
|
243
|
+
* Never throws.
|
|
244
|
+
*/
|
|
245
|
+
declare function sameWireAmount(psp: PspId, reported: unknown, expected: Money | FractionalMoney, options?: SameWireAmountOptions): boolean;
|
|
246
|
+
/**
|
|
247
|
+
* One unit of the PSP's last wire digit, as Money: for ISO-minor PSPs `decodeWire(psp, 1)` (the
|
|
248
|
+
* factor on an iso-minor-v2 payment, 1 storage unit on a pre-cutover one; gated PSPs need the
|
|
249
|
+
* convention), for major PSPs `10^-wireDigits` major. The tolerance for `excessOver`.
|
|
250
|
+
*/
|
|
251
|
+
declare function oneWireUnit(psp: PspId, currency: string, convention?: Convention): Money;
|
|
252
|
+
/** The wire amount as it goes into Redis skip keys and idempotency keys: `String(wire)`, byte for byte. */
|
|
253
|
+
declare function wireKeyPart(wire: number | string): string;
|
|
254
|
+
type DestinationId = 'meta' | 'ga4' | 'google-ads' | 'tiktok' | 'snapchat' | 'pinterest' | 'klaviyo' | 'omnisend' | 'omnisend-viewed-product' | 'mailchimp' | 'goaffpro' | 'profitmetrics' | 'pixi' | 'flow' | 'sendcloud' | 'shipstation' | 'shiprocket' | 'shipbob' | 'printful' | 'ahamove' | 'amazon-mcf' | 'skydropx' | 'royal-mail' | 'sevdesk' | 'shopify-ajax';
|
|
255
|
+
interface DestinationValue {
|
|
256
|
+
readonly value: number | string;
|
|
257
|
+
readonly currency: string;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* `m` as `dest` wants it: major units at the display digits (half-up) as a number or text per
|
|
261
|
+
* destination (`as` overrides), or integer "cents" for Shopify AJAX and Omnisend `viewed product`;
|
|
262
|
+
* the currency upper- or lower-case per destination. Undefined when the destination must not get
|
|
263
|
+
* this amount (Meta: not positive; GA4, Google Ads, TikTok, Snapchat, Pinterest and marketing:
|
|
264
|
+
* negative). Throws `wire_unsupported` for a currency the destination's unit is not defined for.
|
|
265
|
+
*/
|
|
266
|
+
declare function destinationAmount(dest: DestinationId, m: Money, options?: {
|
|
267
|
+
as?: 'number' | 'string';
|
|
268
|
+
}): DestinationValue | undefined;
|
|
269
|
+
/** A shopping-feed price: `'12.345 KWD'`, `'1200 JPY'`, `'19.99 USD'` (display digits, half-up). */
|
|
270
|
+
declare function feedPrice(m: Money): string;
|
|
271
|
+
/** Google micros (major x 10^6) as integer text, exactly: USD 1999 gives `'19990000'`. */
|
|
272
|
+
declare function googleMicros(m: Money): string;
|
|
273
|
+
interface EventMoney {
|
|
274
|
+
readonly value: number;
|
|
275
|
+
readonly currency: string;
|
|
276
|
+
}
|
|
277
|
+
/** First-party analytics money: the stored integer and the lower-case code (the ClickHouse `Int64` contract). */
|
|
278
|
+
declare function eventMoney(m: Money): EventMoney;
|
|
279
|
+
interface LegacyFloatRefundInput {
|
|
280
|
+
/** What Medusa records as captured on the payment. */
|
|
281
|
+
captured: Money | FractionalMoney;
|
|
282
|
+
/** What Medusa has refunded of that capture so far (a zero amount when nothing). */
|
|
283
|
+
refunded: Money | FractionalMoney;
|
|
284
|
+
/** The refund Medusa is about to send. */
|
|
285
|
+
refund: Money | FractionalMoney;
|
|
286
|
+
/** The capture as the PSP reports it, wire value as read (`'10.72'`). */
|
|
287
|
+
capturedWire: unknown;
|
|
288
|
+
/** What the PSP reports as already refunded of that capture, wire value as read (`'0.00'` or 0 when nothing). */
|
|
289
|
+
refundedWire: unknown;
|
|
290
|
+
}
|
|
291
|
+
interface LegacyFloatRefund {
|
|
292
|
+
/** What to send instead of `encodeWire(psp, refund)`. */
|
|
293
|
+
readonly wire: number | string;
|
|
294
|
+
/** The same amount as Money: what Medusa records on the refund row. */
|
|
295
|
+
readonly money: Money;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The PSP's remaining amount, to refund instead of `refund`, when the PSP holds the capture only
|
|
299
|
+
* in Medusa's pre-0.2.0 float spelling (`legacyFloatToFixed` PSPs: USD 1072.5 captured as
|
|
300
|
+
* `'10.72'`, where today's spelling is `'10.73'`) and `refund` is Medusa's whole remaining amount
|
|
301
|
+
* (`captured - refunded`, exactly). Medusa's remaining then encodes one wire unit above what the
|
|
302
|
+
* PSP still holds (after a `'0.72'` refund, Medusa's 1000.5 is `'10.01'` against the PSP's
|
|
303
|
+
* `'10.00'`), and the PSP refuses it (NOT_ALLOWED), so the refund could never complete.
|
|
304
|
+
* Returns `{ wire, money }` for the PSP's remaining (`'10.00'`, USD 1000), never more than it and
|
|
305
|
+
* never more than one legacy rounding below what `refund` encodes to. Null (send `refund` as
|
|
306
|
+
* is) for every other case: a PSP that never encoded in floating point, a capture that matches
|
|
307
|
+
* today's spelling or no spelling, a partial refund, a refund that already fits, mixed
|
|
308
|
+
* currencies, and any amount or PSP fact that cannot be read. Never throws.
|
|
309
|
+
*/
|
|
310
|
+
declare function legacyFloatRefundClamp(psp: PspId, input: LegacyFloatRefundInput): LegacyFloatRefund | null;
|
|
311
|
+
interface PspPresentment {
|
|
312
|
+
/** Every currency some account of the PSP can present: the union over account countries. */
|
|
313
|
+
readonly currencies: ReadonlySet<CurrencyCode>;
|
|
314
|
+
/** Currencies only accounts registered in these countries can present (Stripe KWD: AE; PayPal BRL: BR). */
|
|
315
|
+
readonly currencyRequiresAccountCountry: ReadonlyMap<CurrencyCode, ReadonlySet<string>>;
|
|
316
|
+
/** Account countries limited to these currencies (Airwallex cards on a US or MX account). */
|
|
317
|
+
readonly accountCountryAllowsOnly: ReadonlyMap<string, ReadonlySet<CurrencyCode>>;
|
|
318
|
+
/**
|
|
319
|
+
* The account countries the PSP onboards, where each charges its own list (Paystack): what an
|
|
320
|
+
* account there always presents, and what it presents only once enabled on the account (Paystack
|
|
321
|
+
* USD on NG and KE accounts). Empty for every PSP without per-country lists.
|
|
322
|
+
*/
|
|
323
|
+
readonly accountCountries: ReadonlyMap<string, PspAccountCountry>;
|
|
324
|
+
/**
|
|
325
|
+
* Per account currency that names one account country, the opt-in currencies an account in
|
|
326
|
+
* that country can add (Paystack NGN and KES: USD). Only currencies with a companion are keys.
|
|
327
|
+
*/
|
|
328
|
+
readonly optInCompanions: ReadonlyMap<CurrencyCode, ReadonlySet<CurrencyCode>>;
|
|
329
|
+
}
|
|
330
|
+
interface PspAccountCountry {
|
|
331
|
+
/** What every account registered in the country presents. */
|
|
332
|
+
readonly currencies: ReadonlySet<CurrencyCode>;
|
|
333
|
+
/** What it presents only once the merchant has enabled it on the account (no API reports it). */
|
|
334
|
+
readonly optIn: ReadonlySet<CurrencyCode>;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* The PSP's presentment rules, as data: the union of currencies some account can charge, the
|
|
338
|
+
* currencies that need an account in particular countries, and the account countries limited to
|
|
339
|
+
* a list. For capability declarations that hold the rules themselves; `pspPresentmentCurrencies`
|
|
340
|
+
* applies them to one account. Fresh collections on every call. An unknown PSP throws
|
|
341
|
+
* `wire_unsupported`.
|
|
342
|
+
*/
|
|
343
|
+
declare function pspPresentment(psp: PspId): PspPresentment;
|
|
344
|
+
/**
|
|
345
|
+
* The account country a currency names for `psp`: the one country whose accounts present it
|
|
346
|
+
* (Paystack NGN: `'NG'`, XOF: `'CI'`, the only XOF country Paystack onboards). Null when several
|
|
347
|
+
* countries' accounts can present it (Paystack USD, on NG and KE accounts), when the PSP has no
|
|
348
|
+
* per-country lists, or for an unknown code. Never throws for a bad code; an unknown PSP throws
|
|
349
|
+
* `wire_unsupported`.
|
|
350
|
+
*/
|
|
351
|
+
declare function pspAccountCountryForCurrency(psp: PspId, currency: unknown): string | null;
|
|
352
|
+
interface PresentmentOptions {
|
|
353
|
+
/** ISO 3166 alpha-2, any case: only what an account registered there can present. */
|
|
354
|
+
accountCountry?: string;
|
|
355
|
+
/** With `accountCountry`, add the country's opt-in currencies (the merchant enabled them). Default false. */
|
|
356
|
+
includeOptIn?: boolean;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* The currencies `psp` lets an account present (charge buyers in). Without `accountCountry`, the
|
|
360
|
+
* union over every account country, opt-in currencies included; with it (ISO 3166 alpha-2, any
|
|
361
|
+
* case), only what an account registered there can charge: Stripe's three-decimal five need a UAE
|
|
362
|
+
* account, PayPal's BRL, CNY and MYR an in-country one, Airwallex cards on a US account take its
|
|
363
|
+
* documented 76 and on an MX account MXN only, a Paystack account its country's currency (plus USD
|
|
364
|
+
* on NG and KE with `includeOptIn`, and nothing for a country Paystack does not onboard). Not
|
|
365
|
+
* `pspCurrencies`, which is what the codec scales and the facade lets through (Stripe's adds every
|
|
366
|
+
* two-decimal ISO code it accepts on the wire).
|
|
367
|
+
*/
|
|
368
|
+
declare function pspPresentmentCurrencies(psp: PspId, options?: PresentmentOptions): ReadonlySet<CurrencyCode>;
|
|
369
|
+
interface ProviderAmountOptions {
|
|
370
|
+
/** Accept a negative amount (refunds, credits). Default false. */
|
|
371
|
+
allowNegative?: boolean;
|
|
372
|
+
/** Default `'.'`; `'auto'` decides from the text (see the core separator engine). */
|
|
373
|
+
decimalSeparator?: '.' | ',' | 'auto';
|
|
374
|
+
/** Read the first number and ignore the rest (`'22.67 + KDV'`). Default false. */
|
|
375
|
+
allowTrailingText?: boolean;
|
|
376
|
+
/** Rounding to the currency's storage digits (and the 'auto' whole-unit rounding). Default `'half-up'`. */
|
|
377
|
+
rounding?: RoundingMode;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* A provider's major-unit amount (finite number, or text read by the separator engine, which
|
|
381
|
+
* strips the currency's symbol and code) as Money, rounded once to the storage digits. Null on
|
|
382
|
+
* anything invalid (empty, unparseable, non-finite, negative without `allowNegative`, too large,
|
|
383
|
+
* unknown currency), never 0.
|
|
384
|
+
*/
|
|
385
|
+
declare function parseProviderAmount(value: unknown, currency: string, options?: ProviderAmountOptions): Money | null;
|
|
386
|
+
/** RBI e-mandate cap Razorpay token registrations carry as `max_amount`: INR 15,000 (1,500,000 paise = stored). */
|
|
387
|
+
declare const RAZORPAY_AFA_FREE_CAP: Money;
|
|
388
|
+
type VerificationPsp = 'paystack' | 'razorpay' | 'mollie' | 'adyen';
|
|
389
|
+
/** The verification PSPs with a documented currency (`VERIFICATION_CURRENCY`): the charge may omit it. */
|
|
390
|
+
type VerificationDefaultPsp = 'razorpay' | 'mollie';
|
|
391
|
+
/**
|
|
392
|
+
* The symbolic charge a saved-card setup makes: Paystack one major unit, Razorpay one INR (any
|
|
393
|
+
* other currency is `wire_unsupported`), Mollie one smallest wire unit (`'0.01'`, `'1'` for ISK
|
|
394
|
+
* and JPY), Adyen zero. Vault charges are always new, so the iso-minor-v2 convention applies.
|
|
395
|
+
* `currency` may be left out (undefined only; `''` and null still throw `currency_missing`) for
|
|
396
|
+
* the PSPs that document a currency every account takes: Razorpay INR (recurring is INR only),
|
|
397
|
+
* Mollie EUR (every Mollie card method takes it). Adyen and Paystack have none, so their
|
|
398
|
+
* callers pass one: an Adyen fallback is the caller's policy (any currency the merchant account
|
|
399
|
+
* processes verifies a zero amount), not an Adyen fact.
|
|
400
|
+
*/
|
|
401
|
+
declare function verificationCharge(psp: VerificationDefaultPsp, currency?: string): {
|
|
402
|
+
wire: number | string;
|
|
403
|
+
money: Money;
|
|
404
|
+
};
|
|
405
|
+
declare function verificationCharge(psp: VerificationPsp, currency: string): {
|
|
406
|
+
wire: number | string;
|
|
407
|
+
money: Money;
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* iyzico's price spelling, on the text (no float): canonical decimal (no trailing fraction zeros),
|
|
411
|
+
* then `'.0'` when there is no `.` (`'10.50'` gives `'10.5'`, `'10.00'` gives `'10.0'`). Text that
|
|
412
|
+
* is not a plain decimal throws `parse`.
|
|
413
|
+
*/
|
|
414
|
+
declare function iyzicoPrice(wire: string): string;
|
|
415
|
+
interface SlotMoney {
|
|
416
|
+
readonly amount: StoredAmount;
|
|
417
|
+
/** Lower-case, as Medusa spells it. */
|
|
418
|
+
readonly currency_code: string;
|
|
419
|
+
}
|
|
420
|
+
/** `m` for a slot context's `money` key. */
|
|
421
|
+
declare function slotMoney(m: Money): SlotMoney;
|
|
422
|
+
/**
|
|
423
|
+
* The money a slot context carries: `context.money` when it is valid, else the legacy
|
|
424
|
+
* `total ?? price` with the first known of `currency_code`, `currency`, read leniently (numbers, numeric text,
|
|
425
|
+
* Medusa BigNumber shapes). Undefined when the amount or the currency is missing or unreadable.
|
|
426
|
+
*/
|
|
427
|
+
declare function readSlotMoney(context: unknown): SlotMoney | undefined;
|
|
428
|
+
export { WIRE_SCALE_ISO_MINOR_V2 as $, wireKeyPart as A, pspHomeCurrency as B, eventMoney as C, SameWireAmountOptions as D, DestinationId as E, decodeWire as F, wireFactor as G, pspSupportsCurrency as H, encodeWire as I, ISO_MINOR_V2 as J, wireBreakdown as K, pspCurrencies as L, EncodeWireOptions as M, TryDecodeWireOptions as N, oneWireUnit as O, assertPspCurrency as P, WIRE_ROUNDING_MARKER as Q, pspDefaultCurrency as R, destinationAmount as S, googleMicros as T, pspWireDigits as U, pspMinimumAmount as V, tryDecodeWire as W, WIRE_ROUNDING_EXACT as X, PRE_CUTOVER as Y, WIRE_ROUNDING_KEY as Z, LegacyFloatRefund as _, AuthorizeNetAmounts as _t, VerificationDefaultPsp as a, EncodeGatedPsp as at, DestinationValue as b, PAYSTACK_CURRENCIES as bt, verificationCharge as c, IyzicoCurrency as ct, PresentmentOptions as d, PSP_IDS as dt, WIRE_SCALE_KEY as et, PspAccountCountry as f, PaystackCurrency as ft, pspPresentmentCurrencies as g, WireAmount as gt, pspPresentment as h, VndOnlyPsp as ht, RAZORPAY_AFA_FREE_CAP as i, AuthorizeNetCurrency as it, DecodeWireOptions as j, sameWireAmount as k, ProviderAmountOptions as l, MajorNumberPsp as lt, pspAccountCountryForCurrency as m, PspId as mt, readSlotMoney as n, conventionOf as nt, VerificationPsp as o, GatedPsp as ot, PspPresentment as p, PspCurrency as pt, Convention as q, slotMoney as r, mayHoldLegacyFloatRounding as rt, iyzicoPrice as s, IsoMinorPsp as st, SlotMoney as t, WIRE_SCALE_MARKER as tt, parseProviderAmount as u, MajorStringPsp as ut, LegacyFloatRefundInput as v, authorizeNetReversibleAmount as vt, feedPrice as w, EventMoney as x, legacyFloatRefundClamp as y, jsonDecimalLiteral as yt, pspHomeCountry as z };
|