Webhook 增加订单号查询
This commit is contained in:
@@ -3,6 +3,10 @@ import crypto from 'node:crypto'
|
||||
import { runtimeConfig } from '../../config/runtime.js'
|
||||
import { createWebhookEvent, updateWebhookEvent } from '../../repositories/webhook-event-repo.js'
|
||||
import { enrichAgisoXianyuTradeOrder } from '../platforms/agiso/xianyu/order-detail-service.js'
|
||||
import {
|
||||
extractAgisoTradePayload,
|
||||
resolveAgisoTradePlatformOrderId,
|
||||
} from './agiso-trade-parsing.js'
|
||||
import { upsertOrderFromWebhook } from './order-service.js'
|
||||
import { hasConfiguredOrderItems } from './product-match-service.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
@@ -305,7 +309,7 @@ function parseAgisoTradeRequest(requestLike) {
|
||||
const query = normalizeRecord(requestLike.query)
|
||||
const body = normalizeRecord(requestLike.body)
|
||||
const rawJson = String(body.json || '').trim()
|
||||
const payload = rawJson ? parsePayloadJson(rawJson) : body
|
||||
const payload = rawJson ? parsePayloadJson(rawJson) : extractAgisoTradePayload(body)
|
||||
const timestamp = String(query.timestamp || '').trim()
|
||||
const sign = String(query.sign || '').trim().toLowerCase()
|
||||
const provider = 'agiso'
|
||||
@@ -323,19 +327,7 @@ function parseAgisoTradeRequest(requestLike) {
|
||||
const shop = resolveShop(payload)
|
||||
const eventType = resolveEventType(query.aopic, payload)
|
||||
const signatureValid = verifyAgisoSignature({ rawJson, timestamp, sign })
|
||||
const itemSources = extractOrderItemSources(payload)
|
||||
const firstItem = itemSources[0] || {}
|
||||
const platformOrderId = pickFirstNonEmpty([
|
||||
payload.biz_order_id,
|
||||
payload.Tid,
|
||||
payload.tid,
|
||||
payload.Oid,
|
||||
payload.oid,
|
||||
payload.order_id,
|
||||
payload.orderId,
|
||||
firstItem.Oid,
|
||||
firstItem.oid,
|
||||
])
|
||||
const platformOrderId = resolveAgisoTradePlatformOrderId(payload)
|
||||
|
||||
return {
|
||||
provider,
|
||||
@@ -663,25 +655,6 @@ function normalizeOrderItems(payload) {
|
||||
})
|
||||
}
|
||||
|
||||
function extractOrderItemSources(payload) {
|
||||
const candidates = [
|
||||
payload.items,
|
||||
payload.Items,
|
||||
payload.orders,
|
||||
payload.Orders,
|
||||
payload.order_list,
|
||||
payload.OrderList,
|
||||
]
|
||||
|
||||
for (const current of candidates) {
|
||||
if (Array.isArray(current) && current.length > 0) {
|
||||
return current
|
||||
}
|
||||
}
|
||||
|
||||
return [payload]
|
||||
}
|
||||
|
||||
function resolveBusinessPlatform(rawPlatform) {
|
||||
const normalized = normalizePlatformKey(rawPlatform)
|
||||
|
||||
@@ -910,6 +883,10 @@ function isPlainObject(value) {
|
||||
}
|
||||
|
||||
function safeParseJson(rawValue) {
|
||||
if (rawValue && typeof rawValue === 'object' && !Array.isArray(rawValue)) {
|
||||
return rawValue
|
||||
}
|
||||
|
||||
const normalized = String(rawValue || '').trim()
|
||||
|
||||
if (!normalized) {
|
||||
|
||||
Reference in New Issue
Block a user