简化履约匹配并支持mock订单测试

This commit is contained in:
yml
2026-05-27 12:55:44 +08:00
parent e8010728a4
commit dd6776c4e4
21 changed files with 1892 additions and 683 deletions
@@ -10,6 +10,7 @@ import {
import { normalizeOpen91CreatePayload } from '../../open-91/payload.js'
import { buildOpen91OutTradeNo } from '../../open-91/response.js'
import { createHttpError } from '../../../utils/http.js'
import { parseAmountToFen } from '../../../utils/money.js'
import { nowIso } from '../../../utils/time.js'
import type { OrderItemRow, OrderRow } from '../../../types/repository/rows.js'
@@ -21,6 +22,7 @@ type JsonObject = Record<string, any>
export function buildOpen91SourceEvent(payload: JsonObject = {}, config: JsonObject = {}) {
const normalized = normalizeOpen91CreatePayload(payload)
const productNo = normalized.productNo
const maxAmountFen = parseAmountToFen(normalized.maxAmount)
return {
provider: OPEN_91_PROVIDER,
@@ -33,7 +35,7 @@ export function buildOpen91SourceEvent(payload: JsonObject = {}, config: JsonObj
buyerId: '',
buyerName: '',
receiverContact: '',
totalAmount: 0,
totalAmount: maxAmountFen,
currency: 'CNY',
paidAt: nowIso(),
rawPayload: {
@@ -54,11 +56,14 @@ export function buildOpen91SourceEvent(payload: JsonObject = {}, config: JsonObj
source: OPEN_91_PROVIDER,
orderNo: normalized.orderNo,
productNo,
maxAmount: normalized.maxAmount,
},
snapshot: {
source: OPEN_91_PROVIDER,
orderNo: normalized.orderNo,
productNo,
maxAmount: normalized.maxAmount,
maxAmountFen,
externalItemId: productNo,
externalSkuCode: productNo,
externalSkuName: productNo,
@@ -95,7 +100,7 @@ export async function upsertOpen91PendingOrder(payload: JsonObject = {}, config:
buyerId: '',
buyerName: '',
receiverContact: '',
totalAmount: 0,
totalAmount: event.totalAmount,
currency: 'CNY',
rawPayloadJson,
paidAt: existing?.paid_at || now,