60 行
1.4 KiB
JavaScript
60 行
1.4 KiB
JavaScript
function normalizeAmount(value) {
|
|
if (value == null) {
|
|
return null;
|
|
}
|
|
|
|
const numberValue = Number(value);
|
|
if (!Number.isFinite(numberValue)) {
|
|
return null;
|
|
}
|
|
|
|
return numberValue.toFixed(2);
|
|
}
|
|
|
|
async function runMockVerification({ invoice }) {
|
|
const remarks = String(invoice.remarks ?? "").toLowerCase();
|
|
const invoiceCode = String(invoice.invoice_code ?? "").toUpperCase();
|
|
const invoiceNumber = String(invoice.invoice_number ?? "").toUpperCase();
|
|
|
|
if (remarks.includes("verify-error") || invoiceNumber.includes("ERR")) {
|
|
return {
|
|
status: "error",
|
|
resultCode: "mock_transport_error",
|
|
resultMessage: "mock provider transport error",
|
|
payload: {
|
|
provider: "mock",
|
|
marker: "verify-error",
|
|
},
|
|
};
|
|
}
|
|
|
|
if (remarks.includes("verify-fail") || invoiceCode.includes("FAIL") || invoiceNumber.includes("FAIL")) {
|
|
return {
|
|
status: "failed",
|
|
resultCode: "invoice_mismatch",
|
|
resultMessage: "invoice metadata mismatch",
|
|
payload: {
|
|
provider: "mock",
|
|
matched: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
return {
|
|
status: "passed",
|
|
resultCode: "verified",
|
|
resultMessage: "invoice verified",
|
|
payload: {
|
|
provider: "mock",
|
|
matched: true,
|
|
invoiceCode: invoice.invoice_code ?? null,
|
|
invoiceNumber: invoice.invoice_number ?? null,
|
|
totalAmount: normalizeAmount(invoice.total_amount),
|
|
},
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
runMockVerification,
|
|
};
|