修复电子凭证销毁与飞飞订单金额

This commit is contained in:
yml2213
2026-07-08 19:17:01 +08:00
parent 6647e815a8
commit 487d586492
6 changed files with 111 additions and 2 deletions
@@ -100,6 +100,7 @@ export async function destroyCallback(input: DestroyCallbackInput): Promise<{ su
oid: input.oid,
sellerId: input.sellerId || '',
reason: input.reason,
hasToken: Boolean(input.token),
})
try {
@@ -0,0 +1,37 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { normalizeDestroyCodePayload } from './payload.js'
import { resolveDestroyCallbackToken } from './destroy-code-service.js'
test('normalizeDestroyCodePayload keeps destroy callback token when provided', () => {
const payload = normalizeDestroyCodePayload({
appkey: 'ks-test',
param: {
oid: '2618901686368642',
reason: 'USER_APPLY_REFUND',
token: 'destroy-token',
etickets: [
{
id: 'KSVW9JTD4FZM4VDHKBV',
num: 1,
},
],
},
sign: 'test-sign',
signMethod: 'MD5',
timestamp: 1783499780936,
version: '1',
})
assert.equal(payload.token, 'destroy-token')
})
test('resolveDestroyCallbackToken falls back to stored voucher token', () => {
const token = resolveDestroyCallbackToken([
{ token: '' },
{ token: ' stored-token ' },
])
assert.equal(token, 'stored-token')
})
@@ -39,6 +39,7 @@ export async function handleDestroyCode(rawBody: JsonObject = {}) {
: vouchers
const callbackSellerId = params.sellerId
|| String(targetVouchers.find((voucher) => String(voucher.seller_id || '').trim())?.seller_id || '').trim()
const callbackToken = params.token || resolveDestroyCallbackToken(targetVouchers)
for (const voucher of targetVouchers) {
const status = String(voucher.status || '').trim().toUpperCase()
@@ -80,11 +81,16 @@ export async function handleDestroyCode(rawBody: JsonObject = {}) {
goodsValue: e.goodsValue,
})),
reason: params.reason,
token: callbackToken,
})
return buildIndustrySuccessResponse({ oid: normalizedOid })
}
export function resolveDestroyCallbackToken(vouchers: Array<{ token?: unknown }> = []) {
return String(vouchers.find((voucher) => String(voucher.token || '').trim())?.token || '').trim()
}
function fireDestroyCallback(input: Parameters<typeof destroyCallback>[0]) {
destroyCallback(input).catch((err) => {
logWarn('[kuaishou-industry/destroy-code]', '销毁回调异步执行异常', {
@@ -55,6 +55,7 @@ export function normalizeDestroyCodePayload(raw: JsonObject = {}) {
oid: normalizeIndustryString(param.oid),
sellerId: normalizeIndustryString(param.sellerId),
reason: normalizeIndustryString(param.reason),
token: normalizeIndustryString(param.token),
etickets: normalizeDestroyEtickets(param.etickets),
}
}