@pisell/pisellos 2.3.28 → 2.3.30

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.
Files changed (57) hide show
  1. package/dist/modules/Order/index.d.ts +32 -8
  2. package/dist/modules/Order/index.js +883 -521
  3. package/dist/modules/Order/payment-utils.d.ts +23 -0
  4. package/dist/modules/Order/payment-utils.js +203 -0
  5. package/dist/modules/Order/types.d.ts +33 -1
  6. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  7. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  8. package/dist/modules/Order/utils.d.ts +2 -1
  9. package/dist/modules/Order/utils.js +6 -12
  10. package/dist/modules/Payment/index.d.ts +2 -0
  11. package/dist/modules/Payment/index.js +78 -49
  12. package/dist/modules/Payment/types.d.ts +26 -24
  13. package/dist/modules/Payment/types.js +2 -0
  14. package/dist/modules/Product/index.d.ts +1 -1
  15. package/dist/server/index.d.ts +14 -0
  16. package/dist/server/index.js +1826 -1000
  17. package/dist/server/modules/order/index.d.ts +47 -4
  18. package/dist/server/modules/order/index.js +1415 -711
  19. package/dist/server/modules/order/types.d.ts +11 -3
  20. package/dist/server/modules/order/types.js +1 -1
  21. package/dist/solution/BaseSales/index.d.ts +40 -4
  22. package/dist/solution/BaseSales/index.js +1268 -749
  23. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  24. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  25. package/dist/solution/BookingByStep/index.d.ts +1 -1
  26. package/dist/solution/BookingTicket/index.d.ts +13 -1
  27. package/dist/solution/BookingTicket/index.js +2 -1
  28. package/dist/utils/payment-number.d.ts +9 -0
  29. package/dist/utils/payment-number.js +69 -0
  30. package/lib/modules/Order/index.d.ts +32 -8
  31. package/lib/modules/Order/index.js +270 -64
  32. package/lib/modules/Order/payment-utils.d.ts +23 -0
  33. package/lib/modules/Order/payment-utils.js +193 -0
  34. package/lib/modules/Order/types.d.ts +33 -1
  35. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  36. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  37. package/lib/modules/Order/utils.d.ts +2 -1
  38. package/lib/modules/Order/utils.js +6 -14
  39. package/lib/modules/Payment/index.d.ts +2 -0
  40. package/lib/modules/Payment/index.js +33 -12
  41. package/lib/modules/Payment/types.d.ts +26 -24
  42. package/lib/modules/Product/index.d.ts +1 -1
  43. package/lib/server/index.d.ts +14 -0
  44. package/lib/server/index.js +604 -8
  45. package/lib/server/modules/order/index.d.ts +47 -4
  46. package/lib/server/modules/order/index.js +578 -116
  47. package/lib/server/modules/order/types.d.ts +11 -3
  48. package/lib/solution/BaseSales/index.d.ts +40 -4
  49. package/lib/solution/BaseSales/index.js +363 -37
  50. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  51. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  52. package/lib/solution/BookingByStep/index.d.ts +1 -1
  53. package/lib/solution/BookingTicket/index.d.ts +13 -1
  54. package/lib/solution/BookingTicket/index.js +2 -1
  55. package/lib/utils/payment-number.d.ts +9 -0
  56. package/lib/utils/payment-number.js +64 -0
  57. package/package.json +1 -1
