21 lines
1.1 KiB
TypeScript
21 lines
1.1 KiB
TypeScript
import { notificationTransaction } from "@/goldMiner/merchant";
|
|
import { confirmMerchantTransaction } from "@/goldMiner/legacyPayment";
|
|
import { fulfillOrder } from "@/goldMiner/payment";
|
|
|
|
export default async function (ctx: FunctionContext) {
|
|
try {
|
|
// Some Laf gateways expose rawBody; a parsed body is never used after successful raw verification.
|
|
const input = (ctx.request as any)?.rawBody ?? ctx.rawBody;
|
|
const raw = Buffer.isBuffer(input) ? input.toString("utf8") : typeof input === "string" ? input : JSON.stringify(ctx.body);
|
|
const transaction = notificationTransaction(raw, ctx.headers);
|
|
const order = await confirmMerchantTransaction(transaction, "merchant_notify");
|
|
// Confirmation is durable; timer/login/query can retry entitlement delivery after this acknowledgement.
|
|
try { await fulfillOrder(order.outTradeNo); } catch { console.error("goldMiner merchant entitlement retry", order._id); }
|
|
ctx.response?.status(200);
|
|
return { code: "SUCCESS", message: "成功" };
|
|
} catch {
|
|
ctx.response?.status(500);
|
|
return { code: "FAIL", message: "支付通知验证或保存失败" };
|
|
}
|
|
}
|