@pisell/pisellos 2.3.8 → 2.3.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.
@@ -458,7 +458,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
458
458
  generateIdempotencyToken(): string;
459
459
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
460
460
  createOrder(params: CommitOrderParams['query']): {
461
- type: "appointment_booking" | "virtual";
461
+ type: "virtual" | "appointment_booking";
462
462
  platform: string;
463
463
  sales_channel: string;
464
464
  order_sales_channel: string;
@@ -79,6 +79,9 @@ function isPendingVoucherPaymentRecord(payment) {
79
79
  function isPaidPaymentRecord(payment) {
80
80
  return (payment === null || payment === void 0 ? void 0 : payment.status) === ORDER_PAYMENT_STATUS_PAID;
81
81
  }
82
+ function isCommittedVoucherPaymentRecord(payment) {
83
+ return isVoucherPaymentRecord(payment) && (payment === null || payment === void 0 ? void 0 : payment.status) !== 'voided' && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
84
+ }
82
85
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
83
86
  _inherits(OrderModule, _BaseModule);
84
87
  var _super = _createSuper(OrderModule);
@@ -3253,6 +3256,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3253
3256
  this.applyPaymentLifecycleChange(tempOrder, _objectSpread(_objectSpread({}, options), {}, {
3254
3257
  logContext: 'confirmPendingVoucherPayments'
3255
3258
  }));
3259
+ // this.recalculateSummary();
3256
3260
  return tempOrder.payments;
3257
3261
  }
3258
3262
  }, {
@@ -3322,21 +3326,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3322
3326
  var nonVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3323
3327
  return !isVoucherPaymentRecord(payment);
3324
3328
  });
3325
- var syncedVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3326
- return isVoucherPaymentRecord(payment) && hasSyncedOrderPaymentRecord(payment);
3329
+ var normalizeCommittedVoucherPayment = function normalizeCommittedVoucherPayment(payment) {
3330
+ if (hasSyncedOrderPaymentRecord(payment) && (payment.status === undefined || payment.status === 'active')) {
3331
+ return _objectSpread(_objectSpread({}, payment), {}, {
3332
+ status: ORDER_PAYMENT_STATUS_PAID
3333
+ });
3334
+ }
3335
+ return payment;
3336
+ };
3337
+ var committedVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3338
+ return isCommittedVoucherPaymentRecord(payment);
3339
+ }).map(function (payment) {
3340
+ return normalizeCommittedVoucherPayment(payment);
3327
3341
  });
3328
- var syncedVoucherPaymentIds = new Set(syncedVoucherPayments.map(function (payment) {
3342
+ var committedVoucherPaymentIds = new Set(committedVoucherPayments.filter(function (payment) {
3343
+ return hasSyncedOrderPaymentRecord(payment);
3344
+ }).map(function (payment) {
3329
3345
  return String(payment.order_payment_id);
3330
3346
  }));
3347
+ var committedVoucherIds = new Set(committedVoucherPayments.map(function (payment) {
3348
+ return String(payment.voucher_id);
3349
+ }));
3331
3350
  var replaceableVouchers = mappedVouchers.filter(function (payment) {
3332
- if (!hasSyncedOrderPaymentRecord(payment)) return true;
3333
- return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
3351
+ if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
3352
+ return false;
3353
+ }
3354
+ if (payment.voucher_id !== undefined && committedVoucherIds.has(String(payment.voucher_id))) {
3355
+ return false;
3356
+ }
3357
+ return true;
3334
3358
  });
3335
3359
  var cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
3336
3360
  vouchers: replaceableVouchers,
3337
- nonVoucherPayments: [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(syncedVoucherPayments))
3361
+ nonVoucherPayments: [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(committedVoucherPayments))
3338
3362
  });
3339
- tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(syncedVoucherPayments), _toConsumableArray(cappedVouchers));
3363
+ tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(committedVoucherPayments), _toConsumableArray(cappedVouchers));
3340
3364
  this.updateTempOrderPaymentStatus(tempOrder);
3341
3365
  this.persistTempOrder();
3342
3366
  void this.recalculateSummary({
@@ -4533,7 +4557,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4533
4557
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
4534
4558
  var nextPayload = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, payload), hasPaymentOverride ? {
4535
4559
  payments: preparedPaymentOverride || []
4536
- } : {}), hasPaymentStatusOverride ? {
4560
+ } : {}), hasPaymentStatusOverride && !shouldConfirmPendingVoucherPayments ? {
4537
4561
  payment_status: params === null || params === void 0 ? void 0 : params.paymentStatus
4538
4562
  } : {}), hasSmallTicketDataFlagOverride ? {
4539
4563
  small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
@@ -46,6 +46,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
46
46
  protected hasManualDiscountSelection: boolean;
47
47
  private readonly reusedSharedSubModuleNames;
48
48
  private paymentMethodsCache;
49
+ private queuedAutoPaymentSync;
50
+ private autoPaymentSyncFlushing;
51
+ private autoPaymentSyncTimer;
49
52
  constructor(name?: string, version?: string);
50
53
  /**
51
54
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
@@ -225,6 +228,10 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
225
228
  getOrderPayments(): OrderPaymentData[];
226
229
  /** 覆盖当前订单支付项,内部由 OrderModule 清洗为 Sales 协议字段。 */
227
230
  setOrderPayments(payments: OrderPaymentSource[]): OrderPaymentData[];
231
+ private getPaymentStatusForSync;
232
+ private queueLatestAutoPaymentSync;
233
+ private scheduleQueuedAutoPaymentSyncFlush;
234
+ private flushQueuedAutoPaymentSync;
228
235
  /** 追加单个支付项到当前订单。 */
229
236
  addOrderPayment(payment: OrderPaymentSource): OrderPaymentData[];
230
237
  /** 更新当前订单中的指定支付项。 */