@pisell/pisellos 2.1.8 → 2.1.9

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.
@@ -2,42 +2,6 @@ import { Module } from '../../types';
2
2
  import { OrderModule } from '../../modules/Order';
3
3
  import { PaymentModuleAPI, PaymentOrder, PaymentMethod, PaymentStatus, PaymentItem, PaymentItemInput } from '../../modules/Payment';
4
4
  import { CartItem } from '../../modules/Cart/types';
5
- /**
6
- * 结账状态枚举
7
- */
8
- export declare enum CheckoutStatus {
9
- /** 初始化中 */
10
- Initializing = "initializing",
11
- /** 准备就绪 */
12
- Ready = "ready",
13
- /** 创建订单中 */
14
- CreatingOrder = "creating_order",
15
- /** 订单已创建 */
16
- OrderCreated = "order_created",
17
- /** 处理支付中 */
18
- ProcessingPayment = "processing_payment",
19
- /** 支付完成 */
20
- PaymentCompleted = "payment_completed",
21
- /** 结账完成 */
22
- Completed = "completed",
23
- /** 已取消 */
24
- Cancelled = "cancelled",
25
- /** 错误状态 */
26
- Error = "error"
27
- }
28
- /**
29
- * 结账步骤枚举
30
- */
31
- export declare enum CheckoutStep {
32
- /** 订单确认 */
33
- OrderConfirmation = "order_confirmation",
34
- /** 支付方式选择 */
35
- PaymentMethod = "payment_method",
36
- /** 支付处理 */
37
- PaymentProcessing = "payment_processing",
38
- /** 完成 */
39
- Complete = "complete"
40
- }
41
5
  /**
42
6
  * 结账错误类型
43
7
  */
@@ -127,15 +91,6 @@ export interface CreateLocalOrderParams {
127
91
  autoPayment?: boolean;
128
92
  totalInfo: any;
129
93
  }
130
- /**
131
- * 手动下单参数
132
- */
133
- export interface PlaceOrderParams {
134
- /** 订单提交的 URL (可选,默认使用 /order/appointment) */
135
- url?: string;
136
- /** 是否自动替换虚拟订单ID为真实订单ID */
137
- autoReplaceOrderId?: boolean;
138
- }
139
94
  /**
140
95
  * 本地订单数据结构 (基于 appointmentDemo.json)
141
96
  */
@@ -300,74 +255,12 @@ export interface LocalResourceItem {
300
255
  /** 资源类型 (可选) */
301
256
  resourceType?: string;
302
257
  }
303
- /**
304
- * 订单创建参数
305
- */
306
- export interface CreateOrderParams {
307
- /** 购物车商品 */
308
- cartItems: CartItem[];
309
- /** 订单类型 */
310
- type?: 'virtual' | 'appointment_booking';
311
- /** 平台类型 */
312
- platform?: 'pc' | 'h5';
313
- /** 额外参数 */
314
- extra?: Record<string, any>;
315
- }
316
- /**
317
- * 支付处理参数
318
- */
319
- export interface ProcessPaymentParams {
320
- /** 订单UUID */
321
- orderUuid: string;
322
- /** 支付方式代码 */
323
- paymentMethodCode: string;
324
- /** 支付金额 */
325
- amount: string | number;
326
- /** 支付元数据 */
327
- metadata?: Record<string, any>;
328
- }
329
- /**
330
- * 结账状态信息
331
- */
332
- export interface CheckoutStatusInfo {
333
- /** 当前状态 */
334
- status: CheckoutStatus;
335
- /** 当前步骤 */
336
- step: CheckoutStep;
337
- /** 进度百分比 (0-100) */
338
- progress: number;
339
- /** 状态消息 */
340
- message?: string;
341
- /** 错误信息 */
342
- error?: CheckoutError;
343
- }
344
- /**
345
- * 结账摘要信息
346
- */
347
- export interface CheckoutSummary {
348
- /** 订单信息 */
349
- order?: PaymentOrder;
350
- /** 总金额 */
351
- totalAmount: string;
352
- /** 已支付金额 */
353
- paidAmount: string;
354
- /** 待支付金额 */
355
- remainingAmount: string;
356
- /** 支付状态 */
357
- paymentStatus: PaymentStatus;
358
- /** 可用支付方式 */
359
- availablePaymentMethods: PaymentMethod[];
360
- }
361
258
  /**
362
259
  * 结账事件钩子
363
260
  */