@@ -0,0 +1,415 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/Order/utils/orderCollectionIdentity.ts
20
+ var orderCollectionIdentity_exports = {};
21
+ __export(orderCollectionIdentity_exports, {
22
+ applyOrderCollectionUidRemaps: () => applyOrderCollectionUidRemaps,
23
+ buildOrderCollectionFallbackUid: () => buildOrderCollectionFallbackUid,
24
+ createUuidV4: () => createUuidV4,
25
+ getOrderCollectionPersistentId: () => getOrderCollectionPersistentId,
26
+ getOrderCollectionReferenceUid: () => getOrderCollectionReferenceUid,
27
+ getOrderCollectionUid: () => getOrderCollectionUid,
28
+ isBlankOrderCollectionIdentity: () => isBlankOrderCollectionIdentity,
29
+ isSameOrderCollectionItem: () => isSameOrderCollectionItem,
30
+ mergeOrderCollectionItems: () => mergeOrderCollectionItems,
31
+ normalizeOrderCollection: () => normalizeOrderCollection,
32
+ normalizeOrderCollections: () => normalizeOrderCollections,
33
+ setOrderCollectionUid: () => setOrderCollectionUid
34
+ });
35
+ module.exports = __toCommonJS(orderCollectionIdentity_exports);
36
+ var import_lodash_es = require("lodash-es");
37
+ var IDENTITY_CONFIG = {
38
+ product: {
39
+ persistentIdField: "order_detail_id",
40
+ uidField: "unique_identification_number",
41
+ fallbackPrefix: "os-fallback:product:order-detail"
42
+ },
43
+ booking: {
44
+ persistentIdField: "schedule_event_id",
45
+ uidField: "unique_identification_number",
46
+ fallbackPrefix: "os-fallback:booking:schedule-event"
47
+ },
48
+ payment: {
49
+ persistentIdField: "order_payment_id",
50
+ uidField: "unique_payment_number",
51
+ fallbackPrefix: "os-fallback:payment:order-payment"
52
+ }
53
+ };
54
+ function createUuidV4() {
55
+ const template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
56
+ return template.replace(/[xy]/g, (char) => {
57
+ const randomValue = Math.floor(Math.random() * 16);
58
+ const value = char === "x" ? randomValue : randomValue & 3 | 8;
59
+ return value.toString(16);
60
+ });
61
+ }
62
+ function isBlankOrderCollectionIdentity(value) {
63
+ return value === void 0 || value === null || value === "";
64
+ }
65
+ function getOrderCollectionPersistentId(kind, item) {
66
+ const record = item;
67
+ if (!record)
68
+ return null;
69
+ const value = record[IDENTITY_CONFIG[kind].persistentIdField];
70
+ if (isBlankOrderCollectionIdentity(value))
71
+ return null;
72
+ return String(value);
73
+ }
74
+ function getOrderCollectionUid(kind, item) {
75
+ var _a;
76
+ const record = item;
77
+ if (!record)
78
+ return null;
79
+ const uidField = IDENTITY_CONFIG[kind].uidField;
80
+ const metadataValue = (_a = record.metadata) == null ? void 0 : _a[uidField];
81
+ if (!isBlankOrderCollectionIdentity(metadataValue))
82
+ return String(metadataValue);
83
+ const topLevelValue = record[uidField];
84
+ if (isBlankOrderCollectionIdentity(topLevelValue))
85
+ return null;
86
+ return String(topLevelValue);
87
+ }
88
+ function buildOrderCollectionFallbackUid(kind, persistentId) {
89
+ return `${IDENTITY_CONFIG[kind].fallbackPrefix}:${String(persistentId)}`;
90
+ }
91
+ function getOrderCollectionReferenceUid(kind, item) {
92
+ const uid = getOrderCollectionUid(kind, item);
93
+ if (uid)
94
+ return uid;
95
+ const persistentId = getOrderCollectionPersistentId(kind, item);
96
+ return persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : null;
97
+ }
98
+ function setOrderCollectionUid(kind, item, uid) {
99
+ const record = (0, import_lodash_es.cloneDeep)(item || {});
100
+ const uidField = IDENTITY_CONFIG[kind].uidField;
101
+ record.metadata = {
102
+ ...record.metadata && typeof record.metadata === "object" ? record.metadata : {},
103
+ [uidField]: uid
104
+ };
105
+ delete record[uidField];
106
+ return record;
107
+ }
108
+ function isSameOrderCollectionItem(kind, left, right) {
109
+ const leftPersistentId = getOrderCollectionPersistentId(kind, left);
110
+ const rightPersistentId = getOrderCollectionPersistentId(kind, right);
111
+ if (leftPersistentId && rightPersistentId) {
112
+ return leftPersistentId === rightPersistentId;
113
+ }
114
+ const leftUid = getOrderCollectionUid(kind, left);
115
+ const rightUid = getOrderCollectionUid(kind, right);
116
+ return Boolean(leftUid && rightUid && leftUid === rightUid);
117
+ }
118
+ function mergeOrderCollectionItems(kind, currentItem, incomingItem, options) {
119
+ var _a;
120
+ const current = (0, import_lodash_es.cloneDeep)(currentItem || {});
121
+ const incoming = (0, import_lodash_es.cloneDeep)(incomingItem || {});
122
+ const persistentIdField = IDENTITY_CONFIG[kind].persistentIdField;
123
+ const currentPersistentIdValue = current[persistentIdField];
124
+ const incomingPersistentIdValue = incoming[persistentIdField];
125
+ const incomingUid = getOrderCollectionUid(kind, incoming);
126
+ const currentUid = getOrderCollectionUid(kind, current);
127
+ const persistentId = getOrderCollectionPersistentId(kind, incoming) || getOrderCollectionPersistentId(kind, current);
128
+ const merged = {
129
+ ...current,
130
+ ...incoming,
131
+ metadata: {
132
+ ...current.metadata && typeof current.metadata === "object" ? current.metadata : {},
133
+ ...incoming.metadata && typeof incoming.metadata === "object" ? incoming.metadata : {}
134
+ }
135
+ };
136
+ if (!isBlankOrderCollectionIdentity(incomingPersistentIdValue)) {
137
+ merged[persistentIdField] = incomingPersistentIdValue;
138
+ } else if (!isBlankOrderCollectionIdentity(currentPersistentIdValue)) {
139
+ merged[persistentIdField] = currentPersistentIdValue;
140
+ }
141
+ const incomingUidIsDerived = Boolean(
142
+ incomingUid && persistentId && (incomingUid === buildOrderCollectionFallbackUid(kind, persistentId) || incomingUid.startsWith(`${buildOrderCollectionFallbackUid(kind, persistentId)}:conflict:`))
143
+ );
144
+ const uid = (incomingUid && !incomingUidIsDerived ? incomingUid : null) || currentUid || incomingUid || ((options == null ? void 0 : options.ensureUid) === false ? null : persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : ((_a = options == null ? void 0 : options.createAnonymousUid) == null ? void 0 : _a.call(options)) || createUuidV4());
145
+ return uid ? setOrderCollectionUid(kind, merged, uid) : merged;
146
+ }
147
+ function createEmptyIdentityStats() {
148
+ return {
149
+ backfilledUidCount: 0,
150
+ collapsedDuplicateCount: 0,
151
+ uidConflictCount: 0,
152
+ anonymousRowCount: 0
153
+ };
154
+ }
155
+ function allocateAnonymousUid(occupiedUids, createAnonymousUid) {
156
+ let uid = createAnonymousUid();
157
+ while (occupiedUids.has(uid))
158
+ uid = createAnonymousUid();
159
+ return uid;
160
+ }
161
+ function allocatePersistentConflictUid(kind, persistentId, occupiedUids) {
162
+ const fallbackUid = buildOrderCollectionFallbackUid(kind, persistentId);
163
+ if (!occupiedUids.has(fallbackUid))
164
+ return fallbackUid;
165
+ let suffix = 1;
166
+ let candidate = `${fallbackUid}:conflict:${suffix}`;
167
+ while (occupiedUids.has(candidate)) {
168
+ suffix += 1;
169
+ candidate = `${fallbackUid}:conflict:${suffix}`;
170
+ }
171
+ return candidate;
172
+ }
173
+ function normalizeOrderCollection(kind, items, options) {
174
+ var _a, _b;
175
+ const stats = createEmptyIdentityStats();
176
+ const uidRemaps = [];
177
+ const result = [];
178
+ const ensureUid = (options == null ? void 0 : options.ensureUid) !== false;
179
+ const createAnonymousUid = (options == null ? void 0 : options.createAnonymousUid) || createUuidV4;
180
+ for (const rawItem of items || []) {
181
+ const item = (0, import_lodash_es.cloneDeep)(rawItem);
182
+ const existingIndex = result.findIndex(
183
+ (existing) => isSameOrderCollectionItem(kind, existing, item)
184
+ );
185
+ if (existingIndex === -1) {
186
+ result.push(item);
187
+ continue;
188
+ }
189
+ const previousReferenceUid = getOrderCollectionReferenceUid(
190
+ kind,
191
+ result[existingIndex]
192
+ );
193
+ const incomingReferenceUid = getOrderCollectionReferenceUid(kind, item);
194
+ result[existingIndex] = mergeOrderCollectionItems(
195
+ kind,
196
+ result[existingIndex],
197
+ item,
198
+ { ensureUid: false }
199
+ );
200
+ const nextUid = getOrderCollectionUid(kind, result[existingIndex]);
201
+ if (nextUid) {
202
+ for (const from of /* @__PURE__ */ new Set([previousReferenceUid, incomingReferenceUid])) {
203
+ if (!from || from === nextUid)
204
+ continue;
205
+ uidRemaps.push({
206
+ kind,
207
+ from,
208
+ to: nextUid,
209
+ persistentId: getOrderCollectionPersistentId(kind, result[existingIndex])
210
+ });
211
+ }
212
+ }
213
+ stats.collapsedDuplicateCount += 1;
214
+ }
215
+ if (!ensureUid)
216
+ return { items: result, stats, uidRemaps };
217
+ const occupiedUids = /* @__PURE__ */ new Set();
218
+ for (let index = 0; index < result.length; index += 1) {
219
+ let item = result[index];
220
+ const persistentId = getOrderCollectionPersistentId(kind, item);
221
+ let uid = getOrderCollectionUid(kind, item);
222
+ if (!uid) {
223
+ uid = persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
224
+ item = setOrderCollectionUid(kind, item, uid);
225
+ result[index] = item;
226
+ stats.backfilledUidCount += 1;
227
+ if (!persistentId)
228
+ stats.anonymousRowCount += 1;
229
+ }
230
+ if (occupiedUids.has(uid)) {
231
+ const replacementUid = persistentId ? allocatePersistentConflictUid(kind, persistentId, occupiedUids) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
232
+ result[index] = setOrderCollectionUid(kind, item, replacementUid);
233
+ uidRemaps.push({
234
+ kind,
235
+ from: uid,
236
+ to: replacementUid,
237
+ persistentId,
238
+ scope: "linked-owner",
239
+ referenceOwnerUid: kind === "product" ? String(
240
+ (item == null ? void 0 : item.booking_uid) || ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.booking_uid) || ""
241
+ ) || null : kind === "booking" ? String(
242
+ (item == null ? void 0 : item.product_uid) || ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.product_uid) || ""
243
+ ) || null : null
244
+ });
245
+ uid = replacementUid;
246
+ stats.uidConflictCount += 1;
247
+ }
248
+ occupiedUids.add(uid);
249
+ }
250
+ return { items: result, stats, uidRemaps };
251
+ }
252
+ function applyOrderCollectionUidRemaps(sourceOrder, uidRemaps) {
253
+ var _a, _b, _c, _d, _e;
254
+ if (!uidRemaps.length)
255
+ return sourceOrder;
256
+ const order = (0, import_lodash_es.cloneDeep)(sourceOrder);
257
+ const hasAmbiguousLinkedOwner = (remap) => {
258
+ if (remap.scope !== "linked-owner" || !remap.referenceOwnerUid)
259
+ return false;
260
+ const ownerKind = remap.kind === "product" ? "booking" : remap.kind === "booking" ? "product" : null;
261
+ if (!ownerKind)
262
+ return false;
263
+ return uidRemaps.some(
264
+ (candidate) => candidate.scope === "linked-owner" && candidate.kind === ownerKind && candidate.from === remap.referenceOwnerUid
265
+ );
266
+ };
267
+ for (const remap of uidRemaps) {
268
+ if (remap.from === remap.to)
269
+ continue;
270
+ const linkedOwnerIsAmbiguous = hasAmbiguousLinkedOwner(remap);
271
+ if (remap.kind === "product") {
272
+ for (const booking of order.bookings || []) {
273
+ if (remap.scope === "linked-owner" && (linkedOwnerIsAmbiguous || getOrderCollectionUid("booking", booking) !== remap.referenceOwnerUid)) {
274
+ continue;
275
+ }
276
+ if (String((booking == null ? void 0 : booking.product_uid) || "") === remap.from) {
277
+ booking.product_uid = remap.to;
278
+ }
279
+ if (String(((_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.product_uid) || "") === remap.from) {
280
+ booking.metadata = { ...booking.metadata || {}, product_uid: remap.to };
281
+ }
282
+ }
283
+ if (remap.scope !== "linked-owner") {
284
+ for (const product of order.products || []) {
285
+ if (String(((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.parent_unique_identification_number) || "") === remap.from) {
286
+ product.metadata = {
287
+ ...product.metadata || {},
288
+ parent_unique_identification_number: remap.to
289
+ };
290
+ }
291
+ const giftInfo = (_c = product == null ? void 0 : product.metadata) == null ? void 0 : _c._giftInfo;
292
+ if (giftInfo && typeof giftInfo === "object") {
293
+ const sourceProductIds = Array.isArray(giftInfo.sourceProductIds) ? giftInfo.sourceProductIds.map(
294
+ (uid) => String(uid) === remap.from ? remap.to : uid
295
+ ) : giftInfo.sourceProductIds;
296
+ const sourceProductId = String(giftInfo.sourceProductId || "") === remap.from ? remap.to : giftInfo.sourceProductId;
297
+ product.metadata = {
298
+ ...product.metadata || {},
299
+ _giftInfo: {
300
+ ...giftInfo,
301
+ ...sourceProductIds !== void 0 ? { sourceProductIds } : {},
302
+ ...sourceProductId !== void 0 ? { sourceProductId } : {}
303
+ }
304
+ };
305
+ }
306
+ }
307
+ }
308
+ const productsByUid = (_d = order._extend) == null ? void 0 : _d.productsByUid;
309
+ const cachedProduct = productsByUid == null ? void 0 : productsByUid[remap.from];
310
+ const cachedPersistentId = getOrderCollectionPersistentId(
311
+ "product",
312
+ (cachedProduct == null ? void 0 : cachedProduct.origin) || cachedProduct
313
+ );
314
+ if (productsByUid && remap.scope === "linked-owner") {
315
+ const retainedProduct = (order.products || []).find(
316
+ (product) => getOrderCollectionUid("product", product) === remap.from
317
+ );
318
+ const remappedProduct = (order.products || []).find(
319
+ (product) => getOrderCollectionUid("product", product) === remap.to
320
+ );
321
+ if (cachedProduct && remap.persistentId && cachedPersistentId === remap.persistentId) {
322
+ productsByUid[remap.to] = {
323
+ ...cachedProduct || {},
324
+ ...productsByUid[remap.to] || {}
325
+ };
326
+ if (retainedProduct) {
327
+ productsByUid[remap.from] = {
328
+ ...cachedProduct || {},
329
+ origin: (0, import_lodash_es.cloneDeep)(retainedProduct)
330
+ };
331
+ }
332
+ } else if (remappedProduct && !productsByUid[remap.to]) {
333
+ productsByUid[remap.to] = { origin: (0, import_lodash_es.cloneDeep)(remappedProduct) };
334
+ }
335
+ continue;
336
+ }
337
+ if (cachedProduct && remap.scope !== "linked-owner") {
338
+ productsByUid[remap.to] = {
339
+ ...cachedProduct || {},
340
+ ...productsByUid[remap.to] || {}
341
+ };
342
+ delete productsByUid[remap.from];
343
+ }
344
+ }
345
+ if (remap.kind === "booking") {
346
+ for (const product of order.products || []) {
347
+ if (remap.scope === "linked-owner" && (linkedOwnerIsAmbiguous || getOrderCollectionUid("product", product) !== remap.referenceOwnerUid)) {
348
+ continue;
349
+ }
350
+ if (String((product == null ? void 0 : product.booking_uid) || "") === remap.from) {
351
+ product.booking_uid = remap.to;
352
+ }
353
+ if (String(((_e = product == null ? void 0 : product.metadata) == null ? void 0 : _e.booking_uid) || "") === remap.from) {
354
+ product.metadata = { ...product.metadata || {}, booking_uid: remap.to };
355
+ }
356
+ }
357
+ }
358
+ }
359
+ return order;
360
+ }
361
+ function normalizeOrderCollections(sourceOrder, options) {
362
+ let order = (0, import_lodash_es.cloneDeep)(sourceOrder || {});
363
+ const orderRecord = order;
364
+ const productResult = normalizeOrderCollection(
365
+ "product",
366
+ Array.isArray(orderRecord.products) ? orderRecord.products : [],
367
+ options
368
+ );
369
+ const bookingResult = normalizeOrderCollection(
370
+ "booking",
371
+ Array.isArray(orderRecord.bookings) ? orderRecord.bookings : [],
372
+ options
373
+ );
374
+ const paymentResult = normalizeOrderCollection(
375
+ "payment",
376
+ Array.isArray(orderRecord.payments) ? orderRecord.payments : [],
377
+ options
378
+ );
379
+ if (Array.isArray(orderRecord.products))
380
+ orderRecord.products = productResult.items;
381
+ if (Array.isArray(orderRecord.bookings))
382
+ orderRecord.bookings = bookingResult.items;
383
+ if (Array.isArray(orderRecord.payments))
384
+ orderRecord.payments = paymentResult.items;
385
+ const uidRemaps = [
386
+ ...productResult.uidRemaps,
387
+ ...bookingResult.uidRemaps,
388
+ ...paymentResult.uidRemaps
389
+ ];
390
+ order = applyOrderCollectionUidRemaps(order, uidRemaps);
391
+ return {
392
+ order,
393
+ stats: {
394
+ product: productResult.stats,
395
+ booking: bookingResult.stats,
396
+ payment: paymentResult.stats
397
+ },
398
+ uidRemaps
399
+ };
400
+ }
401
+ // Annotate the CommonJS export names for ESM import in node:
402
+ 0 && (module.exports = {
403
+ applyOrderCollectionUidRemaps,
404
+ buildOrderCollectionFallbackUid,
405
+ createUuidV4,
406
+ getOrderCollectionPersistentId,
407
+ getOrderCollectionReferenceUid,
408
+ getOrderCollectionUid,
409
+ isBlankOrderCollectionIdentity,
410
+ isSameOrderCollectionItem,
411
+ mergeOrderCollectionItems,
412
+ normalizeOrderCollection,
413
+ normalizeOrderCollections,
414
+ setOrderCollectionUid
415
+ });
@@ -3,6 +3,7 @@ import type { CartItem } from "../Cart";
3
3
  import type { OrderProductDiscountItem, OrderProduct, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder } from './types';
4
4
  import type { RulesParamsHooks } from '../Rules/types';
5
5
  import type { MapOrderPaymentsOptions, OrderPaymentData, OrderPaymentSource } from './types';
6
+ import { createUuidV4 } from './utils/orderCollectionIdentity';
6
7
  export interface OrderProductsDepositProtocol {
7
8
  id: number;
8
9
  title: string;
@@ -177,7 +178,7 @@ export declare const mergeRelationForms: (relationForms: {
177
178
  form_record_ids: number[];
178
179
  }[];
179
180
  export declare const getAllDiscountList: (cartItem: CartItem) => any;
180
- export declare function createUuidV4(): string;
181
+ export { createUuidV4 };
181
182
  export declare function isTempOrder(data: any): data is OrderTempOrder;
182
183
  export declare function formatDateTime(date: Date): string;
183
184
  export declare function normalizeBookingIsAll(booking: Record<string, any>): 0 | 1;
@@ -37,7 +37,7 @@ __export(utils_exports, {
37
37
  createDefaultOrderRulesHooks: () => createDefaultOrderRulesHooks,
38
38
  createDefaultTempOrder: () => createDefaultTempOrder,
39
39
  createEmptySummary: () => import_utils2.createEmptySummary,
40
- createUuidV4: () => createUuidV4,
40
+ createUuidV4: () => import_orderCollectionIdentity.createUuidV4,
41
41
  ensureManualProductDiscountList: () => import_manualProductDiscount.ensureManualProductDiscountList,
42
42
  ensureProductSku: () => ensureProductSku,
43
43
  findManualProductDiscountItem: () => import_manualProductDiscount.findManualProductDiscountItem,
@@ -86,6 +86,7 @@ module.exports = __toCommonJS(utils_exports);
86
86
  var import_dayjs = __toESM(require("dayjs"));
87
87
  var import_decimal = __toESM(require("decimal.js"));
88
88
  var import_utils = require("../../solution/ScanOrder/utils");
89
+ var import_orderCollectionIdentity = require("./utils/orderCollectionIdentity");
89
90
  var import_utils2 = require("../../solution/ScanOrder/utils");
90
91
  var import_manualProductDiscount = require("./utils/manualProductDiscount");
91
92
  function composeLinePrice(params) {
@@ -641,14 +642,6 @@ var getAllDiscountList = (cartItem) => {
641
642
  });
642
643
  return discountList;
643
644
  };
644
- function createUuidV4() {
645
- const template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
646
- return template.replace(/[xy]/g, (char) => {
647
- const randomValue = Math.floor(Math.random() * 16);
648
- const value = char === "x" ? randomValue : randomValue & 3 | 8;
649
- return value.toString(16);
650
- });
651
- }
652
645
  function isTempOrder(data) {
653
646
  if (!data || typeof data !== "object")
654
647
  return false;
@@ -938,7 +931,7 @@ function buildSubmitPayload(params) {
938
931
  enhance
939
932
  } = params;
940
933
  const scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
941
- const bookingUuid = createUuidV4();
934
+ const bookingUuid = (0, import_orderCollectionIdentity.createUuidV4)();
942
935
  const {
943
936
  _extend,
944
937
  relation_id: _relationId,
@@ -1027,9 +1020,7 @@ function mapPaymentItemToOrderPayment(paymentItem) {
1027
1020
  const item = paymentItem;
1028
1021
  const customPaymentId = item.custom_payment_id ?? item.id;
1029
1022
  const metadata = item.metadata && typeof item.metadata === "object" ? { ...item.metadata } : {};
1030
- if (item.uuid && !metadata.unique_payment_number) {
1031
- metadata.unique_payment_number = String(item.uuid);
1032
- }
1023
+ const paymentNumber = item.payment_number;
1033
1024
  const paymentMetadataKeys = [
1034
1025
  "rounding_rule",
1035
1026
  "shop_wallet_pass_id",
@@ -1046,6 +1037,7 @@ function mapPaymentItemToOrderPayment(paymentItem) {
1046
1037
  const createdAt = item.created_at ?? timestamp;
1047
1038
  return {
1048
1039
  ...item.order_payment_id !== void 0 ? { order_payment_id: item.order_payment_id } : {},
1040
+ ...paymentNumber !== void 0 && paymentNumber !== null && paymentNumber !== "" ? { payment_number: String(paymentNumber) } : {},
1049
1041
  amount: String(item.amount ?? "0.00"),
1050
1042
  code: String(item.code || ""),
1051
1043
  custom_payment_id: Number(customPaymentId ?? 0),
@@ -1086,7 +1078,7 @@ function formatV1Product(products) {
1086
1078
  note: String(product.note ?? ""),
1087
1079
  rowKey: product.product_id,
1088
1080
  session: null,
1089
- unique: createUuidV4()
1081
+ unique: (0, import_orderCollectionIdentity.createUuidV4)()
1090
1082
  };
1091
1083
  });
1092
1084
  }
@@ -20,6 +20,7 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
20
20
  protected defaultVersion: string;
21
21
  request: RequestPlugin;
22
22
  private app;
23
+ private appPlugin;
23
24
  private store;
24
25
  window: WindowPlugin;
25
26
  private dbManager;
@@ -40,6 +41,7 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
40
41
  * paymentModule.updateOtherParams({ fatherModule: 'bookingTicket' });
41
42
  */
42
43
  updateOtherParams(params: Record<string, any>): void;
44
+ private getPaymentNumberAppData;
43
45
  /**
44
46
  * 记录信息日志
45
47
  */
@@ -31,6 +31,9 @@ var import_cash = require("./cash");
31
31
  var import_eftpos = require("./eftpos");
32
32
  var import_walletpass = require("./walletpass");
33
33
  var import_decimal = require("decimal.js");
34
+ var import_payment_utils = require("../Order/payment-utils");
35
+ var import_utils2 = require("../Order/utils");
36
+ var import_payment_number = require("../../utils/payment-number");
34
37
  __reExport(Payment_exports, require("./types"), module.exports);
35
38
  function formatAmount(amount) {
36
39
  try {
@@ -112,15 +115,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
112
115
  this.store = options.store;
113
116
  this.otherParams = options.otherParams || {};
114
117
  this.request = core.getPlugin("request");
115
- const appPlugin = core.getPlugin("app");
118
+ this.appPlugin = core.getPlugin("app");
116
119
  this.window = core.getPlugin("window");
117
120
  if (!this.request) {
118
121
  throw new Error("支付模块需要 request 插件支持");
119
122
  }
120
- if (!appPlugin) {
123
+ if (!this.appPlugin) {
121
124
  throw new Error("支付模块需要 app 插件支持");
122
125
  }
123
- this.app = appPlugin.getApp();
126
+ this.app = this.appPlugin.getApp();
124
127
  this.dbManager = this.app.dbManager;
125
128
  this.logger = this.app.logger;
126
129
  this.registerNetworkHandlers();
@@ -136,6 +139,14 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
136
139
  updateOtherParams(params) {
137
140
  this.otherParams = params || {};
138
141
  }
142
+ getPaymentNumberAppData(key) {
143
+ var _a, _b, _c, _d, _e, _f, _g;
144
+ const getData = (_b = (_a = this.appPlugin) == null ? void 0 : _a.getData) == null ? void 0 : _b.call(_a);
145
+ if (typeof getData === "function")
146
+ return getData(key);
147
+ const coreData = (_g = (_e = (_d = (_c = this.app) == null ? void 0 : _c.models) == null ? void 0 : _d.getStore) == null ? void 0 : (_f = _e.call(_d)).getDataByModel) == null ? void 0 : _g.call(_f, "core", "core");
148
+ return coreData == null ? void 0 : coreData[key];
149
+ }
139
150
  /**
140
151
  * 记录信息日志
141
152
  */
@@ -521,15 +532,20 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
521
532
  });
522
533
  throw new Error(warningMessage);
523
534
  }
524
- let paymentUuid;
525
- if ((_a = paymentItem.metadata) == null ? void 0 : _a.unique_payment_number) {
526
- paymentUuid = paymentItem.metadata.unique_payment_number;
527
- } else {
528
- paymentUuid = (0, import_utils.getUniqueId)("payment_");
529
- }
535
+ const paymentUuid = paymentItem.uuid || ((_a = paymentItem.metadata) == null ? void 0 : _a.unique_payment_number) || (0, import_utils.getUniqueId)("payment_");
530
536
  const currentTime = formatDateTime(/* @__PURE__ */ new Date());
537
+ const hasPaymentNumber = String(paymentItem.payment_number || "").trim() !== "";
538
+ const paymentNumberDevicePrefix = hasPaymentNumber ? "LOCAL" : await (0, import_payment_number.resolvePaymentNumberDevicePrefix)(
539
+ (key) => this.getPaymentNumberAppData(key)
540
+ );
541
+ const paymentNumber = (0, import_payment_utils.ensureOrderPaymentNumber)(
542
+ paymentItem,
543
+ paymentNumberDevicePrefix,
544
+ import_utils2.createUuidV4
545
+ ).payment_number;
531
546
  const newPaymentItem = {
532
547
  uuid: paymentUuid,
548
+ payment_number: paymentNumber,
533
549
  custom_payment_id: normalizeCustomPaymentId(paymentItem),
534
550
  name: paymentItem.name,
535
551
  code: paymentItem.code,
@@ -549,10 +565,8 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
549
565
  updated_at: currentTime,
550
566
  // 更新时间
551
567
  metadata: {
552
- ...paymentItem.metadata,
568
+ ...paymentItem.metadata
553
569
  // 保留传入的所有 metadata 字段
554
- unique_payment_number: paymentUuid
555
- // 设置唯一支付号为支付项的 uuid
556
570
  }
557
571
  };
558
572
  order.payment.push(newPaymentItem);
@@ -767,6 +781,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
767
781
  if ("amount" in formattedParams && formattedParams.amount !== void 0) {
768
782
  formattedParams.amount = formatAmount(formattedParams.amount);
769
783
  }
784
+ if (formattedParams.metadata && typeof formattedParams.metadata === "object") {
785
+ formattedParams.metadata = {
786
+ ...paymentItem.metadata || {},
787
+ ...formattedParams.metadata
788
+ };
789
+ }
770
790
  Object.assign(paymentItem, formattedParams);
771
791
  this.recalculateOrderAmount(order);
772
792
  await this.dbManager.update("order", order);
@@ -824,6 +844,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
824
844
  const paymentData = {
825
845
  payments: order.payment.map((payment) => ({
826
846
  uuid: payment.uuid,
847
+ payment_number: payment.payment_number,
827
848
  amount: payment.amount,
828
849
  code: payment.code,
829
850
  custom_payment_id: payment.custom_payment_id,