Phase 3: wire e-invoice generation into checkout email + download routes
invoiceData.ts's generateInvoicePdf()/generateCorrectionInvoicePdf() now call renderInvoiceEInvoice()/renderCorrectionInvoiceEInvoice() instead of the plain PDF renderers — both are the single wrapper every caller already goes through (orderEmail.ts's checkout attachment, and the two on-demand /invoice and /correction-invoice download routes), so this one change switches all three. Buffer.from() wraps the library's Uint8Array return value — every downstream consumer already expects a Buffer, unchanged. Imports from "@einfach-produktiv/invoicing/einvoice" (a new subpath, not the package's main entry) — @e-invoice-eu/core pulls in Node-only dependencies that broke the client bundle when reachable from the main entry, which a Client Component also imports transitively (Live Preview). See that package's own commit for the fix. Existing failure-handling is unchanged and covers this: a PDF-generation error still doesn't block the confirmation email, it just sends without the attachment and alerts admin (see orderEmail.ts) — same safety net that already existed for the plain-PDF path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+20
-6
@@ -1,11 +1,17 @@
|
||||
import { getCompanySettings, type CompanySettings } from "./payload";
|
||||
// "/einvoice" subpath, not the package's main entry — @e-invoice-eu/core
|
||||
// pulls in Node-only dependencies that break a client bundle if reachable
|
||||
// from a Client Component; see that package's own src/index.ts comment.
|
||||
// This file is server-only (Next.js Server Components/Route Handlers),
|
||||
// but importing from the main entry would still poison the bundle for
|
||||
// any Client Component that transitively imports this same package.
|
||||
import {
|
||||
renderInvoicePdf,
|
||||
renderCorrectionInvoicePdf,
|
||||
renderInvoiceEInvoice,
|
||||
renderCorrectionInvoiceEInvoice,
|
||||
type InvoiceOrder,
|
||||
type CorrectionInvoiceKind,
|
||||
type CorrectionInvoiceOrder,
|
||||
} from "@einfach-produktiv/invoicing";
|
||||
} from "@einfach-produktiv/invoicing/einvoice";
|
||||
|
||||
export type { CompanySettings };
|
||||
|
||||
@@ -24,18 +30,26 @@ export async function getSellerForInvoice(): Promise<CompanySettings | null> {
|
||||
// later always matches what they were emailed. `seller` is passed in
|
||||
// rather than fetched here, so a caller that already has it (see above)
|
||||
// doesn't fetch it twice.
|
||||
//
|
||||
// As of 2026-07-23 (e-invoicing Phase 3), this produces a Factur-X-EN16931
|
||||
// hybrid PDF/A-3 (visual PDF + embedded EN16931 XML) via
|
||||
// @einfach-produktiv/invoicing's renderInvoiceEInvoice(), not a plain PDF —
|
||||
// same visual document, but now machine-readable too. `Buffer.from()`
|
||||
// wraps the library's `Uint8Array` return value — every downstream
|
||||
// consumer (nodemailer's attachment `content`, the two on-demand download
|
||||
// routes) already expects a `Buffer`, unchanged by this switch.
|
||||
export async function generateInvoicePdf(order: InvoiceOrder, seller: CompanySettings | null): Promise<Buffer | null> {
|
||||
if (!seller) {
|
||||
console.error("generateInvoicePdf: no company-settings row found for tenant");
|
||||
return null;
|
||||
}
|
||||
return renderInvoicePdf(order, seller);
|
||||
return Buffer.from(await renderInvoiceEInvoice(order, seller));
|
||||
}
|
||||
|
||||
// Frontend-side regeneration for the "Stornorechnung/Gutschrift
|
||||
// herunterladen" download button — the real document was already
|
||||
// generated once (Payload's Orders.ts afterChange hook) and emailed; this
|
||||
// reproduces the identical PDF from the order's own stored
|
||||
// reproduces the identical PDF/A-3+XML from the order's own stored
|
||||
// correctionInvoiceNumber/correctionInvoiceIssuedAt, same "deterministic
|
||||
// regeneration, not file storage" approach as the original invoice.
|
||||
export async function generateCorrectionInvoicePdf(
|
||||
@@ -47,5 +61,5 @@ export async function generateCorrectionInvoicePdf(
|
||||
console.error("generateCorrectionInvoicePdf: no company-settings row found for tenant");
|
||||
return null;
|
||||
}
|
||||
return renderCorrectionInvoicePdf(kind, order, seller);
|
||||
return Buffer.from(await renderCorrectionInvoiceEInvoice(kind, order, seller));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user