Updated project changes
This commit is contained in:
@@ -38,8 +38,24 @@ export default async function handler(req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
const { invoiceId, customerEmail } = req.body || {};
|
||||
const invoice = INVOICES[invoiceId];
|
||||
const { invoiceId, customerEmail, fallback } = req.body || {};
|
||||
|
||||
// The static map is authoritative for seed invoices (amount can't be
|
||||
// tampered). DEMO ONLY: invoices the owner created live in the browser's
|
||||
// localStorage, so the server doesn't know them — accept the client's
|
||||
// amount/title as a fallback for those. In production every invoice would
|
||||
// be resolved from the billing DB here and this fallback removed.
|
||||
let invoice = INVOICES[invoiceId];
|
||||
if (!invoice && fallback) {
|
||||
const amount = Number(fallback.amount);
|
||||
if (Number.isInteger(amount) && amount > 0) {
|
||||
invoice = {
|
||||
title: String(fallback.title || 'Payment').slice(0, 200),
|
||||
amount,
|
||||
currency: (fallback.currency || 'usd').toLowerCase(),
|
||||
};
|
||||
}
|
||||
}
|
||||
if (!invoice) {
|
||||
return res.status(404).json({ error: `Unknown invoice: ${invoiceId}` });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user