364
261
  export declare enum CheckoutHooks {
365
262
  /** 结账初始化完成 */
366
263
  OnCheckoutInitialized = "checkout:onInitialized",
367
- /** 状态变更 */
368
- OnStatusChanged = "checkout:onStatusChanged",
369
- /** 步骤变更 */
370
- OnStepChanged = "checkout:onStepChanged",
371
264
  /** 订单创建成功 */
372
265
  OnOrderCreated = "checkout:onOrderCreated",
373
266
  /** 订单创建失败 */
@@ -413,10 +306,6 @@ export declare enum CheckoutHooks {
413
306
  * 结账状态数据
414
307
  */
415
308
  export interface CheckoutState {
416
- /** 当前状态 */
417
- status: CheckoutStatus;
418
- /** 当前步骤 */
419
- step: CheckoutStep;
420
309
  /** 当前订单 */
421
310
  currentOrder?: PaymentOrder;
422
311
  /** 购物车商品 */
@@ -449,10 +338,6 @@ export interface CurrentOrderInfo {
449
338
  uuid?: string;
450
339
  /** 订单ID */
451
340
  orderId?: string;
452
- /** 订单状态 */
453
- status?: CheckoutStatus;
454
- /** 当前步骤 */
455
- step?: CheckoutStep;
456
341
  /** 订单总金额 */
457
342
  totalAmount?: string;
458
343
  /** 待付金额 */
@@ -486,22 +371,6 @@ export interface CheckoutModuleAPI extends Module {
486
371
  * 创建本地订单 (前端模拟下单流程)
487
372
  */
488
373
  createLocalOrderAsync(params: CreateLocalOrderParams): Promise<PaymentOrder>;
489
- /**
490
- * 手动下单 (根据虚拟订单生成实际订单)
491
- */
492
- placeOrderAsync(params?: PlaceOrderParams): Promise<{
493
- success: boolean;
494
- orderId?: string;
495
- error?: string;
496
- }>;
497
- /**
498
- * 创建订单
499
- */
500
- createOrderAsync(params: CreateOrderParams): Promise<PaymentOrder>;
501
- /**
502
- * 处理支付
503
- */
504
- processPaymentAsync(params: ProcessPaymentParams): Promise<void>;
505
374
  /**
506
375
  * 完成结账
507
376
  */
@@ -509,26 +378,6 @@ export interface CheckoutModuleAPI extends Module {
509
378
  success: boolean;
510
379
  orderId?: string;
511
380
  }>;
512
- /**
513
- * 取消结账
514
- */
515
- cancelCheckoutAsync(): Promise<void>;
516
- /**
517
- * 获取结账状态
518
- */
519
- getCheckoutStatus(): CheckoutStatusInfo;
520
- /**
521
- * 获取结账摘要
522
- */
523
- getCheckoutSummaryAsync(): Promise<CheckoutSummary>;
524
- /**
525
- * 获取可用支付方式
526
- */
527
- getAvailablePaymentMethodsAsync(): Promise<PaymentMethod[]>;
528
- /**
529
- * 刷新支付方式缓存
530
- */
531
- refreshPaymentMethodsAsync(): Promise<PaymentMethod[]>;
532
381
  /**
533
382
  * 获取当前订单基础信息
534
383
  */
@@ -537,21 +386,6 @@ export interface CheckoutModuleAPI extends Module {
537
386
  * 获取当前订单的支付项
538
387
  */
539
388
  getCurrentOrderPaymentItemsAsync(): Promise<PaymentItem[]>;
540
- /**
541
- * 验证结账前置条件
542
- */
543
- validateCheckoutAsync(): Promise<{
544
- valid: boolean;
545
- errors: string[];
546
- }>;
547
- /**
548
- * 重试失败的操作
549
- */
550
- retryFailedOperationAsync(): Promise<void>;
551
- /**
552
- * 设置当前步骤
553
- */
554
- setCurrentStep(step: CheckoutStep): void;
555
389
  /**
556
390
  * 获取订单模块
557
391
  */
@@ -578,18 +412,10 @@ export interface CheckoutModuleAPI extends Module {
578
412
  * @returns 当前系统计算的待付金额
579
413
  */
580
414
  getBalanceDueAmount(): string;
581
- /**
582
- * 刷新 stateAmount 为当前剩余未支付金额
583
- */
584
- refreshStateAmountAsync(): Promise<void>;
585
415
  /**
586
416
  * 获取购物车小计数据
587
417
  */
588
418
  getCartSummary(): CartSummaryItem[] | null;
589
- /**
590
- * 获取提取的金额详细信息
591
- */
592
- getExtractedAmountInfo(): ExtractedAmountInfo | null;
593
419
  /**
594
420
  * 获取支付方式列表(直接调用 Payment 模块)
595
421
  */
@@ -610,20 +436,6 @@ export interface CheckoutModuleAPI extends Module {
610
436
  * 修改当前订单的定金状态
611
437
  */
612
438
  updateOrderDepositStatusAsync(isDeposit: number): Promise<void>;
613
- /**
614
- * 更新当前订单的客户信息
615
- */
616
- updateOrderCustomerAsync(customer: {
617
- customer_id?: string;
618
- customer_name?: string;
619
- }): Promise<void>;
620
- /**
621
- * 获取当前订单的客户信息
622
- */
623
- getCurrentCustomer(): {
624
- customer_id?: string;
625
- customer_name?: string;
626
- } | null;
627
439
  /**
628
440
  * 手动同步订单到后端
629
441
  *
@@ -636,13 +448,6 @@ export interface CheckoutModuleAPI extends Module {
636
448
  orderUuid?: string;
637
449
  response?: any;
638
450
  }>;
639
- /**
640
- * 检查订单是否需要手动同步(异步版本)
641
- *
642
- * 返回订单是否为纯代金券支付且待付金额<=0但未同步的状态
643
- * 从 Payment 模块获取最新的支付项数据
644
- */
645
- needsManualSyncAsync(): Promise<boolean>;
646
451
  /**
647
452
  * 更新订单备注
648
453
  *
@@ -680,20 +485,6 @@ export interface CheckoutModuleAPI extends Module {
680
485
  message?: string;
681
486
  orderId?: string;
682
487
  }>;
683
- /**
684
- * 更新订单商店折扣
685
- *
686
- * 同时更新cartSummary和localOrderData中的shop_discount值
687
- *
688
- * @param discountAmount 商店折扣金额
689
- */
690
- updateShopDiscountAsync(discountAmount: number): Promise<void>;
691
- /**
692
- * 获取当前商店折扣金额
693
- *
694
- * @returns 当前的商店折扣金额,如果没有则返回0
695
- */
696
- getShopDiscount(): number;
697
488
  /**
698
489
  * 保存订单并稍后支付
699
490
  *
@@ -764,18 +555,6 @@ export interface SendCustomerPayLinkParams {
764
555
  * 结账事件数据类型
765
556
  */
766
557
  export interface CheckoutEventData {
767
- /** 状态变更事件 */
768
- statusChanged: {
769
- oldStatus: CheckoutStatus;
770
- newStatus: CheckoutStatus;
771
- timestamp: number;
772
- };
773
- /** 步骤变更事件 */
774
- stepChanged: {
775
- oldStep: CheckoutStep;
776
- newStep: CheckoutStep;
777
- timestamp: number;
778
- };
779
558
  /** 订单创建事件 */
780
559
  orderCreated: {
781
560
  order: PaymentOrder;
@@ -20,30 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var types_exports = {};
21
21
  __export(types_exports, {
22
22
  CheckoutErrorType: () => CheckoutErrorType,
23
- CheckoutHooks: () => CheckoutHooks,
24
- CheckoutStatus: () => CheckoutStatus,
25
- CheckoutStep: () => CheckoutStep
23
+ CheckoutHooks: () => CheckoutHooks
26
24
  });
27
25
  module.exports = __toCommonJS(types_exports);
28
- var CheckoutStatus = /* @__PURE__ */ ((CheckoutStatus2) => {
29
- CheckoutStatus2["Initializing"] = "initializing";
30
- CheckoutStatus2["Ready"] = "ready";
31
- CheckoutStatus2["CreatingOrder"] = "creating_order";
32
- CheckoutStatus2["OrderCreated"] = "order_created";
33
- CheckoutStatus2["ProcessingPayment"] = "processing_payment";
34
- CheckoutStatus2["PaymentCompleted"] = "payment_completed";
35
- CheckoutStatus2["Completed"] = "completed";
36
- CheckoutStatus2["Cancelled"] = "cancelled";
37
- CheckoutStatus2["Error"] = "error";
38
- return CheckoutStatus2;
39
- })(CheckoutStatus || {});
40
- var CheckoutStep = /* @__PURE__ */ ((CheckoutStep2) => {
41
- CheckoutStep2["OrderConfirmation"] = "order_confirmation";
42
- CheckoutStep2["PaymentMethod"] = "payment_method";
43
- CheckoutStep2["PaymentProcessing"] = "payment_processing";
44
- CheckoutStep2["Complete"] = "complete";
45
- return CheckoutStep2;
46
- })(CheckoutStep || {});
47
26
  var CheckoutErrorType = /* @__PURE__ */ ((CheckoutErrorType2) => {
48
27
  CheckoutErrorType2["OrderCreationFailed"] = "order_creation_failed";
49
28
  CheckoutErrorType2["PaymentFailed"] = "payment_failed";
@@ -54,8 +33,6 @@ var CheckoutErrorType = /* @__PURE__ */ ((CheckoutErrorType2) => {
54
33
  })(CheckoutErrorType || {});
55
34
  var CheckoutHooks = /* @__PURE__ */ ((CheckoutHooks2) => {
56
35
  CheckoutHooks2["OnCheckoutInitialized"] = "checkout:onInitialized";
57
- CheckoutHooks2["OnStatusChanged"] = "checkout:onStatusChanged";
58
- CheckoutHooks2["OnStepChanged"] = "checkout:onStepChanged";
59
36
  CheckoutHooks2["OnOrderCreated"] = "checkout:onOrderCreated";
60
37
  CheckoutHooks2["OnOrderCreationFailed"] = "checkout:onOrderCreationFailed";
61
38
  CheckoutHooks2["OnPaymentStarted"] = "checkout:onPaymentStarted";
@@ -81,7 +58,5 @@ var CheckoutHooks = /* @__PURE__ */ ((CheckoutHooks2) => {
81
58
  // Annotate the CommonJS export names for ESM import in node:
82
59
  0 && (module.exports = {
83
60
  CheckoutErrorType,
84
- CheckoutHooks,
85
- CheckoutStatus,
86
- CheckoutStep
61
+ CheckoutHooks
87
62
  });
@@ -1,4 +1,4 @@
1
- import { CheckoutInitParams, CheckoutError, CheckoutErrorType, CheckoutStatus, CheckoutStep, LocalOrderData, CartSummaryItem, ExtractedAmountInfo } from '../types';
1
+ import { CheckoutInitParams, CheckoutError, CheckoutErrorType, LocalOrderData, CartSummaryItem, ExtractedAmountInfo } from '../types';
2
2
  import { CartItem } from '../../../modules/Cart/types';
3
3
  /**
4
4
  * 验证结账数据
@@ -11,10 +11,6 @@ export declare function validateCheckoutData(params: CheckoutInitParams): {
11
11
  * 创建结账错误对象
12
12
  */
13
13
  export declare function createCheckoutError(type: CheckoutErrorType, message: string, details?: any): CheckoutError;
14
- /**
15
- * 计算结账进度
16
- */
17
- export declare function calculateProgress(status: CheckoutStatus, step: CheckoutStep): number;
18
14
  /**
19
15
  * 格式化金额
20
16
  */
@@ -115,3 +111,11 @@ export declare function isVirtualOrderId(orderId: string): boolean;
115
111
  * @returns 是否需要同步订单
116
112
  */
117
113
  export declare function shouldSyncOrderForPayment(paymentCode: string, paymentType: string): boolean;
114
+ /**
115
+ * 判断是否为现金支付
116
+ *
117
+ * @param paymentCode 支付方式代码
118
+ * @param paymentType 支付方式类型
119
+ * @returns 是否为现金支付
120
+ */
121
+ export declare function isCashPayment(paymentCode?: string, paymentType?: string): boolean;
@@ -19,7 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/solution/Checkout/utils/index.ts
20
20
  var utils_exports = {};
21
21
  __export(utils_exports, {
22
- calculateProgress: () => calculateProgress,
23
22
  calculateTotalAmount: () => calculateTotalAmount,
24
23
  createCheckoutError: () => createCheckoutError,
25
24
  debounce: () => debounce,
@@ -30,6 +29,7 @@ __export(utils_exports, {
30
29
  generateLocalOrderId: () => generateLocalOrderId,
31
30
  generateOrderId: () => generateOrderId,
32
31
  getErrorMessage: () => getErrorMessage,
32
+ isCashPayment: () => isCashPayment,
33
33
  isEmpty: () => isEmpty,
34
34
  isProduction: () => isProduction,
35
35
  isValidPaymentMethodCode: () => isValidPaymentMethodCode,
@@ -44,8 +44,7 @@ __export(utils_exports, {
44
44
  validateLocalOrderData: () => validateLocalOrderData
45
45
  });
46
46
  module.exports = __toCommonJS(utils_exports);
47
- var import_types = require("../types");
48
- var import_types2 = require("../../../modules/Payment/types");
47
+ var import_types = require("../../../modules/Payment/types");
49
48
  function validateCheckoutData(params) {
50
49
  const errors = [];
51
50
  if (!params.cartItems || params.cartItems.length === 0) {
@@ -83,54 +82,6 @@ function createCheckoutError(type, message, details) {
83
82
  timestamp: Date.now()
84
83
  };
85
84
  }
86
- function calculateProgress(status, step) {
87
- let baseProgress = 0;
88
- switch (status) {
89
- case import_types.CheckoutStatus.Initializing:
90
- baseProgress = 5;
91
- break;
92
- case import_types.CheckoutStatus.Ready:
93
- baseProgress = 10;
94
- break;
95
- case import_types.CheckoutStatus.CreatingOrder:
96
- baseProgress = 25;
97
- break;
98
- case import_types.CheckoutStatus.OrderCreated:
99
- baseProgress = 40;
100
- break;
101
- case import_types.CheckoutStatus.ProcessingPayment:
102
- baseProgress = 65;
103
- break;
104
- case import_types.CheckoutStatus.PaymentCompleted:
105
- baseProgress = 85;
106
- break;
107
- case import_types.CheckoutStatus.Completed:
108
- baseProgress = 100;
109
- break;
110
- case import_types.CheckoutStatus.Cancelled:
111
- case import_types.CheckoutStatus.Error:
112
- baseProgress = 0;
113
- break;
114
- default:
115
- baseProgress = 0;
116
- }
117
- let stepProgress = 0;
118
- switch (step) {
119
- case import_types.CheckoutStep.OrderConfirmation:
120
- stepProgress = 0;
121
- break;
122
- case import_types.CheckoutStep.PaymentMethod:
123
- stepProgress = 10;
124
- break;
125
- case import_types.CheckoutStep.PaymentProcessing:
126
- stepProgress = 15;
127
- break;
128
- case import_types.CheckoutStep.Complete:
129
- stepProgress = 0;
130
- break;
131
- }
132
- return Math.min(100, baseProgress + stepProgress);
133
- }
134
85
  function formatAmount(amount) {
135
86
  const numAmount = typeof amount === "string" ? parseFloat(amount) : amount;
136
87
  if (isNaN(numAmount))
@@ -367,7 +318,7 @@ function shouldSyncOrderForPayment(paymentCode, paymentType) {
367
318
  )) {
368
319
  return false;
369
320
  }
370
- if (paymentCode === import_types2.PaymentMethodType.Cash || paymentType === import_types2.PaymentMethodType.Cash) {
321
+ if (paymentCode === import_types.PaymentMethodType.Cash || paymentType === import_types.PaymentMethodType.Cash) {
371
322
  return false;
372
323
  }
373
324
  if (codeUpper.includes("CUSTOM") || typeUpper.includes("CUSTOM")) {
@@ -375,9 +326,16 @@ function shouldSyncOrderForPayment(paymentCode, paymentType) {
375
326
  }
376
327
  return true;
377
328
  }
329
+ function isCashPayment(paymentCode, paymentType) {
330
+ const codeUpper = (paymentCode == null ? void 0 : paymentCode.toUpperCase()) || "";
331
+ const typeUpper = (paymentType == null ? void 0 : paymentType.toUpperCase()) || "";
332
+ const cashIdentifiers = ["CASH", "CASHMANUAL", "MANUAL"];
333
+ return cashIdentifiers.some(
334
+ (identifier) => codeUpper.includes(identifier) || typeUpper.includes(identifier)
335
+ );
336
+ }
378
337
  // Annotate the CommonJS export names for ESM import in node:
379
338
  0 && (module.exports = {
380
- calculateProgress,
381
339
  calculateTotalAmount,
382
340
  createCheckoutError,
383
341
  debounce,
@@ -388,6 +346,7 @@ function shouldSyncOrderForPayment(paymentCode, paymentType) {
388
346
  generateLocalOrderId,
389
347
  generateOrderId,
390
348
  getErrorMessage,
349
+ isCashPayment,
391
350
  isEmpty,
392
351
  isProduction,
393
352
  isValidPaymentMethodCode,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.8",
4
+ "version": "2.1.9",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",