41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
import { $fetch } from 'ofetch'
|
|
import { createError, defineEventHandler, getHeader, getCookie, getQuery } from 'h3'
|
|
import { useRuntimeConfig } from '#imports'
|
|
import { getTenantFromContext } from '../../utils/tenant'
|
|
|
|
/**
|
|
* 查询支付渠道侧的状态(已支付则后端顺带修复本地订单状态)
|
|
* GET /api/tender/pay-status?orderNo=xxx
|
|
* 代理到 mp-api /api/hjc/order/pay-status/{orderNo};需登录态。
|
|
*
|
|
* 这是 hjc-web **唯一**的支付确认通道:它向渠道查单,以渠道侧的结论为准。
|
|
* 后端按订单的 pay_method 自动打到微信或支付宝,**前端不需要传渠道**。
|
|
* 不要退回 mark-paid——那个接口不查单,点一下就能把订单置为已支付(见 ADR 0010)。
|
|
*
|
|
* 约定:原样透传 ApiResult{code,message,data},由前端按 code 判定登录态与业务失败。
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const config = useRuntimeConfig()
|
|
const ctx = getTenantFromContext(event, config)
|
|
const { orderNo } = getQuery(event)
|
|
const cookieToken = getCookie(event, 'hjc_token')
|
|
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
|
|
|
try {
|
|
return await $fetch(`/hjc/order/pay-status/${encodeURIComponent(String(orderNo ?? ''))}`, {
|
|
baseURL: config.public.modulesApiBase,
|
|
method: 'GET',
|
|
headers: {
|
|
TenantId: ctx.tenantId,
|
|
...(auth ? { Authorization: auth } : {})
|
|
},
|
|
query: { TenantId: ctx.tenantId }
|
|
})
|
|
} catch (error: any) {
|
|
throw createError({
|
|
statusCode: error?.statusCode || error?.response?.status || 502,
|
|
statusMessage: error?.statusMessage || 'Failed to query pay status'
|
|
})
|
|
}
|
|
})
|