@amboras-dev/money 0.2.0 → 0.4.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 +22 -11
- 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-CZRg4TOP.cjs → allocate-AusholrC.cjs} +3 -4
- package/dist/{allocate-X7_jAtOj.js → allocate-BBRfdaSC.js} +3 -4
- package/dist/{amount-BV0O-aN8.cjs → amount-Bzxw9aD4.cjs} +32 -14
- package/dist/{amount-BoYBMgK9.js → amount-off8IMBJ.js} +32 -14
- package/dist/{arithmetic-BhNwisjb.js → arithmetic-C97-YafD.js} +4 -5
- package/dist/{arithmetic-DjT4Kzgt.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-DLhno7eX.cjs → format-92fzvTXY.cjs} +9 -9
- package/dist/{format-BdPnijvn.js → format-BJC513u4.js} +9 -9
- 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 +10 -12
- package/dist/index.d.cts +17 -23
- package/dist/index.d.ts +17 -23
- package/dist/index.js +10 -12
- package/dist/input.cjs +7 -10
- package/dist/input.d.cts +16 -22
- package/dist/input.d.ts +16 -22
- package/dist/input.js +7 -10
- package/dist/{iso-minor-wSwJN57T.cjs → iso-minor-DyNjT9A1.cjs} +2 -3
- package/dist/{iso-minor-CqkWDxHS.js → iso-minor-odkY-e6I.js} +2 -3
- package/dist/{medusa-lRY9xlsf.cjs → medusa-CzVK0bth.cjs} +3 -4
- package/dist/{medusa-DBXJXXvF.d.ts → medusa-DofdvIgQ.d.cts} +1 -3
- package/dist/{medusa-4K8N1pUc.d.cts → medusa-DrbYmD2Y.d.ts} +1 -3
- package/dist/{medusa-DqJY1qpj.js → medusa-pKGlImn9.js} +3 -4
- package/dist/{money-B-3aFjNJ.d.cts → money-BkMeYDEW.d.cts} +0 -6
- package/dist/{money-B-3aFjNJ.d.ts → money-BkMeYDEW.d.ts} +0 -6
- package/dist/{money-WhnGiI00.js → money-BxbAw7BP.js} +7 -15
- package/dist/{money-B3wH_Z4S.cjs → money-DWBjuuEK.cjs} +7 -15
- package/dist/{number-text-DE-q4jO5.js → number-text-Bj-gZXiF.js} +3 -4
- package/dist/{number-text-BWu67jUq.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-D1VB9xXG.js → percent-CB3Ixjc_.js} +2 -3
- package/dist/{percent-C0InC2t2.cjs → percent-DABHiSBs.cjs} +2 -3
- package/dist/{rate-DBPiYgT1.d.ts → rate-BvvZUdSu.d.ts} +1 -3
- package/dist/{rate-tqK8ijG0.d.cts → rate-CEakW3ia.d.cts} +1 -3
- package/dist/{rate-CVeMii4a.cjs → rate-CEjWTATc.cjs} +3 -4
- package/dist/{rate-DicStBue.js → rate-D6S2_wgZ.js} +3 -4
- package/dist/{reporting-tpGJbqYp.d.ts → reporting-DFNyDBdi.d.cts} +2 -4
- package/dist/{reporting-CG-ai2sM.d.cts → reporting-jIBILvnr.d.ts} +2 -4
- package/dist/{retail-DRUTTQoJ.d.ts → retail-B04CjW3b.d.ts} +1 -3
- package/dist/{retail-Cml8YSKg.cjs → retail-CYGPU4ea.cjs} +4 -5
- package/dist/{retail-C_BPLvMj.d.cts → retail-CmEyJQOH.d.cts} +1 -3
- package/dist/{retail-1mu888J1.js → retail-DXgs11ov.js} +4 -5
- package/dist/{rounding-DHBtNCHG.cjs → rounding-4QKTRbMQ.cjs} +2 -3
- package/dist/{rounding-g9rvye0k.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 +39198 -12
- package/dist/testing.d.cts +20 -13
- package/dist/testing.d.ts +20 -13
- package/dist/testing.js +39198 -13
- package/dist/{wire-sW0yzqth.js → wire-B4QU8O3W.js} +350 -93
- package/dist/{wire-CaUN9Vf_.d.ts → wire-CVNicirK.d.ts} +165 -46
- package/dist/{wire-xjYXv4go.d.cts → wire-CtNJmWVP.d.cts} +165 -46
- package/dist/{wire-Bhuut8cW.cjs → wire-u2tmHY0Y.cjs} +403 -92
- package/dist/wire.cjs +10 -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
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { b as FractionDigits, g as CurrencyCode, i as Money, o as StoredAmount, t as FractionalMoney, z as RoundingMode } from "./money-
|
|
2
|
-
|
|
1
|
+
import { b as FractionDigits, g as CurrencyCode, i as Money, o as StoredAmount, t as FractionalMoney, z as RoundingMode } from "./money-BkMeYDEW.js";
|
|
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"];
|
|
3
7
|
/**
|
|
4
8
|
* The first `"<field>": <decimal>` (quoted or not) in a raw JSON body, verbatim: `JSON.parse`
|
|
5
9
|
* would turn the gateway's `43.00` into `43`. The value is the whole JSON token, held to
|
|
@@ -17,8 +21,6 @@ interface AuthorizeNetAmounts {
|
|
|
17
21
|
authAmount?: string | null;
|
|
18
22
|
}
|
|
19
23
|
declare function authorizeNetReversibleAmount(details: AuthorizeNetAmounts): string | undefined;
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/wire/descriptors.d.ts
|
|
22
24
|
type PspId = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo' | 'vnpay' | 'paypal' | 'mollie' | 'airwallex' | 'iyzico' | 'authorize-net' | 'payoo';
|
|
23
25
|
/** ISO minor units, marker-gated decode: a payment created before the cutover holds storage units at the PSP. */
|
|
24
26
|
type GatedPsp = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo';
|
|
@@ -29,10 +31,19 @@ type MajorStringPsp = 'paypal' | 'mollie' | 'iyzico' | 'authorize-net';
|
|
|
29
31
|
type MajorNumberPsp = 'airwallex' | 'payoo';
|
|
30
32
|
/** What a PSP receives: major-unit text for PayPal, Mollie, iyzico and Authorize.Net, a number for the rest. */
|
|
31
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);
|
|
32
45
|
/** Every PSP id, in a stable order. */
|
|
33
46
|
declare const PSP_IDS: readonly PspId[];
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/wire/marker.d.ts
|
|
36
47
|
declare const WIRE_SCALE_KEY = "amboras_wire_scale";
|
|
37
48
|
declare const WIRE_SCALE_ISO_MINOR_V2 = "iso-minor-v2";
|
|
38
49
|
declare const WIRE_SCALE_MARKER: Readonly<{
|
|
@@ -52,8 +63,18 @@ declare const PRE_CUTOVER: Convention;
|
|
|
52
63
|
* fetched records only: it never queries (FORCE RLS would hide the row and the marker with it).
|
|
53
64
|
*/
|
|
54
65
|
declare function conventionOf(...records: unknown[]): Convention;
|
|
55
|
-
|
|
56
|
-
|
|
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;
|
|
57
78
|
/**
|
|
58
79
|
* `total` and its `parts` (same currency, non-negative, adding up to `total`) as integer wire
|
|
59
80
|
* amounts whose sum is exactly `encodeWire(psp, total)`: the wire total split by largest
|
|
@@ -64,8 +85,6 @@ declare function wireBreakdown(psp: IsoMinorPsp, total: Money, parts: Readonly<R
|
|
|
64
85
|
total: number;
|
|
65
86
|
parts: Record<string, number>;
|
|
66
87
|
};
|
|
67
|
-
//#endregion
|
|
68
|
-
//#region src/wire/codec.d.ts
|
|
69
88
|
/** Whether `psp` takes `currency` (any case, historic codes included). Never throws for a bad code. */
|
|
70
89
|
declare function pspSupportsCurrency(psp: PspId, currency: string): boolean;
|
|
71
90
|
/**
|
|
@@ -76,11 +95,29 @@ declare function pspCurrencies(psp: PspId): ReadonlySet<CurrencyCode>;
|
|
|
76
95
|
/**
|
|
77
96
|
* `currency` as a CurrencyCode `psp` takes. Empty throws `currency_missing` (`[<Tag>] Cannot
|
|
78
97
|
* scale an amount without a currency code; ...`); anything the PSP does not take throws
|
|
79
|
-
* `wire_unsupported` with the provider's own message.
|
|
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`).
|
|
80
100
|
*/
|
|
81
|
-
declare function assertPspCurrency(psp:
|
|
101
|
+
declare function assertPspCurrency<P extends PspId>(psp: P, currency: unknown): PspCurrency<P>;
|
|
82
102
|
/** `'VND'` for the single-currency providers (MoMo, Payoo, VNPay), else null. */
|
|
83
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;
|
|
84
121
|
/**
|
|
85
122
|
* Stored units per wire unit for an ISO-minor PSP: the PSP's override (Stripe ISK/UGX, Adyen
|
|
86
123
|
* ISK/CLP, Razorpay MGA, Paystack XOF, VNPay VND give 1; Adyen IDR/CVE give 100), else
|
|
@@ -125,25 +162,38 @@ declare function encodeWire<P extends EncodeGatedPsp>(psp: P, m: Money | Fractio
|
|
|
125
162
|
convention: Convention;
|
|
126
163
|
}): WireAmount<P>;
|
|
127
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;
|
|
128
177
|
/**
|
|
129
178
|
* A PSP wire amount as Money: ISO minor `half-up(w x wireFactor)` (pre-cutover: `half-up(w)`, the
|
|
130
179
|
* PSP already held storage units), major `half-up(w x storageScale)`. `wire` is a finite number
|
|
131
180
|
* or strict decimal text (`/^-?\d+(\.\d+)?$/`: no `''`, exponent or hex), else `amount_invalid`.
|
|
132
|
-
*
|
|
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.
|
|
133
187
|
* The currency is required (`currency_missing`), must be known (`currency_invalid`), must not be
|
|
134
188
|
* provider-only (Adyen CNH: `wire_unsupported`), and must pass the PSP's Medusa inbound gate
|
|
135
189
|
* (`wire_unsupported` with its message: Razorpay only its exponent table, Paystack no
|
|
136
190
|
* zero-decimal code but XOF, MoMo, Payoo and VNPay only VND). Other PSPs read any currency (a PSP
|
|
137
191
|
* may report a settlement currency).
|
|
138
192
|
*/
|
|
139
|
-
declare function decodeWire<P extends GatedPsp>(psp: P, wire: unknown, currency: string,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
convention?: Convention;
|
|
144
|
-
/** Accept a negative wire amount (balance transactions, reversals). Default false; never for VNPay. */
|
|
145
|
-
allowNegative?: boolean;
|
|
146
|
-
}
|
|
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;
|
|
147
197
|
/**
|
|
148
198
|
* `decodeWire` that never throws: undefined wherever it would throw (null, undefined, `''`,
|
|
149
199
|
* whitespace, unparseable or unsafe input, a missing, unknown or provider-only currency, one the
|
|
@@ -151,8 +201,6 @@ interface TryDecodeWireOptions {
|
|
|
151
201
|
* `convention`: no hidden default) and for a negative amount unless `allowNegative`.
|
|
152
202
|
*/
|
|
153
203
|
declare function tryDecodeWire(psp: PspId, wire: unknown, currency: unknown, options?: TryDecodeWireOptions): Money | undefined;
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/wire/compare.d.ts
|
|
156
204
|
interface SameWireAmountOptions {
|
|
157
205
|
/** Required for gated PSPs (Stripe, Adyen, Razorpay, Paystack, MoMo); without it the answer is false. */
|
|
158
206
|
convention?: Convention;
|
|
@@ -162,6 +210,15 @@ interface SameWireAmountOptions {
|
|
|
162
210
|
* digits, half-up (HUF 44.50 went as `'45'`). Major-unit PSPs only.
|
|
163
211
|
*/
|
|
164
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;
|
|
165
222
|
/**
|
|
166
223
|
* The PSP only ever reports decimal text (Mollie, PayPal): a reported (or `requested`) value
|
|
167
224
|
* that is not a string is not its amount, whatever number it holds.
|
|
@@ -194,11 +251,7 @@ declare function sameWireAmount(psp: PspId, reported: unknown, expected: Money |
|
|
|
194
251
|
declare function oneWireUnit(psp: PspId, currency: string, convention?: Convention): Money;
|
|
195
252
|
/** The wire amount as it goes into Redis skip keys and idempotency keys: `String(wire)`, byte for byte. */
|
|
196
253
|
declare function wireKeyPart(wire: number | string): string;
|
|
197
|
-
//#endregion
|
|
198
|
-
//#region src/data/destinations.d.ts
|
|
199
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';
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region src/wire/destinations.d.ts
|
|
202
255
|
interface DestinationValue {
|
|
203
256
|
readonly value: number | string;
|
|
204
257
|
readonly currency: string;
|
|
@@ -223,8 +276,38 @@ interface EventMoney {
|
|
|
223
276
|
}
|
|
224
277
|
/** First-party analytics money: the stored integer and the lower-case code (the ClickHouse `Int64` contract). */
|
|
225
278
|
declare function eventMoney(m: Money): EventMoney;
|
|
226
|
-
|
|
227
|
-
|
|
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;
|
|
228
311
|
interface PspPresentment {
|
|
229
312
|
/** Every currency some account of the PSP can present: the union over account countries. */
|
|
230
313
|
readonly currencies: ReadonlySet<CurrencyCode>;
|
|
@@ -232,6 +315,23 @@ interface PspPresentment {
|
|
|
232
315
|
readonly currencyRequiresAccountCountry: ReadonlyMap<CurrencyCode, ReadonlySet<string>>;
|
|
233
316
|
/** Account countries limited to these currencies (Airwallex cards on a US or MX account). */
|
|
234
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>;
|
|
235
335
|
}
|
|
236
336
|
/**
|
|
237
337
|
* The PSP's presentment rules, as data: the union of currencies some account can charge, the
|
|
@@ -242,18 +342,30 @@ interface PspPresentment {
|
|
|
242
342
|
*/
|
|
243
343
|
declare function pspPresentment(psp: PspId): PspPresentment;
|
|
244
344
|
/**
|
|
245
|
-
* The
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* through (Stripe's adds every two-decimal ISO code it accepts on the wire).
|
|
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`.
|
|
251
350
|
*/
|
|
252
|
-
declare function
|
|
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. */
|
|
253
354
|
accountCountry?: string;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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>;
|
|
257
369
|
interface ProviderAmountOptions {
|
|
258
370
|
/** Accept a negative amount (refunds, credits). Default false. */
|
|
259
371
|
allowNegative?: boolean;
|
|
@@ -271,16 +383,26 @@ interface ProviderAmountOptions {
|
|
|
271
383
|
* unknown currency), never 0.
|
|
272
384
|
*/
|
|
273
385
|
declare function parseProviderAmount(value: unknown, currency: string, options?: ProviderAmountOptions): Money | null;
|
|
274
|
-
//#endregion
|
|
275
|
-
//#region src/wire/providers.d.ts
|
|
276
386
|
/** RBI e-mandate cap Razorpay token registrations carry as `max_amount`: INR 15,000 (1,500,000 paise = stored). */
|
|
277
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';
|
|
278
391
|
/**
|
|
279
392
|
* The symbolic charge a saved-card setup makes: Paystack one major unit, Razorpay one INR (any
|
|
280
393
|
* other currency is `wire_unsupported`), Mollie one smallest wire unit (`'0.01'`, `'1'` for ISK
|
|
281
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.
|
|
282
400
|
*/
|
|
283
|
-
declare function verificationCharge(psp:
|
|
401
|
+
declare function verificationCharge(psp: VerificationDefaultPsp, currency?: string): {
|
|
402
|
+
wire: number | string;
|
|
403
|
+
money: Money;
|
|
404
|
+
};
|
|
405
|
+
declare function verificationCharge(psp: VerificationPsp, currency: string): {
|
|
284
406
|
wire: number | string;
|
|
285
407
|
money: Money;
|
|
286
408
|
};
|
|
@@ -290,8 +412,6 @@ declare function verificationCharge(psp: 'paystack' | 'razorpay' | 'mollie' | 'a
|
|
|
290
412
|
* is not a plain decimal throws `parse`.
|
|
291
413
|
*/
|
|
292
414
|
declare function iyzicoPrice(wire: string): string;
|
|
293
|
-
//#endregion
|
|
294
|
-
//#region src/wire/slot.d.ts
|
|
295
415
|
interface SlotMoney {
|
|
296
416
|
readonly amount: StoredAmount;
|
|
297
417
|
/** Lower-case, as Medusa spells it. */
|
|
@@ -305,5 +425,4 @@ declare function slotMoney(m: Money): SlotMoney;
|
|
|
305
425
|
* Medusa BigNumber shapes). Undefined when the amount or the currency is missing or unreadable.
|
|
306
426
|
*/
|
|
307
427
|
declare function readSlotMoney(context: unknown): SlotMoney | undefined;
|
|
308
|
-
|
|
309
|
-
export { jsonDecimalLiteral as $, pspMinimumAmount as A, WIRE_SCALE_KEY as B, EncodeWireOptions as C, encodeWire as D, decodeWire as E, wireBreakdown as F, IsoMinorPsp as G, conventionOf as H, Convention as I, PSP_IDS as J, MajorNumberPsp as K, ISO_MINOR_V2 as L, pspWireDigits as M, tryDecodeWire as N, pspCurrencies as O, wireFactor as P, authorizeNetReversibleAmount as Q, PRE_CUTOVER as R, wireKeyPart as S, assertPspCurrency as T, EncodeGatedPsp as U, WIRE_SCALE_MARKER as V, GatedPsp as W, WireAmount as X, PspId as Y, AuthorizeNetAmounts as Z, googleMicros as _, iyzicoPrice as a, oneWireUnit as b, parseProviderAmount as c, pspPresentmentCurrencies as d, DestinationValue as f, feedPrice as g, eventMoney as h, RAZORPAY_AFA_FREE_CAP as i, pspSupportsCurrency as j, pspDefaultCurrency as k, PspPresentment as l, destinationAmount as m, readSlotMoney as n, verificationCharge as o, EventMoney as p, MajorStringPsp as q, slotMoney as r, ProviderAmountOptions as s, SlotMoney as t, pspPresentment as u, DestinationId as v, TryDecodeWireOptions as w, sameWireAmount as x, SameWireAmountOptions as y, WIRE_SCALE_ISO_MINOR_V2 as z };
|
|
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 };
|