From d7be602a757cdfeb5eab274936c9e46542ab7cb1 Mon Sep 17 00:00:00 2001 From: Falytom Date: Sun, 13 Sep 2026 08:12:26 +0100 Subject: [PATCH] feat: add invoice generation for payment transactions Closes #62 --- internal/invoice/invoice.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 internal/invoice/invoice.go diff --git a/internal/invoice/invoice.go b/internal/invoice/invoice.go new file mode 100644 index 0000000..f5cbf83 --- /dev/null +++ b/internal/invoice/invoice.go @@ -0,0 +1,33 @@ +package invoice + +import "fmt" + +// LineItem is a single billed item on an invoice. +type LineItem struct { + Description string + AmountCents int64 +} + +// Invoice represents a generated invoice for a payment transaction. +type Invoice struct { + Number string + Items []LineItem +} + +// Generate builds an Invoice for the given transaction ID from a set of +// line items, auto-numbering it using the transaction ID. +func Generate(transactionID string, items []LineItem) Invoice { + return Invoice{ + Number: fmt.Sprintf("INV-%s", transactionID), + Items: items, + } +} + +// Total returns the sum of all line item amounts, in cents. +func (i Invoice) Total() int64 { + var total int64 + for _, item := range i.Items { + total += item.AmountCents + } + return total +}