UNPKG

@pisell/pisellos

Version:

一个可扩展的前端模块化SDK框架,支持插件系统

823 lines (822 loc) 25.7 kB
/** * 支付相关类型定义 */ /** * 支付方式枚举 */ export declare enum PaymentMethodType { Cash = "CASHMANUAL", Eftpos = "EFTPOS", Wallet = "WALLET" } /** * 支付状态枚举 */ export declare enum PaymentStatus { /** 支付处理中 - 订单正在进行支付操作 */ Processing = "payment_processing", /** 同步中 - 暂时不使用,为了向后兼容保留 */ Sync = "sync", /** 部分支付 - 支付金额不足订单总金额 */ PartiallyPaid = "partially_paid", /** 已完成 - 本地支付完成,后台自动同步到服务器 */ Finished = "finish", /** 已撤销 - 本地订单取消 */ Voided = "voided" } /** * 任务状态枚举 */ export declare enum TaskRunStatus { Pending = "pending", Running = "running", Success = "success", Failed = "failed" } /** * 舍入规则枚举 */ export declare enum RoundingRule { /** 标准舍入(中点向上) */ Standard = "standard_rounding", /** 标准舍入(中点向下) */ StandardDown = "standard_down", /** 总是向上舍入 */ AlwaysUp = "always_up", /** 总是向下舍入 */ AlwaysDown = "always_down" } /** * 舍入结果 */ export interface RoundingResult { /** 原始金额 */ originalAmount: string; /** 舍入后的金额 */ roundedAmount: string; /** 舍入差额(舍入后金额 - 原始金额) */ roundingDifference: string; } /** * 舍入间隔枚举 */ export declare enum RoundingInterval { /** 0.05 间隔 */ Interval005 = 0.05, /** 0.1 间隔 */ Interval01 = 0.1, /** 0.5 间隔 */ Interval05 = 0.5, /** 1 间隔 */ Interval1 = 1 } /** * 支付方式信息 */ export interface PaymentMethod { /** 支付方式ID */ id: number; /** 支付方式代码 */ code: string; /** 支付方式名称 */ name: string; /** 支付方式类型 */ type: string; /** 是否启用 */ enabled: boolean; /** 其他配置信息 */ [key: string]: any; } /** * 支付项 */ export interface PaymentItem { /** 当前支付项的唯一 ID */ uuid: string; /** 当前支付方式付出去多少钱 */ amount: string; /** 支付类型,跟支付列表上对应的支付方式保持一致 */ code: string; /** 支付类型id,跟支付列表上对应的支付方式保持一致 */ custom_payment_id: number; /** 支付类型名称,跟支付列表上对应的支付方式保持一致 */ name: string; /** 支付类型type,跟支付列表上对应的支付方式保持一致 */ type: string; /** 代金券、充值卡、积分卡等wallet pass id */ voucher_id?: string; /** 拓展参数字段 */ metadata?: { /** 钱箱 ID */ shop_wallet_pass_id?: string; /** 唯一支付号 */ unique_payment_number?: string; /** rouding规则 */ rounding_rule?: any; /** 实付金额(现金支付时的实际给出金额) */ actual_paid_amount?: number; /** 找零金额(现金支付时的找零金额) */ change_given_amount?: number; }; /** rouding金额 */ rounding_amount?: string; /** 三方支付手续费 */ service_charge?: { percentage?: string; amount?: string; }; /** 支付项状态 */ status?: 'active' | 'voided'; /** 原始金额(用于记录撤销前的金额) */ origin_amount?: string; /** 订单支付类型 */ order_payment_type?: 'normal' | 'deposit'; /** 本支付项是否已成功同步到后端 */ isSynced?: boolean; /** 最近一次同步失败信息(存在则代表同步失败过) */ syncError?: { error: string; errorCode?: string; statusCode?: number; timestamp: number; }; /** 支付项创建时间 (格式: YYYY-MM-DD HH:mm:ss) */ created_at?: string; /** 支付项更新时间 (格式: YYYY-MM-DD HH:mm:ss) */ updated_at?: string; /** 钱包支付使用金额 */ wallet_pass_use_value?: any; /** 钱包支付使用单位 */ wallet_pass_usage_unit?: any; } /** * 订单信息 */ export interface OrderInfo { /** 订单 id */ order_id: number; /** 订单总金额 */ total_amount: string; /** 是否是定金订单 */ is_deposit: number; /** 定金金额 */ deposit_amount: string; } /** * 支付订单(简化版,仅保留支付相关信息) */ export interface PaymentOrder { /** 当前订单的唯一 ID */ uuid: string; /** 订单ID(字符串类型,支持本地虚拟ID) */ id: string; /** 订单ID(数字类型,兼容旧版本) */ order_id: string; /** 支付项列表 */ payment: PaymentItem[]; /** 修改的支付项列表 */ adjust_offline_payments: PaymentItem[]; /** 总计金额 */ total_amount: string; /** 待付金额 */ expect_amount: string; /** 支付状态 */ payment_status: PaymentStatus; /** 是否是定金订单 */ is_deposit: number; /** 定金金额 */ deposit_amount: string; /** 总税费 */ tax_fee: string; /** 原始订单数据(由 Checkout 模块传入) */ order_info?: any; } /** * 支付状态 */ export interface PaymentState { } /** * 推送订单参数(简化版) */ export interface PushOrderParams { /** 订单ID */ order_id: string; /** 总金额 */ total_amount: string; /** 是否是定金订单 */ is_deposit?: number; /** 定金金额 */ deposit_amount?: string; /** 原始订单数据(可选,由 Checkout 模块传入) */ order_info?: any; /** 云端已存在的支付项(可选,用于处理订单在其他设备或云端生成的场景) */ existPayment?: PaymentItem[]; } /** * 更新订单参数 */ export interface UpdateOrderParams { /** 订单UUID */ uuid: string; /** 更新的字段 */ [key: string]: any; } /** * 支付项输入类型(允许 amount 为数字) */ export interface PaymentItemInput { /** 当前支付方式付出去多少钱 */ amount: string | number; /** 支付类型,跟支付列表上对应的支付方式保持一致 */ code: string; /** 支付类型id,跟支付列表上对应的支付方式保持一致 */ custom_payment_id: number; /** 支付类型名称,跟支付列表上对应的支付方式保持一致 */ name: string; /** 支付类型type,跟支付列表上对应的支付方式保持一致 */ type: string; /** 代金券、充值卡、积分卡等wallet pass id */ voucher_id?: string; /** 三方支付手续费 */ service_charge?: { percentage?: string; amount?: string; }; /** 舍入金额 */ rounding_amount?: string; /** 订单支付类型 */ order_payment_type?: 'normal' | 'deposit'; /** 扩展参数字段 */ metadata?: { /** 钱箱 ID */ shop_wallet_pass_id?: string; /** 唯一支付号 */ unique_payment_number?: string; /** rounding规则 */ rounding_rule?: any; /** 实付金额(现金支付时的实际给出金额) */ actual_paid_amount?: number; /** 找零金额(现金支付时的找零金额) */ change_given_amount?: number; }; /** 支付项创建时间 (格式: YYYY-MM-DD HH:mm:ss, 可选,不传则自动生成) */ created_at?: string; /** 支付项更新时间 (格式: YYYY-MM-DD HH:mm:ss, 可选,不传则自动生成) */ updated_at?: string; /** 钱包支付使用金额 */ wallet_pass_use_value?: any; /** 钱包支付使用单位 */ wallet_pass_usage_unit?: any; } /** * 推送支付项参数 */ export interface PushPaymentParams { /** 订单UUID */ orderUuid: string; /** 支付项信息 */ paymentItem: PaymentItemInput; } /** * 更新支付项参数中的字段类型(允许 amount 为数字) */ export interface PaymentUpdateFields { /** 当前支付项的唯一 ID */ uuid?: string; /** 当前支付方式付出去多少钱 */ amount?: string | number; /** 支付类型,跟支付列表上对应的支付方式保持一致 */ code?: string; /** 支付类型id,跟支付列表上对应的支付方式保持一致 */ id?: number; /** 支付类型名称,跟支付列表上对应的支付方式保持一致 */ name?: string; /** 支付类型type,跟支付列表上对应的支付方式保持一致 */ type?: string; /** 代金券、充值卡、积分卡等wallet pass id */ voucher_id?: string; /** 该支付项是否已经同步给后端服务器(只有网络请求成功后才为true) */ isSynced?: boolean; /** 同步错误信息(业务错误时记录错误信息,用于区分"未同步"和"同步失败") */ syncError?: { error: string; errorCode?: string; statusCode?: number; timestamp: number; }; /** 钱包支付使用金额 */ wallet_pass_use_value?: any; /** 钱包支付使用单位 */ wallet_pass_usage_unit?: any; } /** * 更新支付项参数 */ export interface UpdatePaymentParams { /** 订单UUID */ orderUuid: string; /** 支付项UUID */ paymentUuid: string; /** 更新的字段 */ params: PaymentUpdateFields; } /** * 删除支付项参数 */ export interface DeletePaymentParams { /** 订单UUID */ orderUuid: string; /** 支付项UUID */ paymentUuid: string; } /** * 现金支付接口 */ export interface CashPayment { /** 处理现金支付 */ processCashPayment: (amount: number, orderUuid: string) => Promise<void>; /** 获取现金余额 */ getCashBalance: () => Promise<number>; } /** * Eftpos支付接口 */ export interface EftposPayment { /** 处理Eftpos支付 */ processEftposPayment: (amount: number, orderUuid: string) => Promise<void>; /** 检查Eftpos设备状态 */ checkDeviceStatus: () => Promise<boolean>; } /** * 钱包支付接口 */ export interface WalletPassPayment { /** 生成钱包API默认参数 */ generateWalletParams: (businessData: WalletInitBusinessData) => WalletDeductionRecommendParams; /** 获取已存储的钱包参数 */ getStoredWalletParams: () => WalletDeductionRecommendParams | null; /** 清理已存储的钱包参数 */ clearStoredWalletParams: () => void; /** 初始化钱包数据(从业务数据开始,内部生成参数) */ initializeWalletDataFromBusinessAsync: (businessData: WalletInitBusinessData) => Promise<{ walletRecommendList: WalletRecommendItem[]; userIdentificationCodes: UserIdentificationCodeItem[]; }>; /** 初始化钱包数据(先获取推荐列表,再获取用户识别码列表) */ initializeWalletDataAsync: (baseParams: WalletDeductionRecommendParams) => Promise<{ walletRecommendList: WalletRecommendItem[]; userIdentificationCodes: UserIdentificationCodeItem[]; }>; /** 获取钱包推荐扣款列表(异步获取并缓存) */ getWalletPassRecommendListAsync: (params: WalletDeductionRecommendParams) => Promise<WalletRecommendItem[]>; /** 查询用户识别码列表(异步获取并缓存) */ getUserIdentificationCodeListAsync: (params: UserIdentificationCodeParams) => Promise<UserIdentificationCodeItem[]>; /** 搜索识别码信息 */ searchIdentificationCodeAsync: (params: SearchIdentificationCodeParams) => Promise<SearchIdentificationCodeResult>; /** 获取缓存的搜索结果列表 */ getSearchResults: () => SearchIdentificationCodeItem[]; /** 根据识别码查找搜索结果 */ findSearchResultByCode: (code: string) => SearchIdentificationCodeItem | undefined; /** 获取缓存的钱包推荐列表 */ getWalletRecommendList: () => WalletRecommendItem[]; /** 获取缓存的用户识别码列表 */ getUserIdentificationCodes: () => UserIdentificationCodeItem[]; /** 清除钱包推荐列表 */ clearWalletRecommendList: () => void; /** 清除用户识别码列表 */ clearUserIdentificationCodes: () => void; /** 清除搜索结果缓存 */ clearSearchResults: () => void; /** 清除所有缓存数据 */ clearAllCache: () => void; /** 处理钱包支付 */ processWalletPayment: (amount: number, orderUuid: string, voucherId?: string) => Promise<void>; /** 获取钱包余额 */ getWalletBalance: (voucherId: string) => Promise<number>; } /** * 支付模块API接口 */ export interface PaymentModuleAPI { /** 现金支付相关方法 */ cash: CashPayment; /** Eftpos支付相关方法 */ eftpos: EftposPayment; /** 钱包支付相关方法 */ wallet: WalletPassPayment; /** 获取支付方式列表 */ getPayMethodListAsync: () => Promise<PaymentMethod[]>; /** 创建支付订单(仅保存支付相关信息) */ createPaymentOrderAsync: (params: PushOrderParams) => Promise<PaymentOrder>; /** 根据订单UUID获取支付订单 */ getPaymentOrderByUuidAsync: (orderUuid: string) => Promise<PaymentOrder | null>; /** 基于UUID替换订单ID */ replaceOrderIdByUuidAsync: (orderUuid: string, newOrderId: string) => Promise<PaymentOrder | null>; /** 删除支付订单 */ deletePaymentOrderAsync: (orderUuid: string) => Promise<void>; /** 获取支付项 */ getPaymentItemsAsync: (orderUuid: string, includeVoided?: boolean) => Promise<PaymentItem[]>; /** 获取所有支付项(包括已撤销的) */ getAllPaymentItemsAsync: (orderUuid: string) => Promise<PaymentItem[]>; /** 为某个订单添加支付项 */ addPaymentItemAsync: (orderUuid: string, paymentItem: PaymentItemInput) => Promise<void>; /** 删除支付项 */ deletePaymentAsync: (orderUuid: string, paymentUuid: string) => Promise<void>; /** 更新支付项 */ updatePaymentAsync: (orderUuid: string, paymentUuid: string, params: PaymentUpdateFields) => Promise<void>; /** 批量更新代金券类支付项(覆盖更新) */ updateVoucherPaymentItemsAsync: (orderUuid: string, voucherPaymentItems: PaymentItemInput[]) => Promise<void>; /** 获取订单剩余待付金额 */ getRemainingOrderAmountAsync: (orderUuid: string) => Promise<number>; /** 获取订单剩余待付金额(基于用户输入的金额) */ getRemainingOrderAmountWithInputAsync: (inputAmount: string | number, orderUuid: string) => Promise<number>; /** * 智能金额舍入 * @param originalAmount 原始金额 * @param interval 舍入间隔 (0.05, 0.1, 0.5, 1) * @param rule 舍入规则 (standard, standard_down, always_up, always_down) * @returns 舍入后的金额 */ roundAmountAsync: (originalAmount: number | string, interval: RoundingInterval | number, rule: RoundingRule | string) => Promise<RoundingResult>; /** 提交支付 */ submitPayAsync: (orderUuid?: string) => Promise<{ status: 'success' | 'failed'; }>; /** 获取部分支付的订单 */ getPartiallyPaidOrdersAsync: () => Promise<PaymentOrder[]>; } /** * 订单变化事件数据 */ export interface OnOrderChangedEventData { /** 操作类型 */ action: 'add' | 'delete' | 'update' | 'payment_add' | 'payment_delete' | 'payment_update' | 'submit'; /** 当前订单 */ order: PaymentOrder; /** 原始订单(仅在 update 操作时提供) */ originalOrder?: PaymentOrder; /** 相关的支付项(仅在 payment_* 操作时提供) */ paymentItem?: PaymentItem; } /** * 支付方式变化事件数据 */ export interface OnPaymentMethodsChangedEventData { /** 旧的支付方式列表 */ oldMethods: PaymentMethod[]; /** 新的支付方式列表 */ newMethods: PaymentMethod[]; } /** * 支付同步错误事件数据 */ export interface OnPaymentSyncErrorEventData { /** 订单UUID */ orderUuid: string; /** 订单ID */ orderId: number; /** 错误信息 */ error: string; /** 错误代码 */ errorCode?: string; /** HTTP状态码 */ statusCode?: number; /** 错误发生时间 */ timestamp: number; /** 响应数据(当HTTP请求成功但业务失败时) */ responseData?: any; } /** * 支付同步成功事件数据 */ export interface OnPaymentSyncSuccessEventData { /** 订单UUID */ orderUuid: string; /** 订单ID */ orderId: number; /** 成功时间 */ timestamp: number; } /** * 钱包推荐列表更新事件数据 */ export interface OnWalletRecommendListUpdatedEventData { /** 新的钱包推荐列表 */ walletRecommendList: WalletRecommendItem[]; } /** * 用户识别码列表更新事件数据 */ export interface OnUserIdentificationCodesUpdatedEventData { /** 新的用户识别码列表 */ userIdentificationCodes: UserIdentificationCodeItem[]; } /** * 钱包缓存清除事件数据 */ export interface OnWalletCacheClearedEventData { /** 清除的数据类型 */ clearedTypes: ('walletRecommendList' | 'userIdentificationCodes' | 'all')[]; } /** * 搜索识别码完成事件数据 */ export interface OnSearchIdentificationCodeCompletedEventData { /** 当前搜索的识别码 */ searchCode: string; /** 当前搜索返回的结果 */ currentSearchResults: SearchIdentificationCodeItem[]; /** 缓存中的所有搜索结果 */ cachedSearchResults: SearchIdentificationCodeItem[]; /** 搜索参数 */ searchParams: SearchIdentificationCodeParams; } /** * 钱包初始化开始事件数据 */ export interface OnWalletInitializationStartedEventData { /** 业务数据 */ businessData: WalletInitBusinessData; /** 开始时间 */ startTime: number; } /** * 钱包初始化完成事件数据 */ export interface OnWalletInitializationCompletedEventData { /** 业务数据 */ businessData: WalletInitBusinessData; /** 初始化结果 */ result: { walletRecommendList: WalletRecommendItem[]; userIdentificationCodes: UserIdentificationCodeItem[]; }; /** 开始时间 */ startTime: number; /** 结束时间 */ endTime: number; /** 执行时长(毫秒) */ duration: number; } /** * 钱包初始化失败事件数据 */ export interface OnWalletInitializationFailedEventData { /** 业务数据 */ businessData: WalletInitBusinessData; /** 错误信息 */ error: Error; /** 开始时间 */ startTime: number; /** 结束时间 */ endTime: number; /** 执行时长(毫秒) */ duration: number; } /** * 钱包支付事件枚举 */ export declare enum WalletPassHooks { OnWalletRecommendListUpdated = "wallet:onWalletRecommendListUpdated", OnWalletRecommendListCleared = "wallet:onWalletRecommendListCleared", OnUserIdentificationCodesUpdated = "wallet:onUserIdentificationCodesUpdated", OnUserIdentificationCodesCleared = "wallet:onUserIdentificationCodesCleared", OnWalletCacheCleared = "wallet:onWalletCacheCleared", OnSearchIdentificationCodeCompleted = "wallet:onSearchIdentificationCodeCompleted", OnWalletInitializationStarted = "wallet:onWalletInitializationStarted", OnWalletInitializationCompleted = "wallet:onWalletInitializationCompleted", OnWalletInitializationFailed = "wallet:onWalletInitializationFailed" } /** * 支付钩子事件(统一接口) */ export declare enum PaymentHooks { OnPaymentMethodsLoaded = "payment:onPaymentMethodsLoaded", OnPaymentMethodsChanged = "payment:onPaymentMethodsChanged", OnOrderChanged = "payment:onOrderChanged", OnOrderAdded = "payment:onOrderAdded", OnOrderUpdated = "payment:onOrderUpdated", OnOrderDeleted = "payment:onOrderDeleted", OnPaymentAdded = "payment:onPaymentAdded", OnPaymentUpdated = "payment:onPaymentUpdated", OnPaymentDeleted = "payment:onPaymentDeleted", OnPaymentSubmitted = "payment:onPaymentSubmitted", OnOrderAmountChanged = "payment:onOrderAmountChanged", OnPaymentSyncError = "payment:onPaymentSyncError", OnPaymentSyncSuccess = "payment:onPaymentSyncSuccess", OnWalletRecommendListUpdated = "wallet:onWalletRecommendListUpdated", OnWalletRecommendListCleared = "wallet:onWalletRecommendListCleared", OnUserIdentificationCodesUpdated = "wallet:onUserIdentificationCodesUpdated", OnUserIdentificationCodesCleared = "wallet:onUserIdentificationCodesCleared", OnWalletCacheCleared = "wallet:onWalletCacheCleared", OnSearchIdentificationCodeCompleted = "wallet:onSearchIdentificationCodeCompleted" } /** * 钱包推荐扣款请求参数 */ export interface WalletDeductionRecommendParams { /** 销售渠道 */ sale_channel: string; /** 前端设置只想要的字段 */ expect_columns?: string[]; /** 客户id */ customer_id?: number; /** 客户holder_id */ holder_id?: number; /** 订单总计金额 */ order_expect_amount: number; /** 订单小计金额 */ order_product_amount: number; /** 订单待支付金额 */ order_wait_pay_amount: number; /** 统计计数用户id */ order_behavior_count_customer_id?: number; /** 已选商品 */ products: { /** 商品id */ product_id: number; /** 商品variant_id */ product_variant_id: string; /** 商品数量 */ quantity: number; /** 商品使用了所有优惠后的最终价格 */ selling_price: number; /** 客户holder_id */ holder_id?: number; }[]; /** 预备支付 */ prepare_payments?: { voucher_id: number; amount: number; tag: string; }[]; /** 订单ID */ payment_order_id?: string; } /** * 钱包初始化业务数据接口 * 用于生成钱包API参数的必要业务信息 */ export interface WalletInitBusinessData { /** 客户ID(可选) */ customer_id?: number; /** 客户 holder */ holder?: { form_record: number[]; }; /** 金额信息 */ amountInfo: { totalAmount: string; subTotal: string; /** 是否是定金订单 */ isDeposit?: number; /** 定金金额 */ depositAmount?: string; }; /** 商品列表 */ products: { product_id: number; product_variant_id: string; quantity: number; selling_price: number; holder_id?: number; }[]; order_wait_pay_amount?: number; /** 订单ID */ payment_order_id?: string; is_price_include_tax: number; } /** * 查询用户识别码列表请求参数 */ export interface UserIdentificationCodeParams extends WalletDeductionRecommendParams { /** 是否可用 */ available?: 0 | 1 | 2; /** 其他精确码 */ other_exact_codes?: string[]; /** 过滤预备钱包通行证 */ filter_prepare_wallet_pass?: 0 | 1; /** 预备支付 */ prepare_payments?: { voucher_id: number; amount: number; tag: string; }[]; /** 订单ID */ payment_order_id?: string; } /** * 钱包推荐扣款响应数据 */ export interface WalletDeductionRecommendResponse { /** 响应状态码 */ code?: number; /** 响应消息 */ message?: string; /** 响应数据 */ data?: WalletRecommendItem[]; } /** * 用户识别码列表响应数据 */ export interface UserIdentificationCodeResponse { /** 响应状态码 */ code?: number; /** 响应消息 */ message?: string; /** 响应数据 */ data?: UserIdentificationCodeItem[]; } /** * 用户识别码项目 */ export interface UserIdentificationCodeItem { /** 识别码ID */ id: number; /** 识别码 */ code: string; /** 识别码名称 */ name: string; /** 识别码类型 */ type: string; /** 是否可用 */ available: boolean; /** 余额信息 */ balance?: number; /** 有效期 */ expires_at?: string; /** 其他扩展字段 */ [key: string]: any; } /** * 搜索识别码请求参数 * 基于 WalletDeductionRecommendParams 并增加 code 字段 */ export interface SearchIdentificationCodeParams extends WalletDeductionRecommendParams { /** 识别码 */ code: string; /** 订单ID */ payment_order_id?: string; } /** * 搜索识别码响应数据 */ export interface SearchIdentificationCodeResponse { /** 响应状态码 */ code?: number; /** 响应消息 */ message?: string; /** 响应数据 */ data?: SearchIdentificationCodeItem[]; } /** * 搜索识别码结果类型 */ export type SearchIdentificationCodeResult = { type: 'walletCode'; data: SearchIdentificationCodeItem[]; } | { type: 'normalCode'; data: SearchIdentificationCodeItem[]; }; /** * 搜索识别码项目 */ export interface SearchIdentificationCodeItem { /** 识别码ID */ id: number; /** 识别码 */ code: string; /** 识别码名称 */ name: string; /** 识别码类型 */ type: string; /** 标签 */ tag?: string; /** 是否可用 */ available: boolean; /** 余额信息 */ balance?: number; /** 有效期 */ expires_at?: string; } /** * 钱包推荐项目 */ export interface WalletRecommendItem { /** 推荐项目ID */ id: number; /** 推荐项目名称 */ name: string; /** 推荐金额 */ amount: number; /** 项目类型 */ type: string; /** 是否可用 */ available: boolean; /** 优先级 */ priority?: number; /** 其他扩展字段 */ [key: string]: any; }