Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions internal/invoice/invoice.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading