@vectoriox/iox-ui 5.92.0 → 5.94.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/commerce-core/index.d.ts +638 -0
- package/commerce-core/package.json +3 -0
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs +1325 -0
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs.map +1 -0
- package/package.json +5 -1
- package/src/commerce-core/cart.ts +305 -0
- package/src/commerce-core/catalog.ts +42 -0
- package/src/commerce-core/checkout.ts +202 -0
- package/src/commerce-core/currency.ts +99 -0
- package/src/commerce-core/decimal.ts +106 -0
- package/src/commerce-core/labels.ts +29 -0
- package/src/commerce-core/limits.ts +9 -0
- package/src/commerce-core/money-error.ts +19 -0
- package/src/commerce-core/money.ts +159 -0
- package/src/commerce-core/order-snapshot.ts +151 -0
- package/src/commerce-core/orders.ts +172 -0
- package/src/commerce-core/payments.ts +196 -0
- package/src/commerce-core/public-api.ts +23 -0
- package/src/commerce-core/shipping.ts +168 -0
- package/src/commerce-core/text.ts +13 -0
- package/src/commerce-core/vat.ts +38 -0
|
@@ -0,0 +1,1325 @@
|
|
|
1
|
+
var MoneyErrorCode;
|
|
2
|
+
(function (MoneyErrorCode) {
|
|
3
|
+
MoneyErrorCode["UnknownCurrency"] = "unknown-currency";
|
|
4
|
+
MoneyErrorCode["NotMoney"] = "not-money";
|
|
5
|
+
MoneyErrorCode["NotInteger"] = "not-integer";
|
|
6
|
+
MoneyErrorCode["NotANumber"] = "not-a-number";
|
|
7
|
+
MoneyErrorCode["TooManyDecimals"] = "too-many-decimals";
|
|
8
|
+
MoneyErrorCode["CurrencyMismatch"] = "currency-mismatch";
|
|
9
|
+
MoneyErrorCode["NotWhole"] = "not-whole";
|
|
10
|
+
MoneyErrorCode["Negative"] = "negative";
|
|
11
|
+
MoneyErrorCode["Overflow"] = "overflow";
|
|
12
|
+
MoneyErrorCode["OutOfRange"] = "out-of-range";
|
|
13
|
+
})(MoneyErrorCode || (MoneyErrorCode = {}));
|
|
14
|
+
class MoneyError extends Error {
|
|
15
|
+
constructor(code, message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.name = 'MoneyError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var CurrencyCode;
|
|
23
|
+
(function (CurrencyCode) {
|
|
24
|
+
CurrencyCode["ILS"] = "ILS";
|
|
25
|
+
CurrencyCode["USD"] = "USD";
|
|
26
|
+
CurrencyCode["EUR"] = "EUR";
|
|
27
|
+
CurrencyCode["GBP"] = "GBP";
|
|
28
|
+
CurrencyCode["CHF"] = "CHF";
|
|
29
|
+
CurrencyCode["CAD"] = "CAD";
|
|
30
|
+
CurrencyCode["AUD"] = "AUD";
|
|
31
|
+
CurrencyCode["NZD"] = "NZD";
|
|
32
|
+
CurrencyCode["SEK"] = "SEK";
|
|
33
|
+
CurrencyCode["NOK"] = "NOK";
|
|
34
|
+
CurrencyCode["DKK"] = "DKK";
|
|
35
|
+
CurrencyCode["PLN"] = "PLN";
|
|
36
|
+
CurrencyCode["CZK"] = "CZK";
|
|
37
|
+
CurrencyCode["HUF"] = "HUF";
|
|
38
|
+
CurrencyCode["RON"] = "RON";
|
|
39
|
+
CurrencyCode["TRY"] = "TRY";
|
|
40
|
+
CurrencyCode["AED"] = "AED";
|
|
41
|
+
CurrencyCode["SAR"] = "SAR";
|
|
42
|
+
CurrencyCode["QAR"] = "QAR";
|
|
43
|
+
CurrencyCode["EGP"] = "EGP";
|
|
44
|
+
CurrencyCode["MAD"] = "MAD";
|
|
45
|
+
CurrencyCode["ZAR"] = "ZAR";
|
|
46
|
+
CurrencyCode["INR"] = "INR";
|
|
47
|
+
CurrencyCode["CNY"] = "CNY";
|
|
48
|
+
CurrencyCode["HKD"] = "HKD";
|
|
49
|
+
CurrencyCode["SGD"] = "SGD";
|
|
50
|
+
CurrencyCode["THB"] = "THB";
|
|
51
|
+
CurrencyCode["MXN"] = "MXN";
|
|
52
|
+
CurrencyCode["BRL"] = "BRL";
|
|
53
|
+
CurrencyCode["JPY"] = "JPY";
|
|
54
|
+
CurrencyCode["KRW"] = "KRW";
|
|
55
|
+
CurrencyCode["VND"] = "VND";
|
|
56
|
+
CurrencyCode["CLP"] = "CLP";
|
|
57
|
+
CurrencyCode["ISK"] = "ISK";
|
|
58
|
+
CurrencyCode["BHD"] = "BHD";
|
|
59
|
+
CurrencyCode["KWD"] = "KWD";
|
|
60
|
+
CurrencyCode["JOD"] = "JOD";
|
|
61
|
+
CurrencyCode["OMR"] = "OMR";
|
|
62
|
+
CurrencyCode["TND"] = "TND";
|
|
63
|
+
})(CurrencyCode || (CurrencyCode = {}));
|
|
64
|
+
/** ISO-4217 minor units — our own table, never Intl's CLDR digits (they differ for some codes). */
|
|
65
|
+
const CURRENCY_EXPONENTS = Object.freeze({
|
|
66
|
+
[CurrencyCode.ILS]: 2,
|
|
67
|
+
[CurrencyCode.USD]: 2,
|
|
68
|
+
[CurrencyCode.EUR]: 2,
|
|
69
|
+
[CurrencyCode.GBP]: 2,
|
|
70
|
+
[CurrencyCode.CHF]: 2,
|
|
71
|
+
[CurrencyCode.CAD]: 2,
|
|
72
|
+
[CurrencyCode.AUD]: 2,
|
|
73
|
+
[CurrencyCode.NZD]: 2,
|
|
74
|
+
[CurrencyCode.SEK]: 2,
|
|
75
|
+
[CurrencyCode.NOK]: 2,
|
|
76
|
+
[CurrencyCode.DKK]: 2,
|
|
77
|
+
[CurrencyCode.PLN]: 2,
|
|
78
|
+
[CurrencyCode.CZK]: 2,
|
|
79
|
+
[CurrencyCode.HUF]: 2,
|
|
80
|
+
[CurrencyCode.RON]: 2,
|
|
81
|
+
[CurrencyCode.TRY]: 2,
|
|
82
|
+
[CurrencyCode.AED]: 2,
|
|
83
|
+
[CurrencyCode.SAR]: 2,
|
|
84
|
+
[CurrencyCode.QAR]: 2,
|
|
85
|
+
[CurrencyCode.EGP]: 2,
|
|
86
|
+
[CurrencyCode.MAD]: 2,
|
|
87
|
+
[CurrencyCode.ZAR]: 2,
|
|
88
|
+
[CurrencyCode.INR]: 2,
|
|
89
|
+
[CurrencyCode.CNY]: 2,
|
|
90
|
+
[CurrencyCode.HKD]: 2,
|
|
91
|
+
[CurrencyCode.SGD]: 2,
|
|
92
|
+
[CurrencyCode.THB]: 2,
|
|
93
|
+
[CurrencyCode.MXN]: 2,
|
|
94
|
+
[CurrencyCode.BRL]: 2,
|
|
95
|
+
[CurrencyCode.JPY]: 0,
|
|
96
|
+
[CurrencyCode.KRW]: 0,
|
|
97
|
+
[CurrencyCode.VND]: 0,
|
|
98
|
+
[CurrencyCode.CLP]: 0,
|
|
99
|
+
[CurrencyCode.ISK]: 0,
|
|
100
|
+
[CurrencyCode.BHD]: 3,
|
|
101
|
+
[CurrencyCode.KWD]: 3,
|
|
102
|
+
[CurrencyCode.JOD]: 3,
|
|
103
|
+
[CurrencyCode.OMR]: 3,
|
|
104
|
+
[CurrencyCode.TND]: 3,
|
|
105
|
+
});
|
|
106
|
+
const CURRENCY_CODES = Object.freeze(Object.values(CurrencyCode));
|
|
107
|
+
function isCurrencyCode(value) {
|
|
108
|
+
return typeof value === 'string' && Object.prototype.hasOwnProperty.call(CURRENCY_EXPONENTS, value);
|
|
109
|
+
}
|
|
110
|
+
function currencyExponent(currency) {
|
|
111
|
+
if (!isCurrencyCode(currency)) {
|
|
112
|
+
throw new MoneyError(MoneyErrorCode.UnknownCurrency, `Unknown currency: ${String(currency)}`);
|
|
113
|
+
}
|
|
114
|
+
return CURRENCY_EXPONENTS[currency];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var DecimalRounding;
|
|
118
|
+
(function (DecimalRounding) {
|
|
119
|
+
DecimalRounding["Exact"] = "exact";
|
|
120
|
+
DecimalRounding["HalfEven"] = "half-even";
|
|
121
|
+
})(DecimalRounding || (DecimalRounding = {}));
|
|
122
|
+
const DECIMAL = /^([+-])?(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d{1,3}))?$/;
|
|
123
|
+
/** Plain decimal text, or the e-notation `String(number)` produces below 1e-6 and from 1e21. */
|
|
124
|
+
function parseDecimal(text) {
|
|
125
|
+
const match = DECIMAL.exec(text);
|
|
126
|
+
if (!match)
|
|
127
|
+
return null;
|
|
128
|
+
const int = match[2] ?? '';
|
|
129
|
+
const frac = match[3] ?? '';
|
|
130
|
+
if (!int && !frac)
|
|
131
|
+
return null;
|
|
132
|
+
const digits = int + frac;
|
|
133
|
+
const point = int.length + Number(match[4] ?? 0);
|
|
134
|
+
const shiftedInt = point <= 0 ? '' : point >= digits.length ? digits + '0'.repeat(point - digits.length) : digits.slice(0, point);
|
|
135
|
+
const shiftedFrac = point <= 0 ? '0'.repeat(-point) + digits : point >= digits.length ? '' : digits.slice(point);
|
|
136
|
+
return {
|
|
137
|
+
negative: match[1] === '-',
|
|
138
|
+
int: shiftedInt.replace(/^0+/, ''),
|
|
139
|
+
frac: shiftedFrac.replace(/0+$/, ''),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function safeFromDigits(digits) {
|
|
143
|
+
const trimmed = digits.replace(/^0+/, '') || '0';
|
|
144
|
+
const value = trimmed.length > 16 ? Infinity : Number(trimmed);
|
|
145
|
+
if (!Number.isSafeInteger(value)) {
|
|
146
|
+
throw new MoneyError(MoneyErrorCode.Overflow, `${digits} is beyond the safe integer range`);
|
|
147
|
+
}
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
/** Scales a parsed decimal by 10^exponent into an integer, without ever touching a float. */
|
|
151
|
+
function decimalToScaledInteger(decimal, exponent, rounding) {
|
|
152
|
+
const kept = decimal.frac.slice(0, exponent);
|
|
153
|
+
const rest = decimal.frac.slice(exponent);
|
|
154
|
+
if (rest && rounding === DecimalRounding.Exact) {
|
|
155
|
+
throw new MoneyError(MoneyErrorCode.TooManyDecimals, `More than ${exponent} decimal digits`);
|
|
156
|
+
}
|
|
157
|
+
let magnitude = safeFromDigits(decimal.int + kept.padEnd(exponent, '0'));
|
|
158
|
+
if (rest) {
|
|
159
|
+
const first = Number(rest[0]);
|
|
160
|
+
const tie = first === 5 && /^5$/.test(rest);
|
|
161
|
+
const up = first > 5 || (first === 5 && !tie) || (tie && magnitude % 2 === 1);
|
|
162
|
+
if (up)
|
|
163
|
+
magnitude += 1;
|
|
164
|
+
if (!Number.isSafeInteger(magnitude)) {
|
|
165
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Rounded value is beyond the safe integer range');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return decimal.negative && magnitude !== 0 ? -magnitude : magnitude;
|
|
169
|
+
}
|
|
170
|
+
/** Integer division rounded half-to-even; numerator ≥ 0, denominator > 0, both safe integers. */
|
|
171
|
+
function divideHalfEven(numerator, denominator) {
|
|
172
|
+
let quotient = Math.trunc(numerator / denominator);
|
|
173
|
+
let remainder = numerator - quotient * denominator;
|
|
174
|
+
while (remainder < 0) {
|
|
175
|
+
quotient -= 1;
|
|
176
|
+
remainder += denominator;
|
|
177
|
+
}
|
|
178
|
+
while (remainder >= denominator) {
|
|
179
|
+
quotient += 1;
|
|
180
|
+
remainder -= denominator;
|
|
181
|
+
}
|
|
182
|
+
const twice = remainder * 2;
|
|
183
|
+
if (twice > denominator || (twice === denominator && quotient % 2 === 1))
|
|
184
|
+
quotient += 1;
|
|
185
|
+
return quotient;
|
|
186
|
+
}
|
|
187
|
+
/** Integer division that never trusts the float quotient: trunc, then corrected by the remainder. */
|
|
188
|
+
function divMod(numerator, denominator) {
|
|
189
|
+
let quotient = Math.trunc(numerator / denominator);
|
|
190
|
+
let remainder = numerator - quotient * denominator;
|
|
191
|
+
while (remainder < 0) {
|
|
192
|
+
quotient -= 1;
|
|
193
|
+
remainder += denominator;
|
|
194
|
+
}
|
|
195
|
+
while (remainder >= denominator) {
|
|
196
|
+
quotient += 1;
|
|
197
|
+
remainder -= denominator;
|
|
198
|
+
}
|
|
199
|
+
return [quotient, remainder];
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* round-half-even(a × b / d) for a, b ≥ 0 and d > b, without forming a × b (it can pass 2^53): a = q·d + r, so
|
|
203
|
+
* a·b/d = q·b + r·b/d, where q·b < a and r·b < d·b — callers keep d·b a safe integer.
|
|
204
|
+
*/
|
|
205
|
+
function mulDivHalfEven(a, b, d) {
|
|
206
|
+
const [q, r] = divMod(a, d);
|
|
207
|
+
const [f, rest] = divMod(r * b, d);
|
|
208
|
+
let result = q * b + f;
|
|
209
|
+
const twice = rest * 2;
|
|
210
|
+
if (twice > d || (twice === d && result % 2 === 1))
|
|
211
|
+
result += 1;
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const MAX_PERCENT_DECIMALS = 6;
|
|
216
|
+
function isMoney(value) {
|
|
217
|
+
if (typeof value !== 'object' || value === null)
|
|
218
|
+
return false;
|
|
219
|
+
const record = value;
|
|
220
|
+
return Number.isSafeInteger(record['amount']) && isCurrencyCode(record['currency']);
|
|
221
|
+
}
|
|
222
|
+
function assertWhole(amount, what) {
|
|
223
|
+
if (typeof amount !== 'number' || !Number.isSafeInteger(amount)) {
|
|
224
|
+
throw new MoneyError(MoneyErrorCode.NotInteger, `${what} must be a whole number of minor units, got ${String(amount)}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function assertMoney(value) {
|
|
228
|
+
if (typeof value !== 'object' || value === null) {
|
|
229
|
+
throw new MoneyError(MoneyErrorCode.NotMoney, `Not a Money value: ${String(value)}`);
|
|
230
|
+
}
|
|
231
|
+
currencyExponent(value.currency);
|
|
232
|
+
assertWhole(value.amount, 'Money.amount');
|
|
233
|
+
}
|
|
234
|
+
function assertSameCurrency(a, b) {
|
|
235
|
+
assertMoney(a);
|
|
236
|
+
assertMoney(b);
|
|
237
|
+
if (a.currency !== b.currency) {
|
|
238
|
+
throw new MoneyError(MoneyErrorCode.CurrencyMismatch, `Cannot combine ${a.currency} with ${b.currency}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function safeResult(amount, currency) {
|
|
242
|
+
if (!Number.isSafeInteger(amount)) {
|
|
243
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Result is beyond the safe integer range');
|
|
244
|
+
}
|
|
245
|
+
return { amount: amount === 0 ? 0 : amount, currency };
|
|
246
|
+
}
|
|
247
|
+
function money(amount, currency) {
|
|
248
|
+
currencyExponent(currency);
|
|
249
|
+
assertWhole(amount, 'amount');
|
|
250
|
+
return { amount: amount === 0 ? 0 : amount, currency };
|
|
251
|
+
}
|
|
252
|
+
function decimalText(value) {
|
|
253
|
+
if (typeof value === 'number')
|
|
254
|
+
return Number.isFinite(value) ? String(value) : null;
|
|
255
|
+
if (typeof value === 'string')
|
|
256
|
+
return value.trim();
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
/** Exact: `19.99` → 1999 by reading the digits, never `x * 100`; refuses digits the currency lacks. */
|
|
260
|
+
function majorToMinor(major, currency) {
|
|
261
|
+
const exponent = currencyExponent(currency);
|
|
262
|
+
const text = decimalText(major);
|
|
263
|
+
const decimal = text === null ? null : parseDecimal(text);
|
|
264
|
+
if (!decimal) {
|
|
265
|
+
throw new MoneyError(MoneyErrorCode.NotANumber, `Not a decimal amount: ${String(major)}`);
|
|
266
|
+
}
|
|
267
|
+
return decimalToScaledInteger(decimal, exponent, DecimalRounding.Exact);
|
|
268
|
+
}
|
|
269
|
+
function minorToMajor(minor, currency) {
|
|
270
|
+
const exponent = currencyExponent(currency);
|
|
271
|
+
assertWhole(minor, 'minor');
|
|
272
|
+
return exponent === 0 ? minor : minor / 10 ** exponent;
|
|
273
|
+
}
|
|
274
|
+
function addMoney(a, b) {
|
|
275
|
+
assertSameCurrency(a, b);
|
|
276
|
+
return safeResult(a.amount + b.amount, a.currency);
|
|
277
|
+
}
|
|
278
|
+
function subtractMoney(a, b) {
|
|
279
|
+
assertSameCurrency(a, b);
|
|
280
|
+
return safeResult(a.amount - b.amount, a.currency);
|
|
281
|
+
}
|
|
282
|
+
function timesMoney(value, quantity) {
|
|
283
|
+
assertMoney(value);
|
|
284
|
+
if (typeof quantity !== 'number' || !Number.isSafeInteger(quantity)) {
|
|
285
|
+
throw new MoneyError(MoneyErrorCode.NotWhole, `Quantity must be a whole number, got ${String(quantity)}`);
|
|
286
|
+
}
|
|
287
|
+
if (quantity < 0) {
|
|
288
|
+
throw new MoneyError(MoneyErrorCode.Negative, `Quantity cannot be negative, got ${quantity}`);
|
|
289
|
+
}
|
|
290
|
+
return safeResult(value.amount * quantity, value.currency);
|
|
291
|
+
}
|
|
292
|
+
/** `percent` of an amount, rounded ONCE to a minor unit, half-to-even (banker's). */
|
|
293
|
+
function percentOf(value, percent) {
|
|
294
|
+
assertMoney(value);
|
|
295
|
+
if (typeof percent !== 'number' || !Number.isFinite(percent)) {
|
|
296
|
+
throw new MoneyError(MoneyErrorCode.NotANumber, `Percent must be a finite number, got ${String(percent)}`);
|
|
297
|
+
}
|
|
298
|
+
if (percent < 0) {
|
|
299
|
+
throw new MoneyError(MoneyErrorCode.Negative, `Percent cannot be negative, got ${percent}`);
|
|
300
|
+
}
|
|
301
|
+
const decimal = parseDecimal(String(percent));
|
|
302
|
+
if (!decimal) {
|
|
303
|
+
throw new MoneyError(MoneyErrorCode.NotANumber, `Percent must be a finite number, got ${String(percent)}`);
|
|
304
|
+
}
|
|
305
|
+
if (decimal.frac.length > MAX_PERCENT_DECIMALS) {
|
|
306
|
+
throw new MoneyError(MoneyErrorCode.TooManyDecimals, `Percent has more than ${MAX_PERCENT_DECIMALS} decimal digits`);
|
|
307
|
+
}
|
|
308
|
+
const scale = decimal.frac.length;
|
|
309
|
+
const percentScaled = decimalToScaledInteger(decimal, scale, DecimalRounding.Exact);
|
|
310
|
+
const numerator = Math.abs(value.amount) * percentScaled;
|
|
311
|
+
if (!Number.isSafeInteger(numerator)) {
|
|
312
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Percent of this amount is beyond the safe integer range');
|
|
313
|
+
}
|
|
314
|
+
const magnitude = divideHalfEven(numerator, 100 * 10 ** scale);
|
|
315
|
+
return safeResult(value.amount < 0 ? -magnitude : magnitude, value.currency);
|
|
316
|
+
}
|
|
317
|
+
const formatters = new Map();
|
|
318
|
+
function formatMoney(value, locale) {
|
|
319
|
+
assertMoney(value);
|
|
320
|
+
const exponent = currencyExponent(value.currency);
|
|
321
|
+
const key = `${locale}|${value.currency}`;
|
|
322
|
+
let formatter = formatters.get(key);
|
|
323
|
+
if (!formatter) {
|
|
324
|
+
formatter = new Intl.NumberFormat(locale, {
|
|
325
|
+
style: 'currency',
|
|
326
|
+
currency: value.currency,
|
|
327
|
+
minimumFractionDigits: exponent,
|
|
328
|
+
maximumFractionDigits: exponent,
|
|
329
|
+
});
|
|
330
|
+
formatters.set(key, formatter);
|
|
331
|
+
}
|
|
332
|
+
return formatter.format(minorToMajor(value.amount, value.currency));
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* For the one boot migration of stored major-unit prices. A stored float may carry arithmetic noise
|
|
336
|
+
* (19.990000000000002), so extra digits round half-to-even instead of refusing. No usable price
|
|
337
|
+
* (null, '', NaN, text, a negative) → null; it never applies twice by itself — the caller marks rows.
|
|
338
|
+
*/
|
|
339
|
+
function migrateMajorPrice(value, currency) {
|
|
340
|
+
const exponent = currencyExponent(currency);
|
|
341
|
+
if (typeof value !== 'number' && typeof value !== 'string')
|
|
342
|
+
return null;
|
|
343
|
+
const text = decimalText(value);
|
|
344
|
+
const decimal = text ? parseDecimal(text) : null;
|
|
345
|
+
if (!decimal || (decimal.negative && (decimal.int || decimal.frac)))
|
|
346
|
+
return null;
|
|
347
|
+
try {
|
|
348
|
+
return decimalToScaledInteger(decimal, exponent, DecimalRounding.HalfEven);
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* The words a refusal or a state is shown with. A string-rendered site and iox-cms's emails have no translation
|
|
357
|
+
* service, so the core carries English and Hebrew itself (the `blurbHe` / `sentWord` precedent); a host with its
|
|
358
|
+
* own translations may key them by the stable code instead.
|
|
359
|
+
*/
|
|
360
|
+
var CommerceLanguage;
|
|
361
|
+
(function (CommerceLanguage) {
|
|
362
|
+
CommerceLanguage["En"] = "en";
|
|
363
|
+
CommerceLanguage["He"] = "he";
|
|
364
|
+
})(CommerceLanguage || (CommerceLanguage = {}));
|
|
365
|
+
const LANGUAGE_ALIASES = Object.freeze({
|
|
366
|
+
en: CommerceLanguage.En,
|
|
367
|
+
he: CommerceLanguage.He,
|
|
368
|
+
iw: CommerceLanguage.He,
|
|
369
|
+
});
|
|
370
|
+
function commerceLanguage(lang) {
|
|
371
|
+
const primary = String(lang ?? '').trim().toLowerCase().split(/[-_]/)[0];
|
|
372
|
+
return LANGUAGE_ALIASES[primary] ?? CommerceLanguage.En;
|
|
373
|
+
}
|
|
374
|
+
function labelIn(label, lang) {
|
|
375
|
+
return label[commerceLanguage(lang)];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** A cart holds at most this many distinct lines; more are dropped (`too-many-lines`). */
|
|
379
|
+
const MAX_CART_LINES = 100;
|
|
380
|
+
/** One line's quantity is capped here (`quantity-capped`), before stock. */
|
|
381
|
+
const MAX_LINE_QUANTITY = 999;
|
|
382
|
+
/**
|
|
383
|
+
* The largest subtotal, shipping price or threshold, in minor units. Subtotal + shipping stays far below 2^53, and
|
|
384
|
+
* the included-VAT arithmetic never forms a product past it.
|
|
385
|
+
*/
|
|
386
|
+
const MAX_CART_AMOUNT = 10 ** 15;
|
|
387
|
+
|
|
388
|
+
const MAX_VAT_PERCENT = 100;
|
|
389
|
+
/** 17, 18, 7.7, 8.1 — four decimals is more than any rate in force; it also keeps the arithmetic below 2^53. */
|
|
390
|
+
const VAT_PERCENT_MAX_DECIMALS = 4;
|
|
391
|
+
function isVatPercent(value) {
|
|
392
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > MAX_VAT_PERCENT)
|
|
393
|
+
return false;
|
|
394
|
+
const decimal = parseDecimal(String(value));
|
|
395
|
+
return !!decimal && decimal.frac.length <= VAT_PERCENT_MAX_DECIMALS;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* The VAT a VAT-INCLUSIVE amount already holds (C-D8): amount × v / (100 + v), rounded ONCE to a minor unit,
|
|
399
|
+
* half-to-even. Exact: v is read as the integer R = v·10^s (s ≤ 4 decimals), so the share is
|
|
400
|
+
* amount × R / (100·10^s + R) in whole numbers. 118.00 at 18 % → 18.00; 100.00 at 17 % → 14.53.
|
|
401
|
+
*/
|
|
402
|
+
function includedVat(total, vatPercent) {
|
|
403
|
+
currencyExponent(total.currency);
|
|
404
|
+
if (typeof total.amount !== 'number' || !Number.isSafeInteger(total.amount)) {
|
|
405
|
+
throw new MoneyError(MoneyErrorCode.NotInteger, `total must be a whole number of minor units, got ${String(total.amount)}`);
|
|
406
|
+
}
|
|
407
|
+
if (!isVatPercent(vatPercent)) {
|
|
408
|
+
throw new MoneyError(MoneyErrorCode.OutOfRange, `VAT must be 0–${MAX_VAT_PERCENT} with at most ${VAT_PERCENT_MAX_DECIMALS} decimals, got ${String(vatPercent)}`);
|
|
409
|
+
}
|
|
410
|
+
const decimal = parseDecimal(String(vatPercent));
|
|
411
|
+
const scale = decimal.frac.length;
|
|
412
|
+
const rate = decimalToScaledInteger(decimal, scale, DecimalRounding.Exact);
|
|
413
|
+
const magnitude = Math.abs(total.amount);
|
|
414
|
+
if (magnitude > Number.MAX_SAFE_INTEGER / 2) {
|
|
415
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Amount is beyond the range VAT is computed for');
|
|
416
|
+
}
|
|
417
|
+
const share = mulDivHalfEven(magnitude, rate, 100 * 10 ** scale + rate);
|
|
418
|
+
return { amount: total.amount < 0 && share !== 0 ? -share : share, currency: total.currency };
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** The storefront's stock word (iox-cms `storefront-projection.ts` speaks the same values). */
|
|
422
|
+
var Availability;
|
|
423
|
+
(function (Availability) {
|
|
424
|
+
Availability["InStock"] = "in_stock";
|
|
425
|
+
Availability["Low"] = "low";
|
|
426
|
+
Availability["Out"] = "out";
|
|
427
|
+
})(Availability || (Availability = {}));
|
|
428
|
+
/** How many units may be sold: the count, else 0 for `out` or nothing known, else null = unbounded here (the server checks the count). */
|
|
429
|
+
function sellableQuantity(entry) {
|
|
430
|
+
if (typeof entry.stock === 'number')
|
|
431
|
+
return Number.isSafeInteger(entry.stock) && entry.stock > 0 ? entry.stock : 0;
|
|
432
|
+
if (entry.availability === Availability.InStock || entry.availability === Availability.Low)
|
|
433
|
+
return null;
|
|
434
|
+
return 0;
|
|
435
|
+
}
|
|
436
|
+
const catalogKey = (productId, variantId) => `${productId}\u0000${variantId ?? ''}`;
|
|
437
|
+
|
|
438
|
+
const filled = (value) => typeof value === 'string' && value.trim() !== '';
|
|
439
|
+
const looksLikeEmail = (value) => filled(value) && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value.trim());
|
|
440
|
+
const digitsOf = (value) => (typeof value === 'string' ? value.replace(/\D/g, '') : '');
|
|
441
|
+
/** A phone a person can be called on: 7–15 digits once spaces, dashes, brackets and a leading + are dropped. */
|
|
442
|
+
const looksLikePhone = (value) => filled(value) && /^\+?[\d\s\-().]+$/.test(value.trim()) && digitsOf(value).length >= 7 && digitsOf(value).length <= 15;
|
|
443
|
+
/** An Israeli mobile number (Bit sends to one): 05X-XXXXXXX, or +972 5X-XXXXXXX. */
|
|
444
|
+
const looksLikeIsraeliMobile = (value) => filled(value) && /^\+?[\d\s\-().]+$/.test(value.trim()) && /^(?:9725|05)\d{8}$/.test(digitsOf(value));
|
|
445
|
+
|
|
446
|
+
/** Shipping v1 (C-D9): methods per studio, one country. Zones and weights come later. */
|
|
447
|
+
var ShippingMethodKind;
|
|
448
|
+
(function (ShippingMethodKind) {
|
|
449
|
+
ShippingMethodKind["Pickup"] = "pickup";
|
|
450
|
+
ShippingMethodKind["Flat"] = "flat";
|
|
451
|
+
/** A flat price that becomes free once the goods reach `freeOver`. */
|
|
452
|
+
ShippingMethodKind["FreeOver"] = "freeOver";
|
|
453
|
+
/** No address, nothing shipped — offered only when nothing in the cart ships. */
|
|
454
|
+
ShippingMethodKind["Digital"] = "digital";
|
|
455
|
+
})(ShippingMethodKind || (ShippingMethodKind = {}));
|
|
456
|
+
/** What an owner must fill for a method of a kind. */
|
|
457
|
+
var ShippingField;
|
|
458
|
+
(function (ShippingField) {
|
|
459
|
+
ShippingField["Price"] = "price";
|
|
460
|
+
ShippingField["FreeOver"] = "freeOver";
|
|
461
|
+
ShippingField["PickupAddress"] = "pickupAddress";
|
|
462
|
+
})(ShippingField || (ShippingField = {}));
|
|
463
|
+
const zero = (goods) => money(0, goods.currency);
|
|
464
|
+
const SHIPPING_KINDS = Object.freeze({
|
|
465
|
+
[ShippingMethodKind.Pickup]: {
|
|
466
|
+
needsAddress: false,
|
|
467
|
+
forPhysical: true,
|
|
468
|
+
requires: [ShippingField.PickupAddress],
|
|
469
|
+
price: (_method, goods) => zero(goods),
|
|
470
|
+
label: { en: 'Pickup', he: 'איסוף עצמי' },
|
|
471
|
+
},
|
|
472
|
+
[ShippingMethodKind.Flat]: {
|
|
473
|
+
needsAddress: true,
|
|
474
|
+
forPhysical: true,
|
|
475
|
+
requires: [ShippingField.Price],
|
|
476
|
+
price: (method) => method.price,
|
|
477
|
+
label: { en: 'Flat-rate delivery', he: 'משלוח במחיר קבוע' },
|
|
478
|
+
},
|
|
479
|
+
[ShippingMethodKind.FreeOver]: {
|
|
480
|
+
needsAddress: true,
|
|
481
|
+
forPhysical: true,
|
|
482
|
+
requires: [ShippingField.Price, ShippingField.FreeOver],
|
|
483
|
+
price: (method, goods) => goods.amount >= method.freeOver.amount ? zero(goods) : method.price,
|
|
484
|
+
label: { en: 'Delivery, free over an amount', he: 'משלוח, חינם מעל סכום' },
|
|
485
|
+
},
|
|
486
|
+
[ShippingMethodKind.Digital]: {
|
|
487
|
+
needsAddress: false,
|
|
488
|
+
forPhysical: false,
|
|
489
|
+
requires: [],
|
|
490
|
+
price: (_method, goods) => zero(goods),
|
|
491
|
+
label: { en: 'Digital — nothing shipped', he: 'דיגיטלי — ללא משלוח' },
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
const validAmount = (value, currency) => isMoney(value) && value.currency === currency && value.amount >= 0 && value.amount <= MAX_CART_AMOUNT;
|
|
495
|
+
const SHIPPING_FIELD_CHECKS = Object.freeze({
|
|
496
|
+
[ShippingField.Price]: (method, currency) => validAmount(method.price, currency),
|
|
497
|
+
[ShippingField.FreeOver]: (method, currency) => validAmount(method.freeOver, currency),
|
|
498
|
+
[ShippingField.PickupAddress]: (method) => filled(method.pickupAddress),
|
|
499
|
+
});
|
|
500
|
+
const isShippingMethodKind = (value) => typeof value === 'string' && Object.prototype.hasOwnProperty.call(SHIPPING_KINDS, value);
|
|
501
|
+
function shippingNeedsAddress(kind) {
|
|
502
|
+
return isShippingMethodKind(kind) && SHIPPING_KINDS[kind].needsAddress;
|
|
503
|
+
}
|
|
504
|
+
/** The fields a method lacks (or holds in another currency) — empty = it can be offered. */
|
|
505
|
+
function shippingMethodProblems(method, currency) {
|
|
506
|
+
if (!method || !isShippingMethodKind(method.kind))
|
|
507
|
+
return [ShippingField.Price];
|
|
508
|
+
return SHIPPING_KINDS[method.kind].requires.filter(field => !SHIPPING_FIELD_CHECKS[field](method, currency));
|
|
509
|
+
}
|
|
510
|
+
/** Enabled, complete, with an id and a name: the ONE rule both the offer and the checkout gate read. */
|
|
511
|
+
function shippingMethodReady(method, currency) {
|
|
512
|
+
return !!method && method.enabled === true && filled(method.id) && filled(method.name)
|
|
513
|
+
&& shippingMethodProblems(method, currency).length === 0;
|
|
514
|
+
}
|
|
515
|
+
function quoteShipping(methods, cart) {
|
|
516
|
+
const list = Array.isArray(methods) ? methods : [];
|
|
517
|
+
if (!cart.lineCount)
|
|
518
|
+
return [];
|
|
519
|
+
const seen = new Set();
|
|
520
|
+
return list
|
|
521
|
+
.filter(method => shippingMethodReady(method, cart.currency)
|
|
522
|
+
&& SHIPPING_KINDS[method.kind].forPhysical === cart.requiresShipping
|
|
523
|
+
&& !seen.has(method.id) && !!seen.add(method.id))
|
|
524
|
+
.map(method => {
|
|
525
|
+
const rule = SHIPPING_KINDS[method.kind];
|
|
526
|
+
const price = rule.price(method, cart.goods);
|
|
527
|
+
return {
|
|
528
|
+
methodId: method.id,
|
|
529
|
+
kind: method.kind,
|
|
530
|
+
name: method.name,
|
|
531
|
+
price: money(price.amount, price.currency),
|
|
532
|
+
free: method.kind === ShippingMethodKind.FreeOver && price.amount === 0,
|
|
533
|
+
needsAddress: rule.needsAddress,
|
|
534
|
+
};
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* The methods a buyer may choose for this cart, each priced for it (free over: free when the goods after
|
|
539
|
+
* discounts are AT or above the threshold). A cart where nothing ships is offered Digital methods only; a cart
|
|
540
|
+
* where anything ships never is.
|
|
541
|
+
*/
|
|
542
|
+
function availableShippingMethods(methods, pricedCart) {
|
|
543
|
+
return quoteShipping(methods, {
|
|
544
|
+
currency: pricedCart.currency,
|
|
545
|
+
goods: subtractMoney(pricedCart.subtotal, pricedCart.discount),
|
|
546
|
+
requiresShipping: pricedCart.requiresShipping,
|
|
547
|
+
lineCount: pricedCart.lines.length,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
var CartIssueCode;
|
|
552
|
+
(function (CartIssueCode) {
|
|
553
|
+
/** Not a whole number ≥ 1: the line is dropped. */
|
|
554
|
+
CartIssueCode["InvalidQuantity"] = "invalid-quantity";
|
|
555
|
+
/** The same product and variant twice: merged into the first. */
|
|
556
|
+
CartIssueCode["DuplicateLine"] = "duplicate-line";
|
|
557
|
+
CartIssueCode["TooManyLines"] = "too-many-lines";
|
|
558
|
+
CartIssueCode["QuantityCapped"] = "quantity-capped";
|
|
559
|
+
CartIssueCode["UnknownProduct"] = "unknown-product";
|
|
560
|
+
/** The product exists, this variant does not (or the product needs a variant chosen). */
|
|
561
|
+
CartIssueCode["UnknownVariant"] = "unknown-variant";
|
|
562
|
+
CartIssueCode["Unpublished"] = "unpublished";
|
|
563
|
+
CartIssueCode["VariantDisabled"] = "variant-disabled";
|
|
564
|
+
CartIssueCode["NoPrice"] = "no-price";
|
|
565
|
+
CartIssueCode["CurrencyMismatch"] = "currency-mismatch";
|
|
566
|
+
CartIssueCode["OutOfStock"] = "out-of-stock";
|
|
567
|
+
/** Fewer left than asked: the line keeps what is left. */
|
|
568
|
+
CartIssueCode["QuantityClamped"] = "quantity-clamped";
|
|
569
|
+
/** The line would push the subtotal past `MAX_CART_AMOUNT`: dropped. */
|
|
570
|
+
CartIssueCode["AmountTooLarge"] = "amount-too-large";
|
|
571
|
+
/** The chosen shipping method is not offered for this cart: no shipping is priced. */
|
|
572
|
+
CartIssueCode["ShippingUnavailable"] = "shipping-unavailable";
|
|
573
|
+
/** The studio's VAT is not a usable rate: the VAT line reads 0. */
|
|
574
|
+
CartIssueCode["VatInvalid"] = "vat-invalid";
|
|
575
|
+
})(CartIssueCode || (CartIssueCode = {}));
|
|
576
|
+
const CART_ISSUE_LABELS = Object.freeze({
|
|
577
|
+
[CartIssueCode.InvalidQuantity]: { en: 'A quantity was not a whole number, so the item was removed.', he: 'כמות שאינה מספר שלם — הפריט הוסר.' },
|
|
578
|
+
[CartIssueCode.DuplicateLine]: { en: 'The same item appeared twice and was combined.', he: 'אותו פריט הופיע פעמיים ואוחד.' },
|
|
579
|
+
[CartIssueCode.TooManyLines]: { en: 'Your cart has too many different items; the last ones were removed.', he: 'יש בעגלה יותר מדי פריטים שונים; האחרונים הוסרו.' },
|
|
580
|
+
[CartIssueCode.QuantityCapped]: { en: 'That is more than one order can hold; the quantity was lowered.', he: 'הכמות גדולה מהמותר בהזמנה אחת, והיא הוקטנה.' },
|
|
581
|
+
[CartIssueCode.UnknownProduct]: { en: 'An item is no longer sold and was removed.', he: 'פריט כבר לא נמכר והוסר.' },
|
|
582
|
+
[CartIssueCode.UnknownVariant]: { en: 'An option of an item is no longer sold and was removed.', he: 'אפשרות של פריט כבר לא נמכרת והוסרה.' },
|
|
583
|
+
[CartIssueCode.Unpublished]: { en: 'An item is not on sale right now and was removed.', he: 'פריט אינו למכירה כרגע והוסר.' },
|
|
584
|
+
[CartIssueCode.VariantDisabled]: { en: 'An option of an item is not available and was removed.', he: 'אפשרות של פריט אינה זמינה והוסרה.' },
|
|
585
|
+
[CartIssueCode.NoPrice]: { en: 'An item has no price yet and was removed.', he: 'לפריט עדיין אין מחיר, והוא הוסר.' },
|
|
586
|
+
[CartIssueCode.CurrencyMismatch]: { en: 'An item is priced in another currency and was removed.', he: 'פריט מתומחר במטבע אחר והוסר.' },
|
|
587
|
+
[CartIssueCode.OutOfStock]: { en: 'An item is out of stock and was removed.', he: 'פריט אזל מהמלאי והוסר.' },
|
|
588
|
+
[CartIssueCode.QuantityClamped]: { en: 'Fewer are left than you asked for; your cart holds what is left.', he: 'נשארו פחות ממה שביקשתם; בעגלה מה שנשאר.' },
|
|
589
|
+
[CartIssueCode.AmountTooLarge]: { en: 'The order is too large; an item was removed.', he: 'ההזמנה גדולה מדי; פריט הוסר.' },
|
|
590
|
+
[CartIssueCode.ShippingUnavailable]: { en: 'That delivery method is not available for this order. Choose another.', he: 'שיטת המשלוח הזו אינה זמינה להזמנה. בחרו אחרת.' },
|
|
591
|
+
[CartIssueCode.VatInvalid]: { en: 'The shop\'s VAT rate is not set correctly.', he: 'שיעור המע"מ של החנות אינו מוגדר כראוי.' },
|
|
592
|
+
});
|
|
593
|
+
/** Checked in order; the first that refuses drops the line. */
|
|
594
|
+
const LINE_REFUSALS = Object.freeze([
|
|
595
|
+
{ code: CartIssueCode.Unpublished, refuses: (entry) => entry.published !== true },
|
|
596
|
+
{ code: CartIssueCode.VariantDisabled, refuses: (entry) => entry.enabled !== true },
|
|
597
|
+
{ code: CartIssueCode.NoPrice, refuses: (entry) => !isMoney(entry.unitPrice) || entry.unitPrice.amount < 0 },
|
|
598
|
+
{ code: CartIssueCode.CurrencyMismatch, refuses: (entry, currency) => entry.unitPrice.currency !== currency },
|
|
599
|
+
{ code: CartIssueCode.OutOfStock, refuses: (entry) => sellableQuantity(entry) === 0 },
|
|
600
|
+
]);
|
|
601
|
+
const isText = (value) => typeof value === 'string' && value !== '';
|
|
602
|
+
const variantOf = (line) => (isText(line.variantId) ? line.variantId : null);
|
|
603
|
+
const validQuantity = (quantity) => typeof quantity === 'number' && Number.isSafeInteger(quantity) && quantity >= 1;
|
|
604
|
+
/** Drops malformed lines, merges duplicates, keeps the first `MAX_CART_LINES` distinct ones. */
|
|
605
|
+
function wantedLines(cart, issues) {
|
|
606
|
+
const lines = cart && Array.isArray(cart.lines) ? cart.lines : [];
|
|
607
|
+
const byKey = new Map();
|
|
608
|
+
for (const line of lines) {
|
|
609
|
+
const productId = line && isText(line.productId) ? line.productId : '';
|
|
610
|
+
const variantId = line ? variantOf(line) : null;
|
|
611
|
+
if (!productId) {
|
|
612
|
+
issues.push({ code: CartIssueCode.UnknownProduct });
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
if (!validQuantity(line.quantity)) {
|
|
616
|
+
issues.push({ code: CartIssueCode.InvalidQuantity, productId, variantId });
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
const key = catalogKey(productId, variantId);
|
|
620
|
+
const same = byKey.get(key);
|
|
621
|
+
if (same) {
|
|
622
|
+
same.quantity = Math.min(same.quantity + line.quantity, Number.MAX_SAFE_INTEGER);
|
|
623
|
+
issues.push({ code: CartIssueCode.DuplicateLine, productId, variantId });
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
if (byKey.size >= MAX_CART_LINES) {
|
|
627
|
+
issues.push({ code: CartIssueCode.TooManyLines, productId, variantId });
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
byKey.set(key, { productId, variantId, quantity: line.quantity });
|
|
631
|
+
}
|
|
632
|
+
return [...byKey.values()];
|
|
633
|
+
}
|
|
634
|
+
function indexCatalog(catalog) {
|
|
635
|
+
const entries = new Map();
|
|
636
|
+
const products = new Set();
|
|
637
|
+
const list = Array.isArray(catalog) ? catalog : [];
|
|
638
|
+
for (const entry of list) {
|
|
639
|
+
if (!entry || !isText(entry.productId))
|
|
640
|
+
continue;
|
|
641
|
+
products.add(entry.productId);
|
|
642
|
+
const key = catalogKey(entry.productId, isText(entry.variantId) ? entry.variantId : null);
|
|
643
|
+
if (!entries.has(key))
|
|
644
|
+
entries.set(key, entry);
|
|
645
|
+
}
|
|
646
|
+
return { entries, products };
|
|
647
|
+
}
|
|
648
|
+
const compareAtOf = (entry, unitPrice) => isMoney(entry.compareAt) && entry.compareAt.currency === unitPrice.currency && entry.compareAt.amount > unitPrice.amount
|
|
649
|
+
? money(entry.compareAt.amount, entry.compareAt.currency)
|
|
650
|
+
: null;
|
|
651
|
+
function lineTotalWithin(unitPrice, quantity, subtotal) {
|
|
652
|
+
try {
|
|
653
|
+
const lineTotal = timesMoney(unitPrice, quantity);
|
|
654
|
+
return subtotal.amount + lineTotal.amount <= MAX_CART_AMOUNT ? lineTotal : null;
|
|
655
|
+
}
|
|
656
|
+
catch {
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* THE pricing function (C-D7, trap T1): the engine shows its result, iox-cms recomputes it at checkout and at
|
|
662
|
+
* payment. Prices come from the catalog only — a cart line carries no number but a quantity. Every money value
|
|
663
|
+
* out is whole minor units in the studio currency. An unusable line is dropped or adjusted and SAID in `issues`.
|
|
664
|
+
*/
|
|
665
|
+
function priceCart(cart, catalog, studio, choice) {
|
|
666
|
+
const currency = studio.currency;
|
|
667
|
+
currencyExponent(currency);
|
|
668
|
+
const issues = [];
|
|
669
|
+
const { entries, products } = indexCatalog(catalog);
|
|
670
|
+
const lines = [];
|
|
671
|
+
let subtotal = money(0, currency);
|
|
672
|
+
for (const wanted of wantedLines(cart, issues)) {
|
|
673
|
+
const { productId, variantId } = wanted;
|
|
674
|
+
const entry = entries.get(catalogKey(productId, variantId));
|
|
675
|
+
if (!entry) {
|
|
676
|
+
issues.push({ code: products.has(productId) ? CartIssueCode.UnknownVariant : CartIssueCode.UnknownProduct, productId, variantId });
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
const refusal = LINE_REFUSALS.find(rule => rule.refuses(entry, currency));
|
|
680
|
+
if (refusal) {
|
|
681
|
+
issues.push({ code: refusal.code, productId, variantId, requested: wanted.quantity });
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
let quantity = wanted.quantity;
|
|
685
|
+
if (quantity > MAX_LINE_QUANTITY) {
|
|
686
|
+
quantity = MAX_LINE_QUANTITY;
|
|
687
|
+
issues.push({ code: CartIssueCode.QuantityCapped, productId, variantId, requested: wanted.quantity, quantity });
|
|
688
|
+
}
|
|
689
|
+
const left = sellableQuantity(entry);
|
|
690
|
+
if (left !== null && quantity > left) {
|
|
691
|
+
const requested = quantity;
|
|
692
|
+
quantity = left;
|
|
693
|
+
issues.push({ code: CartIssueCode.QuantityClamped, productId, variantId, requested, quantity });
|
|
694
|
+
}
|
|
695
|
+
const unitPrice = money(entry.unitPrice.amount, currency);
|
|
696
|
+
const lineTotal = lineTotalWithin(unitPrice, quantity, subtotal);
|
|
697
|
+
if (!lineTotal) {
|
|
698
|
+
issues.push({ code: CartIssueCode.AmountTooLarge, productId, variantId, requested: wanted.quantity });
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
subtotal = addMoney(subtotal, lineTotal);
|
|
702
|
+
lines.push({
|
|
703
|
+
productId,
|
|
704
|
+
variantId,
|
|
705
|
+
title: String(entry.title ?? ''),
|
|
706
|
+
variantName: isText(entry.variantName) ? entry.variantName : null,
|
|
707
|
+
quantity,
|
|
708
|
+
unitPrice,
|
|
709
|
+
compareAt: compareAtOf(entry, unitPrice),
|
|
710
|
+
lineTotal,
|
|
711
|
+
requiresShipping: entry.requiresShipping !== false,
|
|
712
|
+
image: isText(entry.image) ? entry.image : null,
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
const discount = money(0, currency);
|
|
716
|
+
const goods = subtractMoney(subtotal, discount);
|
|
717
|
+
const requiresShipping = lines.some(line => line.requiresShipping);
|
|
718
|
+
const chosenId = choice && isText(choice.shippingMethodId) ? choice.shippingMethodId : null;
|
|
719
|
+
const quotes = chosenId ? quoteShipping(studio.shippingMethods, { currency, goods, requiresShipping, lineCount: lines.length }) : [];
|
|
720
|
+
const shippingMethod = chosenId ? quotes.find(quote => quote.methodId === chosenId) ?? null : null;
|
|
721
|
+
if (chosenId && !shippingMethod)
|
|
722
|
+
issues.push({ code: CartIssueCode.ShippingUnavailable, shippingMethodId: chosenId });
|
|
723
|
+
const shipping = shippingMethod ? shippingMethod.price : money(0, currency);
|
|
724
|
+
const total = addMoney(goods, shipping);
|
|
725
|
+
const vatUsable = isVatPercent(studio.vatPercent);
|
|
726
|
+
if (!vatUsable)
|
|
727
|
+
issues.push({ code: CartIssueCode.VatInvalid });
|
|
728
|
+
return {
|
|
729
|
+
currency,
|
|
730
|
+
lines,
|
|
731
|
+
subtotal,
|
|
732
|
+
discount,
|
|
733
|
+
shipping,
|
|
734
|
+
shippingMethod,
|
|
735
|
+
requiresShipping,
|
|
736
|
+
total,
|
|
737
|
+
vat: vatUsable ? includedVat(total, studio.vatPercent) : money(0, currency),
|
|
738
|
+
vatPercent: vatUsable ? studio.vatPercent : 0,
|
|
739
|
+
issues,
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
/** The cart a priced cart stands for — what to store back once the buyer has seen the issues. */
|
|
743
|
+
function cartOf(priced) {
|
|
744
|
+
return { lines: priced.lines.map(line => ({ productId: line.productId, variantId: line.variantId, quantity: line.quantity })) };
|
|
745
|
+
}
|
|
746
|
+
/** Sign-in merge (E3): b's lines join a's; the same product and variant add up. priceCart caps and clamps later. */
|
|
747
|
+
function mergeCarts(a, b) {
|
|
748
|
+
const merged = [];
|
|
749
|
+
const byKey = new Map();
|
|
750
|
+
const all = [...(Array.isArray(a?.lines) ? a.lines : []), ...(Array.isArray(b?.lines) ? b.lines : [])];
|
|
751
|
+
for (const line of all.filter(each => !!each && isText(each.productId))) {
|
|
752
|
+
const key = catalogKey(line.productId, variantOf(line));
|
|
753
|
+
const same = byKey.get(key);
|
|
754
|
+
if (same && validQuantity(same.quantity) && validQuantity(line.quantity)) {
|
|
755
|
+
same.quantity = Math.min(same.quantity + line.quantity, Number.MAX_SAFE_INTEGER);
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
const copy = { productId: line.productId, variantId: variantOf(line), quantity: line.quantity };
|
|
759
|
+
if (!same)
|
|
760
|
+
byKey.set(key, copy);
|
|
761
|
+
merged.push(copy);
|
|
762
|
+
}
|
|
763
|
+
return { lines: merged };
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
var PaymentChannel;
|
|
767
|
+
(function (PaymentChannel) {
|
|
768
|
+
/** The owner marks the order paid (C-D11). */
|
|
769
|
+
PaymentChannel["Manual"] = "manual";
|
|
770
|
+
/** The studio's PSP; only its verified callback marks the order paid. */
|
|
771
|
+
PaymentChannel["Online"] = "online";
|
|
772
|
+
})(PaymentChannel || (PaymentChannel = {}));
|
|
773
|
+
var PaymentMethodKind;
|
|
774
|
+
(function (PaymentMethodKind) {
|
|
775
|
+
PaymentMethodKind["BankTransfer"] = "bankTransfer";
|
|
776
|
+
PaymentMethodKind["PayOnPickup"] = "payOnPickup";
|
|
777
|
+
PaymentMethodKind["CashOnDelivery"] = "cashOnDelivery";
|
|
778
|
+
PaymentMethodKind["Bit"] = "bit";
|
|
779
|
+
/** A PSP's hosted page (E2, Cardcom first) — typed now, not offered yet. */
|
|
780
|
+
PaymentMethodKind["Online"] = "online";
|
|
781
|
+
})(PaymentMethodKind || (PaymentMethodKind = {}));
|
|
782
|
+
var PaymentProvider;
|
|
783
|
+
(function (PaymentProvider) {
|
|
784
|
+
PaymentProvider["Cardcom"] = "cardcom";
|
|
785
|
+
})(PaymentProvider || (PaymentProvider = {}));
|
|
786
|
+
/** What an owner fills for a method. */
|
|
787
|
+
var PaymentField;
|
|
788
|
+
(function (PaymentField) {
|
|
789
|
+
PaymentField["AccountName"] = "accountName";
|
|
790
|
+
PaymentField["Bank"] = "bank";
|
|
791
|
+
PaymentField["Branch"] = "branch";
|
|
792
|
+
PaymentField["AccountNumber"] = "accountNumber";
|
|
793
|
+
PaymentField["BitPhone"] = "bitPhone";
|
|
794
|
+
PaymentField["Provider"] = "provider";
|
|
795
|
+
})(PaymentField || (PaymentField = {}));
|
|
796
|
+
/** Which deliveries a method can be used with. */
|
|
797
|
+
var DeliveryFit;
|
|
798
|
+
(function (DeliveryFit) {
|
|
799
|
+
DeliveryFit["Any"] = "any";
|
|
800
|
+
/** Paid at the counter: only with a pickup method. */
|
|
801
|
+
DeliveryFit["PickupOnly"] = "pickupOnly";
|
|
802
|
+
/** Paid to the courier: only with a method that delivers to an address. */
|
|
803
|
+
DeliveryFit["AddressOnly"] = "addressOnly";
|
|
804
|
+
})(DeliveryFit || (DeliveryFit = {}));
|
|
805
|
+
const PAYMENT_METHODS = Object.freeze({
|
|
806
|
+
[PaymentMethodKind.BankTransfer]: {
|
|
807
|
+
channel: PaymentChannel.Manual,
|
|
808
|
+
offered: true,
|
|
809
|
+
fields: [PaymentField.AccountName, PaymentField.Bank, PaymentField.Branch, PaymentField.AccountNumber],
|
|
810
|
+
fit: DeliveryFit.Any,
|
|
811
|
+
label: { en: 'Bank transfer', he: 'העברה בנקאית' },
|
|
812
|
+
instructions: {
|
|
813
|
+
en: 'Transfer {total} to {accountName}, bank {bank}, branch {branch}, account {accountNumber}. Write order {orderNumber} in the transfer\'s reference. We will confirm your order once the money arrives.',
|
|
814
|
+
he: 'העבירו {total} לחשבון על שם {accountName}, בנק {bank}, סניף {branch}, חשבון {accountNumber}. ציינו את מספר ההזמנה {orderNumber} בפרטי ההעברה. נאשר את ההזמנה כשהכסף יגיע.',
|
|
815
|
+
},
|
|
816
|
+
},
|
|
817
|
+
[PaymentMethodKind.PayOnPickup]: {
|
|
818
|
+
channel: PaymentChannel.Manual,
|
|
819
|
+
offered: true,
|
|
820
|
+
fields: [],
|
|
821
|
+
fit: DeliveryFit.PickupOnly,
|
|
822
|
+
label: { en: 'Pay on pickup', he: 'תשלום באיסוף' },
|
|
823
|
+
instructions: {
|
|
824
|
+
en: 'Pay {total} when you pick up order {orderNumber}.',
|
|
825
|
+
he: 'שלמו {total} כשאתם אוספים את הזמנה {orderNumber}.',
|
|
826
|
+
},
|
|
827
|
+
},
|
|
828
|
+
[PaymentMethodKind.CashOnDelivery]: {
|
|
829
|
+
channel: PaymentChannel.Manual,
|
|
830
|
+
offered: true,
|
|
831
|
+
fields: [],
|
|
832
|
+
fit: DeliveryFit.AddressOnly,
|
|
833
|
+
label: { en: 'Cash on delivery', he: 'מזומן במסירה' },
|
|
834
|
+
instructions: {
|
|
835
|
+
en: 'Pay {total} in cash when order {orderNumber} is delivered.',
|
|
836
|
+
he: 'שלמו {total} במזומן כשהזמנה {orderNumber} נמסרת לכם.',
|
|
837
|
+
},
|
|
838
|
+
},
|
|
839
|
+
[PaymentMethodKind.Bit]: {
|
|
840
|
+
channel: PaymentChannel.Manual,
|
|
841
|
+
offered: true,
|
|
842
|
+
fields: [PaymentField.BitPhone],
|
|
843
|
+
fit: DeliveryFit.Any,
|
|
844
|
+
label: { en: 'Bit', he: 'ביט' },
|
|
845
|
+
instructions: {
|
|
846
|
+
en: 'Send {total} with Bit to {bitPhone}. Write order {orderNumber} in the note. We will confirm your order once the payment arrives.',
|
|
847
|
+
he: 'שלחו {total} בביט למספר {bitPhone}. ציינו את מספר ההזמנה {orderNumber} בהערה. נאשר את ההזמנה כשהתשלום יגיע.',
|
|
848
|
+
},
|
|
849
|
+
},
|
|
850
|
+
[PaymentMethodKind.Online]: {
|
|
851
|
+
channel: PaymentChannel.Online,
|
|
852
|
+
offered: false,
|
|
853
|
+
fields: [PaymentField.Provider],
|
|
854
|
+
fit: DeliveryFit.Any,
|
|
855
|
+
label: { en: 'Card', he: 'כרטיס אשראי' },
|
|
856
|
+
instructions: {
|
|
857
|
+
en: 'You will pay {total} for order {orderNumber} on a secure payment page.',
|
|
858
|
+
he: 'תשלמו {total} עבור הזמנה {orderNumber} בעמוד תשלום מאובטח.',
|
|
859
|
+
},
|
|
860
|
+
},
|
|
861
|
+
});
|
|
862
|
+
const PAYMENT_FIELD_LABELS = Object.freeze({
|
|
863
|
+
[PaymentField.AccountName]: { en: 'Account holder', he: 'שם בעל החשבון' },
|
|
864
|
+
[PaymentField.Bank]: { en: 'Bank', he: 'בנק' },
|
|
865
|
+
[PaymentField.Branch]: { en: 'Branch', he: 'סניף' },
|
|
866
|
+
[PaymentField.AccountNumber]: { en: 'Account number', he: 'מספר חשבון' },
|
|
867
|
+
[PaymentField.BitPhone]: { en: 'Phone number for Bit', he: 'מספר טלפון לביט' },
|
|
868
|
+
[PaymentField.Provider]: { en: 'Payment provider', he: 'ספק סליקה' },
|
|
869
|
+
});
|
|
870
|
+
const isPaymentProvider = (value) => typeof value === 'string' && Object.values(PaymentProvider).includes(value);
|
|
871
|
+
const PAYMENT_FIELD_CHECKS = Object.freeze({
|
|
872
|
+
[PaymentField.AccountName]: filled,
|
|
873
|
+
[PaymentField.Bank]: filled,
|
|
874
|
+
[PaymentField.Branch]: filled,
|
|
875
|
+
[PaymentField.AccountNumber]: filled,
|
|
876
|
+
[PaymentField.BitPhone]: looksLikeIsraeliMobile,
|
|
877
|
+
[PaymentField.Provider]: isPaymentProvider,
|
|
878
|
+
});
|
|
879
|
+
const DELIVERY_FITS = Object.freeze({
|
|
880
|
+
[DeliveryFit.Any]: () => true,
|
|
881
|
+
[DeliveryFit.PickupOnly]: (kind) => kind === ShippingMethodKind.Pickup,
|
|
882
|
+
[DeliveryFit.AddressOnly]: (kind) => !!kind && isShippingMethodKind(kind) && SHIPPING_KINDS[kind].needsAddress,
|
|
883
|
+
});
|
|
884
|
+
const isPaymentMethodKind = (value) => typeof value === 'string' && Object.prototype.hasOwnProperty.call(PAYMENT_METHODS, value);
|
|
885
|
+
function paymentChannelOf(kind) {
|
|
886
|
+
return PAYMENT_METHODS[kind].channel;
|
|
887
|
+
}
|
|
888
|
+
/** The fields a method lacks or holds in a form it cannot be paid with. */
|
|
889
|
+
function paymentMethodProblems(config) {
|
|
890
|
+
if (!config || !isPaymentMethodKind(config.kind))
|
|
891
|
+
return [];
|
|
892
|
+
const details = config.details ?? {};
|
|
893
|
+
return PAYMENT_METHODS[config.kind].fields.filter(field => !PAYMENT_FIELD_CHECKS[field](details[field]));
|
|
894
|
+
}
|
|
895
|
+
/** Enabled, offered in this phase, complete: the ONE rule the checkout and its gate read. */
|
|
896
|
+
function paymentMethodReady(config) {
|
|
897
|
+
return !!config && isPaymentMethodKind(config.kind) && config.enabled === true
|
|
898
|
+
&& PAYMENT_METHODS[config.kind].offered && paymentMethodProblems(config).length === 0;
|
|
899
|
+
}
|
|
900
|
+
/** The methods a buyer may pick with this delivery (null = nothing ships). */
|
|
901
|
+
function usablePaymentMethods(configs, shippingKind) {
|
|
902
|
+
const seen = new Set();
|
|
903
|
+
const list = Array.isArray(configs) ? configs : [];
|
|
904
|
+
return list.filter(config => paymentMethodReady(config)
|
|
905
|
+
&& DELIVERY_FITS[PAYMENT_METHODS[config.kind].fit](shippingKind ?? null)
|
|
906
|
+
&& !seen.has(config.kind) && !!seen.add(config.kind));
|
|
907
|
+
}
|
|
908
|
+
const LOCALES = Object.freeze({ [CommerceLanguage.En]: 'en-US', [CommerceLanguage.He]: 'he-IL' });
|
|
909
|
+
/** What the buyer is told to do, in their language: the method's sentence with the order, the amount and the owner's details, then the owner's note. */
|
|
910
|
+
function paymentInstructions(config, order, lang, locale) {
|
|
911
|
+
const rule = PAYMENT_METHODS[config.kind];
|
|
912
|
+
const values = {
|
|
913
|
+
...(config.details ?? {}),
|
|
914
|
+
orderNumber: order.orderNumber,
|
|
915
|
+
total: formatMoney(order.total, locale ?? LOCALES[commerceLanguage(lang)]),
|
|
916
|
+
};
|
|
917
|
+
const sentence = labelIn(rule.instructions, lang).replace(/\{(\w+)\}/g, (_match, name) => values[name] ?? '');
|
|
918
|
+
return filled(config.note) ? `${sentence}\n${config.note.trim()}` : sentence;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/** C-D11 — the order's closed states. */
|
|
922
|
+
var OrderState;
|
|
923
|
+
(function (OrderState) {
|
|
924
|
+
/** A manual method: waiting for the owner to see the money. */
|
|
925
|
+
OrderState["AwaitingPayment"] = "awaiting_payment";
|
|
926
|
+
/** An online method: the PSP's page is open. */
|
|
927
|
+
OrderState["PendingPayment"] = "pending_payment";
|
|
928
|
+
OrderState["Paid"] = "paid";
|
|
929
|
+
OrderState["Fulfilled"] = "fulfilled";
|
|
930
|
+
OrderState["Delivered"] = "delivered";
|
|
931
|
+
OrderState["Cancelled"] = "cancelled";
|
|
932
|
+
OrderState["PaymentFailed"] = "payment_failed";
|
|
933
|
+
OrderState["Refunded"] = "refunded";
|
|
934
|
+
OrderState["PartiallyRefunded"] = "partially_refunded";
|
|
935
|
+
})(OrderState || (OrderState = {}));
|
|
936
|
+
var OrderEvent;
|
|
937
|
+
(function (OrderEvent) {
|
|
938
|
+
/** The buyer tries to pay again after a failure. */
|
|
939
|
+
OrderEvent["StartPayment"] = "startPayment";
|
|
940
|
+
/** The PSP's verified callback says paid. */
|
|
941
|
+
OrderEvent["ConfirmPayment"] = "confirmPayment";
|
|
942
|
+
OrderEvent["FailPayment"] = "failPayment";
|
|
943
|
+
/** The owner saw the money of a manual method. */
|
|
944
|
+
OrderEvent["MarkPaid"] = "markPaid";
|
|
945
|
+
OrderEvent["Fulfil"] = "fulfil";
|
|
946
|
+
OrderEvent["Deliver"] = "deliver";
|
|
947
|
+
OrderEvent["Cancel"] = "cancel";
|
|
948
|
+
/** Nobody paid in time (the jobs runner). */
|
|
949
|
+
OrderEvent["Expire"] = "expire";
|
|
950
|
+
OrderEvent["Refund"] = "refund";
|
|
951
|
+
OrderEvent["PartialRefund"] = "partialRefund";
|
|
952
|
+
})(OrderEvent || (OrderEvent = {}));
|
|
953
|
+
var OrderActor;
|
|
954
|
+
(function (OrderActor) {
|
|
955
|
+
OrderActor["Buyer"] = "buyer";
|
|
956
|
+
OrderActor["Owner"] = "owner";
|
|
957
|
+
/** A VERIFIED payment callback (trap T2) — never the browser's return redirect. */
|
|
958
|
+
OrderActor["PaymentCallback"] = "paymentCallback";
|
|
959
|
+
OrderActor["System"] = "system";
|
|
960
|
+
})(OrderActor || (OrderActor = {}));
|
|
961
|
+
/** What an order holds of the stock in a state (C-D10). */
|
|
962
|
+
var StockHold;
|
|
963
|
+
(function (StockHold) {
|
|
964
|
+
StockHold["None"] = "none";
|
|
965
|
+
/** Held for `STOCK_RESERVATION_MINUTES` while a PSP payment is open. */
|
|
966
|
+
StockHold["Reserved"] = "reserved";
|
|
967
|
+
/** Decremented: sold, or promised to a manual order. */
|
|
968
|
+
StockHold["Taken"] = "taken";
|
|
969
|
+
})(StockHold || (StockHold = {}));
|
|
970
|
+
/** What the server does to stock when an order moves — read from data, never decided per call site. */
|
|
971
|
+
var StockEffect;
|
|
972
|
+
(function (StockEffect) {
|
|
973
|
+
StockEffect["None"] = "none";
|
|
974
|
+
StockEffect["Reserve"] = "reserve";
|
|
975
|
+
StockEffect["CommitReservation"] = "commitReservation";
|
|
976
|
+
StockEffect["ReleaseReservation"] = "releaseReservation";
|
|
977
|
+
/** The conditional atomic decrement (E0's `takeStock`). */
|
|
978
|
+
StockEffect["Take"] = "take";
|
|
979
|
+
StockEffect["GiveBack"] = "giveBack";
|
|
980
|
+
})(StockEffect || (StockEffect = {}));
|
|
981
|
+
var OrderRefusal;
|
|
982
|
+
(function (OrderRefusal) {
|
|
983
|
+
/** The event does not apply in this state. */
|
|
984
|
+
OrderRefusal["InvalidTransition"] = "invalid-transition";
|
|
985
|
+
/** It applies — but not from this actor (e.g. the owner marking an online payment paid). */
|
|
986
|
+
OrderRefusal["ActorNotAllowed"] = "actor-not-allowed";
|
|
987
|
+
/** Cancelled and refunded orders move no more. */
|
|
988
|
+
OrderRefusal["OrderFinal"] = "order-final";
|
|
989
|
+
})(OrderRefusal || (OrderRefusal = {}));
|
|
990
|
+
const STOCK_RESERVATION_MINUTES = 15;
|
|
991
|
+
const ORDER_STOCK_HOLD = Object.freeze({
|
|
992
|
+
[OrderState.AwaitingPayment]: StockHold.Taken,
|
|
993
|
+
[OrderState.PendingPayment]: StockHold.Reserved,
|
|
994
|
+
[OrderState.Paid]: StockHold.Taken,
|
|
995
|
+
[OrderState.Fulfilled]: StockHold.Taken,
|
|
996
|
+
[OrderState.Delivered]: StockHold.Taken,
|
|
997
|
+
[OrderState.Cancelled]: StockHold.None,
|
|
998
|
+
[OrderState.PaymentFailed]: StockHold.None,
|
|
999
|
+
/** A refund never restocks by itself: whether the goods came back is the owner's to say. */
|
|
1000
|
+
[OrderState.Refunded]: StockHold.Taken,
|
|
1001
|
+
[OrderState.PartiallyRefunded]: StockHold.Taken,
|
|
1002
|
+
});
|
|
1003
|
+
/** from-hold → to-hold → effect. Taken → Reserved never happens (the transitions spec proves it). */
|
|
1004
|
+
const STOCK_EFFECTS = Object.freeze({
|
|
1005
|
+
[StockHold.None]: { [StockHold.None]: StockEffect.None, [StockHold.Reserved]: StockEffect.Reserve, [StockHold.Taken]: StockEffect.Take },
|
|
1006
|
+
[StockHold.Reserved]: { [StockHold.None]: StockEffect.ReleaseReservation, [StockHold.Reserved]: StockEffect.None, [StockHold.Taken]: StockEffect.CommitReservation },
|
|
1007
|
+
[StockHold.Taken]: { [StockHold.None]: StockEffect.GiveBack, [StockHold.Reserved]: StockEffect.None, [StockHold.Taken]: StockEffect.None },
|
|
1008
|
+
});
|
|
1009
|
+
const FINAL_ORDER_STATES = Object.freeze([OrderState.Cancelled, OrderState.Refunded]);
|
|
1010
|
+
const OWNER = [OrderActor.Owner];
|
|
1011
|
+
const CALLBACK = [OrderActor.PaymentCallback];
|
|
1012
|
+
const SYSTEM = [OrderActor.System];
|
|
1013
|
+
const REFUNDERS = [OrderActor.Owner, OrderActor.PaymentCallback];
|
|
1014
|
+
const REFUNDABLE = [OrderState.Paid, OrderState.Fulfilled, OrderState.Delivered, OrderState.PartiallyRefunded];
|
|
1015
|
+
/** THE order state machine (C-D11). Anything not listed is refused. */
|
|
1016
|
+
const ORDER_TRANSITIONS = Object.freeze([
|
|
1017
|
+
{ from: OrderState.AwaitingPayment, event: OrderEvent.MarkPaid, to: OrderState.Paid, actors: OWNER },
|
|
1018
|
+
{ from: OrderState.AwaitingPayment, event: OrderEvent.Cancel, to: OrderState.Cancelled, actors: OWNER },
|
|
1019
|
+
{ from: OrderState.AwaitingPayment, event: OrderEvent.Expire, to: OrderState.Cancelled, actors: SYSTEM },
|
|
1020
|
+
{ from: OrderState.PendingPayment, event: OrderEvent.ConfirmPayment, to: OrderState.Paid, actors: CALLBACK },
|
|
1021
|
+
{ from: OrderState.PendingPayment, event: OrderEvent.FailPayment, to: OrderState.PaymentFailed, actors: CALLBACK },
|
|
1022
|
+
{ from: OrderState.PendingPayment, event: OrderEvent.Expire, to: OrderState.Cancelled, actors: SYSTEM },
|
|
1023
|
+
{ from: OrderState.PaymentFailed, event: OrderEvent.StartPayment, to: OrderState.PendingPayment, actors: [OrderActor.Buyer] },
|
|
1024
|
+
{ from: OrderState.PaymentFailed, event: OrderEvent.ConfirmPayment, to: OrderState.Paid, actors: CALLBACK },
|
|
1025
|
+
{ from: OrderState.PaymentFailed, event: OrderEvent.Cancel, to: OrderState.Cancelled, actors: OWNER },
|
|
1026
|
+
{ from: OrderState.PaymentFailed, event: OrderEvent.Expire, to: OrderState.Cancelled, actors: SYSTEM },
|
|
1027
|
+
{ from: OrderState.Paid, event: OrderEvent.Fulfil, to: OrderState.Fulfilled, actors: OWNER },
|
|
1028
|
+
{ from: OrderState.PartiallyRefunded, event: OrderEvent.Fulfil, to: OrderState.Fulfilled, actors: OWNER },
|
|
1029
|
+
{ from: OrderState.Fulfilled, event: OrderEvent.Deliver, to: OrderState.Delivered, actors: OWNER },
|
|
1030
|
+
...REFUNDABLE.map(from => ({ from, event: OrderEvent.Refund, to: OrderState.Refunded, actors: REFUNDERS })),
|
|
1031
|
+
...REFUNDABLE.map(from => ({ from, event: OrderEvent.PartialRefund, to: OrderState.PartiallyRefunded, actors: REFUNDERS })),
|
|
1032
|
+
]);
|
|
1033
|
+
function stockEffect(from, to) {
|
|
1034
|
+
return STOCK_EFFECTS[from === null ? StockHold.None : ORDER_STOCK_HOLD[from]][ORDER_STOCK_HOLD[to]];
|
|
1035
|
+
}
|
|
1036
|
+
/** The ONE place an order moves: the next state and what to do to the stock, or why not. */
|
|
1037
|
+
function nextOrderState(state, event, actor) {
|
|
1038
|
+
const transition = ORDER_TRANSITIONS.find(each => each.from === state && each.event === event);
|
|
1039
|
+
if (!transition) {
|
|
1040
|
+
return { ok: false, refusal: FINAL_ORDER_STATES.includes(state) ? OrderRefusal.OrderFinal : OrderRefusal.InvalidTransition };
|
|
1041
|
+
}
|
|
1042
|
+
if (!transition.actors.includes(actor))
|
|
1043
|
+
return { ok: false, refusal: OrderRefusal.ActorNotAllowed };
|
|
1044
|
+
return { ok: true, state: transition.to, stock: stockEffect(state, transition.to) };
|
|
1045
|
+
}
|
|
1046
|
+
const OPENING_STATE = Object.freeze({
|
|
1047
|
+
[PaymentChannel.Manual]: OrderState.AwaitingPayment,
|
|
1048
|
+
[PaymentChannel.Online]: OrderState.PendingPayment,
|
|
1049
|
+
});
|
|
1050
|
+
/** A new order's state and stock effect: a manual order takes its stock at once, an online one reserves it. */
|
|
1051
|
+
function openingOrderState(kind) {
|
|
1052
|
+
const state = OPENING_STATE[paymentChannelOf(kind)];
|
|
1053
|
+
return { state, stock: stockEffect(null, state) };
|
|
1054
|
+
}
|
|
1055
|
+
function reservationExpiresAt(now) {
|
|
1056
|
+
return new Date(now.getTime() + STOCK_RESERVATION_MINUTES * 60000);
|
|
1057
|
+
}
|
|
1058
|
+
const ORDER_STATE_LABELS = Object.freeze({
|
|
1059
|
+
[OrderState.AwaitingPayment]: { en: 'Awaiting payment', he: 'ממתינה לתשלום' },
|
|
1060
|
+
[OrderState.PendingPayment]: { en: 'Payment in progress', he: 'תשלום בתהליך' },
|
|
1061
|
+
[OrderState.Paid]: { en: 'Paid', he: 'שולמה' },
|
|
1062
|
+
[OrderState.Fulfilled]: { en: 'Fulfilled', he: 'טופלה' },
|
|
1063
|
+
[OrderState.Delivered]: { en: 'Delivered', he: 'נמסרה' },
|
|
1064
|
+
[OrderState.Cancelled]: { en: 'Cancelled', he: 'בוטלה' },
|
|
1065
|
+
[OrderState.PaymentFailed]: { en: 'Payment failed', he: 'התשלום נכשל' },
|
|
1066
|
+
[OrderState.Refunded]: { en: 'Refunded', he: 'זוכתה' },
|
|
1067
|
+
[OrderState.PartiallyRefunded]: { en: 'Partly refunded', he: 'זוכתה חלקית' },
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
/** The fixed checkout's steps, in order (C-D3); a checkout keeps the FURTHEST it reached (the journey, §3g). */
|
|
1071
|
+
var CheckoutStep;
|
|
1072
|
+
(function (CheckoutStep) {
|
|
1073
|
+
CheckoutStep["Contact"] = "contact";
|
|
1074
|
+
CheckoutStep["Delivery"] = "delivery";
|
|
1075
|
+
CheckoutStep["Payment"] = "payment";
|
|
1076
|
+
CheckoutStep["Paid"] = "paid";
|
|
1077
|
+
})(CheckoutStep || (CheckoutStep = {}));
|
|
1078
|
+
const CHECKOUT_STEPS = Object.freeze([
|
|
1079
|
+
CheckoutStep.Contact,
|
|
1080
|
+
CheckoutStep.Delivery,
|
|
1081
|
+
CheckoutStep.Payment,
|
|
1082
|
+
CheckoutStep.Paid,
|
|
1083
|
+
]);
|
|
1084
|
+
const CHECKOUT_STEP_LABELS = Object.freeze({
|
|
1085
|
+
[CheckoutStep.Contact]: { en: 'Contact', he: 'פרטי קשר' },
|
|
1086
|
+
[CheckoutStep.Delivery]: { en: 'Delivery', he: 'משלוח' },
|
|
1087
|
+
[CheckoutStep.Payment]: { en: 'Payment', he: 'תשלום' },
|
|
1088
|
+
[CheckoutStep.Paid]: { en: 'Paid', he: 'שולם' },
|
|
1089
|
+
});
|
|
1090
|
+
function furthestStep(a, b) {
|
|
1091
|
+
const rank = (step) => (step ? CHECKOUT_STEPS.indexOf(step) : -1);
|
|
1092
|
+
const best = rank(a) >= rank(b) ? a : b;
|
|
1093
|
+
return best && CHECKOUT_STEPS.includes(best) ? best : CheckoutStep.Contact;
|
|
1094
|
+
}
|
|
1095
|
+
/** The pages the OWNER writes and links from checkout (§3k). IOX never writes their text (T14). */
|
|
1096
|
+
var LegalPage;
|
|
1097
|
+
(function (LegalPage) {
|
|
1098
|
+
LegalPage["Terms"] = "terms";
|
|
1099
|
+
LegalPage["Returns"] = "returns";
|
|
1100
|
+
LegalPage["Shipping"] = "shipping";
|
|
1101
|
+
LegalPage["Privacy"] = "privacy";
|
|
1102
|
+
})(LegalPage || (LegalPage = {}));
|
|
1103
|
+
var CheckoutGateArea;
|
|
1104
|
+
(function (CheckoutGateArea) {
|
|
1105
|
+
CheckoutGateArea["Payment"] = "payment";
|
|
1106
|
+
CheckoutGateArea["Money"] = "money";
|
|
1107
|
+
CheckoutGateArea["Shipping"] = "shipping";
|
|
1108
|
+
CheckoutGateArea["Business"] = "business";
|
|
1109
|
+
CheckoutGateArea["LegalPages"] = "legalPages";
|
|
1110
|
+
})(CheckoutGateArea || (CheckoutGateArea = {}));
|
|
1111
|
+
var CheckoutGateCode;
|
|
1112
|
+
(function (CheckoutGateCode) {
|
|
1113
|
+
CheckoutGateCode["NoPaymentMethod"] = "no-payment-method";
|
|
1114
|
+
CheckoutGateCode["CurrencyNotSet"] = "currency-not-set";
|
|
1115
|
+
CheckoutGateCode["VatNotSet"] = "vat-not-set";
|
|
1116
|
+
CheckoutGateCode["NoShippingMethod"] = "no-shipping-method";
|
|
1117
|
+
CheckoutGateCode["BusinessNameMissing"] = "business-name-missing";
|
|
1118
|
+
CheckoutGateCode["BusinessNumberMissing"] = "business-number-missing";
|
|
1119
|
+
CheckoutGateCode["BusinessAddressMissing"] = "business-address-missing";
|
|
1120
|
+
CheckoutGateCode["BusinessEmailMissing"] = "business-email-missing";
|
|
1121
|
+
CheckoutGateCode["BusinessPhoneMissing"] = "business-phone-missing";
|
|
1122
|
+
CheckoutGateCode["TermsPageMissing"] = "terms-page-missing";
|
|
1123
|
+
CheckoutGateCode["ReturnsPageMissing"] = "returns-page-missing";
|
|
1124
|
+
CheckoutGateCode["ShippingPageMissing"] = "shipping-page-missing";
|
|
1125
|
+
CheckoutGateCode["PrivacyPageMissing"] = "privacy-page-missing";
|
|
1126
|
+
})(CheckoutGateCode || (CheckoutGateCode = {}));
|
|
1127
|
+
const ships = (facts) => facts.anyProductShips === true;
|
|
1128
|
+
const page = (facts, which) => facts.legalPages?.[which] === true;
|
|
1129
|
+
const business = (facts) => facts.business ?? {};
|
|
1130
|
+
/** THE checkout gate (C-D19), in the order the owner fixes things. The server refuses with it; the admin shows the same rows. */
|
|
1131
|
+
const CHECKOUT_GATE_RULES = Object.freeze([
|
|
1132
|
+
{
|
|
1133
|
+
code: CheckoutGateCode.NoPaymentMethod,
|
|
1134
|
+
area: CheckoutGateArea.Payment,
|
|
1135
|
+
refuses: (facts) => !(facts.paymentMethods ?? []).some(paymentMethodReady),
|
|
1136
|
+
label: { en: 'Turn on a way to get paid', he: 'הפעילו אמצעי תשלום' },
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
code: CheckoutGateCode.CurrencyNotSet,
|
|
1140
|
+
area: CheckoutGateArea.Money,
|
|
1141
|
+
refuses: (facts) => !isCurrencyCode(facts.currency),
|
|
1142
|
+
label: { en: 'Set the shop\'s currency', he: 'הגדירו את מטבע החנות' },
|
|
1143
|
+
},
|
|
1144
|
+
{
|
|
1145
|
+
code: CheckoutGateCode.VatNotSet,
|
|
1146
|
+
area: CheckoutGateArea.Money,
|
|
1147
|
+
refuses: (facts) => !isVatPercent(facts.vatPercent),
|
|
1148
|
+
label: { en: 'Set the VAT rate', he: 'הגדירו את שיעור המע"מ' },
|
|
1149
|
+
},
|
|
1150
|
+
{
|
|
1151
|
+
code: CheckoutGateCode.NoShippingMethod,
|
|
1152
|
+
area: CheckoutGateArea.Shipping,
|
|
1153
|
+
refuses: (facts) => ships(facts) && !(isCurrencyCode(facts.currency)
|
|
1154
|
+
&& (facts.shippingMethods ?? []).some(method => shippingMethodReady(method, facts.currency)
|
|
1155
|
+
&& SHIPPING_KINDS[method.kind].forPhysical)),
|
|
1156
|
+
label: { en: 'Add a delivery or pickup method', he: 'הוסיפו שיטת משלוח או איסוף' },
|
|
1157
|
+
},
|
|
1158
|
+
{
|
|
1159
|
+
code: CheckoutGateCode.BusinessNameMissing,
|
|
1160
|
+
area: CheckoutGateArea.Business,
|
|
1161
|
+
refuses: (facts) => !filled(business(facts).legalName),
|
|
1162
|
+
label: { en: 'Add the business\'s legal name', he: 'הוסיפו את השם הרשמי של העסק' },
|
|
1163
|
+
},
|
|
1164
|
+
{
|
|
1165
|
+
code: CheckoutGateCode.BusinessNumberMissing,
|
|
1166
|
+
area: CheckoutGateArea.Business,
|
|
1167
|
+
refuses: (facts) => !filled(business(facts).businessNumber),
|
|
1168
|
+
label: { en: 'Add the business number (company or VAT dealer number)', he: 'הוסיפו מספר עוסק או ח.פ' },
|
|
1169
|
+
},
|
|
1170
|
+
{
|
|
1171
|
+
code: CheckoutGateCode.BusinessAddressMissing,
|
|
1172
|
+
area: CheckoutGateArea.Business,
|
|
1173
|
+
refuses: (facts) => !filled(business(facts).address),
|
|
1174
|
+
label: { en: 'Add the business address', he: 'הוסיפו את כתובת העסק' },
|
|
1175
|
+
},
|
|
1176
|
+
{
|
|
1177
|
+
code: CheckoutGateCode.BusinessEmailMissing,
|
|
1178
|
+
area: CheckoutGateArea.Business,
|
|
1179
|
+
refuses: (facts) => !looksLikeEmail(business(facts).email),
|
|
1180
|
+
label: { en: 'Add an email buyers can write to', he: 'הוסיפו כתובת אימייל לפניות קונים' },
|
|
1181
|
+
},
|
|
1182
|
+
{
|
|
1183
|
+
code: CheckoutGateCode.BusinessPhoneMissing,
|
|
1184
|
+
area: CheckoutGateArea.Business,
|
|
1185
|
+
refuses: (facts) => !looksLikePhone(business(facts).phone),
|
|
1186
|
+
label: { en: 'Add a phone number buyers can call', he: 'הוסיפו מספר טלפון לפניות קונים' },
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
code: CheckoutGateCode.TermsPageMissing,
|
|
1190
|
+
area: CheckoutGateArea.LegalPages,
|
|
1191
|
+
refuses: (facts) => !page(facts, LegalPage.Terms),
|
|
1192
|
+
label: { en: 'Write your terms of sale page', he: 'כתבו עמוד תקנון ותנאי מכירה' },
|
|
1193
|
+
},
|
|
1194
|
+
{
|
|
1195
|
+
code: CheckoutGateCode.ReturnsPageMissing,
|
|
1196
|
+
area: CheckoutGateArea.LegalPages,
|
|
1197
|
+
refuses: (facts) => !page(facts, LegalPage.Returns),
|
|
1198
|
+
label: { en: 'Write your returns and cancellation page', he: 'כתבו עמוד מדיניות החזרות וביטולים' },
|
|
1199
|
+
},
|
|
1200
|
+
{
|
|
1201
|
+
code: CheckoutGateCode.ShippingPageMissing,
|
|
1202
|
+
area: CheckoutGateArea.LegalPages,
|
|
1203
|
+
refuses: (facts) => ships(facts) && !page(facts, LegalPage.Shipping),
|
|
1204
|
+
label: { en: 'Write your shipping page', he: 'כתבו עמוד מדיניות משלוחים' },
|
|
1205
|
+
},
|
|
1206
|
+
{
|
|
1207
|
+
code: CheckoutGateCode.PrivacyPageMissing,
|
|
1208
|
+
area: CheckoutGateArea.LegalPages,
|
|
1209
|
+
refuses: (facts) => !page(facts, LegalPage.Privacy),
|
|
1210
|
+
label: { en: 'Write your privacy page', he: 'כתבו עמוד מדיניות פרטיות' },
|
|
1211
|
+
},
|
|
1212
|
+
]);
|
|
1213
|
+
/** Checkout opens only when no rule refuses (C-D19, trap T9: the server's, never a hidden button). */
|
|
1214
|
+
function checkoutGate(facts) {
|
|
1215
|
+
const refusals = CHECKOUT_GATE_RULES
|
|
1216
|
+
.filter(rule => rule.refuses(facts))
|
|
1217
|
+
.map(rule => ({ code: rule.code, area: rule.area, label: rule.label }));
|
|
1218
|
+
return { open: refusals.length === 0, refusals };
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
var OrderSnapshotRefusal;
|
|
1222
|
+
(function (OrderSnapshotRefusal) {
|
|
1223
|
+
OrderSnapshotRefusal["EmptyCart"] = "empty-cart";
|
|
1224
|
+
/** The priced cart has issues the buyer has not seen: show them the priced cart first. */
|
|
1225
|
+
OrderSnapshotRefusal["CartChanged"] = "cart-changed";
|
|
1226
|
+
OrderSnapshotRefusal["ShippingNotChosen"] = "shipping-not-chosen";
|
|
1227
|
+
OrderSnapshotRefusal["AddressRequired"] = "address-required";
|
|
1228
|
+
OrderSnapshotRefusal["EmailRequired"] = "email-required";
|
|
1229
|
+
OrderSnapshotRefusal["NameRequired"] = "name-required";
|
|
1230
|
+
/** Not enabled, not complete, not offered yet, or not usable with this delivery. */
|
|
1231
|
+
OrderSnapshotRefusal["PaymentMethodUnusable"] = "payment-method-unusable";
|
|
1232
|
+
})(OrderSnapshotRefusal || (OrderSnapshotRefusal = {}));
|
|
1233
|
+
function deepFreeze(value) {
|
|
1234
|
+
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
1235
|
+
Object.freeze(value);
|
|
1236
|
+
for (const key of Object.keys(value))
|
|
1237
|
+
deepFreeze(value[key]);
|
|
1238
|
+
}
|
|
1239
|
+
return value;
|
|
1240
|
+
}
|
|
1241
|
+
const copyMoney = (value) => money(value.amount, value.currency);
|
|
1242
|
+
const text = (value) => (filled(value) ? value.trim() : null);
|
|
1243
|
+
function copyAddress(address) {
|
|
1244
|
+
if (!address || !filled(address.line1) || !filled(address.city) || !filled(address.country))
|
|
1245
|
+
return null;
|
|
1246
|
+
return {
|
|
1247
|
+
line1: address.line1.trim(),
|
|
1248
|
+
line2: text(address.line2),
|
|
1249
|
+
city: address.city.trim(),
|
|
1250
|
+
postalCode: text(address.postalCode),
|
|
1251
|
+
country: address.country.trim(),
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
const SNAPSHOT_RULES = Object.freeze([
|
|
1255
|
+
{ refusal: OrderSnapshotRefusal.EmptyCart, refuses: (priced) => !priced.lines.length },
|
|
1256
|
+
{ refusal: OrderSnapshotRefusal.CartChanged, refuses: (priced) => priced.issues.length > 0 },
|
|
1257
|
+
{ refusal: OrderSnapshotRefusal.ShippingNotChosen, refuses: (priced) => priced.requiresShipping && !priced.shippingMethod },
|
|
1258
|
+
{
|
|
1259
|
+
refusal: OrderSnapshotRefusal.AddressRequired,
|
|
1260
|
+
refuses: (priced, _payment, buyer) => !!priced.shippingMethod?.needsAddress && !copyAddress(buyer?.address),
|
|
1261
|
+
},
|
|
1262
|
+
{ refusal: OrderSnapshotRefusal.EmailRequired, refuses: (_priced, _payment, buyer) => !looksLikeEmail(buyer?.email) },
|
|
1263
|
+
{ refusal: OrderSnapshotRefusal.NameRequired, refuses: (_priced, _payment, buyer) => !filled(buyer?.name) },
|
|
1264
|
+
{
|
|
1265
|
+
refusal: OrderSnapshotRefusal.PaymentMethodUnusable,
|
|
1266
|
+
refuses: (priced, payment) => usablePaymentMethods([payment], priced.shippingMethod?.kind ?? null).length === 0,
|
|
1267
|
+
},
|
|
1268
|
+
]);
|
|
1269
|
+
/** Freezes what an order stores (lines, unit prices, totals, VAT, currency, delivery, payment, buyer) — or says why it cannot. */
|
|
1270
|
+
function orderSnapshot(pricedCart, payment, buyer) {
|
|
1271
|
+
const refusals = SNAPSHOT_RULES.filter(rule => rule.refuses(pricedCart, payment, buyer)).map(rule => rule.refusal);
|
|
1272
|
+
if (refusals.length)
|
|
1273
|
+
return { ok: false, refusals };
|
|
1274
|
+
const delivery = pricedCart.shippingMethod;
|
|
1275
|
+
const snapshot = {
|
|
1276
|
+
currency: pricedCart.currency,
|
|
1277
|
+
lines: pricedCart.lines.map(line => ({
|
|
1278
|
+
productId: line.productId,
|
|
1279
|
+
variantId: line.variantId,
|
|
1280
|
+
title: line.title,
|
|
1281
|
+
variantName: line.variantName,
|
|
1282
|
+
quantity: line.quantity,
|
|
1283
|
+
unitPrice: copyMoney(line.unitPrice),
|
|
1284
|
+
lineTotal: copyMoney(line.lineTotal),
|
|
1285
|
+
requiresShipping: line.requiresShipping,
|
|
1286
|
+
})),
|
|
1287
|
+
subtotal: copyMoney(pricedCart.subtotal),
|
|
1288
|
+
discount: copyMoney(pricedCart.discount),
|
|
1289
|
+
shipping: copyMoney(pricedCart.shipping),
|
|
1290
|
+
delivery: delivery ? { methodId: delivery.methodId, kind: delivery.kind, name: delivery.name } : null,
|
|
1291
|
+
total: copyMoney(pricedCart.total),
|
|
1292
|
+
vat: { percent: pricedCart.vatPercent, amount: copyMoney(pricedCart.vat) },
|
|
1293
|
+
payment: {
|
|
1294
|
+
kind: payment.kind,
|
|
1295
|
+
channel: paymentChannelOf(payment.kind),
|
|
1296
|
+
details: { ...(payment.details ?? {}) },
|
|
1297
|
+
note: text(payment.note),
|
|
1298
|
+
},
|
|
1299
|
+
buyer: {
|
|
1300
|
+
email: buyer.email.trim(),
|
|
1301
|
+
name: buyer.name.trim(),
|
|
1302
|
+
phone: text(buyer.phone),
|
|
1303
|
+
address: delivery?.needsAddress ? copyAddress(buyer.address) : null,
|
|
1304
|
+
},
|
|
1305
|
+
};
|
|
1306
|
+
return { ok: true, snapshot: deepFreeze(snapshot) };
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* @vectoriox/iox-ui/commerce-core — the shared, FRAMEWORK-FREE core of selling (commerce plan C-D7…C-D11, C-D19).
|
|
1311
|
+
*
|
|
1312
|
+
* Money is integer minor units in one ISO-4217 currency, so the engine, the builder and iox-cms compute the same
|
|
1313
|
+
* totals (trap T6: never a float). E0 shipped Money; E1a adds the cart and its ONE pricing function, shipping v1,
|
|
1314
|
+
* manual payment methods, the order state machine, the checkout steps and gate, and the order snapshot. No clock is
|
|
1315
|
+
* read anywhere — a caller passes `now`.
|
|
1316
|
+
* ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets,
|
|
1317
|
+
* jest moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM.
|
|
1318
|
+
*/
|
|
1319
|
+
|
|
1320
|
+
/**
|
|
1321
|
+
* Generated bundle index. Do not edit.
|
|
1322
|
+
*/
|
|
1323
|
+
|
|
1324
|
+
export { Availability, CART_ISSUE_LABELS, CHECKOUT_GATE_RULES, CHECKOUT_STEPS, CHECKOUT_STEP_LABELS, CURRENCY_CODES, CURRENCY_EXPONENTS, CartIssueCode, CheckoutGateArea, CheckoutGateCode, CheckoutStep, CommerceLanguage, CurrencyCode, DeliveryFit, FINAL_ORDER_STATES, LegalPage, MAX_CART_AMOUNT, MAX_CART_LINES, MAX_LINE_QUANTITY, MAX_VAT_PERCENT, MoneyError, MoneyErrorCode, ORDER_STATE_LABELS, ORDER_STOCK_HOLD, ORDER_TRANSITIONS, OrderActor, OrderEvent, OrderRefusal, OrderSnapshotRefusal, OrderState, PAYMENT_FIELD_LABELS, PAYMENT_METHODS, PaymentChannel, PaymentField, PaymentMethodKind, PaymentProvider, SHIPPING_KINDS, STOCK_EFFECTS, STOCK_RESERVATION_MINUTES, ShippingField, ShippingMethodKind, StockEffect, StockHold, VAT_PERCENT_MAX_DECIMALS, addMoney, availableShippingMethods, cartOf, catalogKey, checkoutGate, commerceLanguage, currencyExponent, formatMoney, furthestStep, includedVat, isCurrencyCode, isMoney, isPaymentMethodKind, isShippingMethodKind, isVatPercent, labelIn, majorToMinor, mergeCarts, migrateMajorPrice, minorToMajor, money, nextOrderState, openingOrderState, orderSnapshot, paymentChannelOf, paymentInstructions, paymentMethodProblems, paymentMethodReady, percentOf, priceCart, quoteShipping, reservationExpiresAt, sellableQuantity, shippingMethodProblems, shippingMethodReady, shippingNeedsAddress, stockEffect, subtractMoney, timesMoney, usablePaymentMethods };
|
|
1325
|
+
//# sourceMappingURL=vectoriox-iox-ui-commerce-core.mjs.map
|