Skip to content

Commit

Permalink
feat(invoice): save number at finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike committed Jan 21, 2025
1 parent b26951c commit 4a69be5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions openmeter/billing/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func NewUpsertInvoiceResult() *UpsertInvoiceResult {
}

type FinalizeInvoiceResult struct {
invoiceNumber string
paymentExternalID string
}

Expand All @@ -89,8 +90,12 @@ func (f *FinalizeInvoiceResult) SetPaymentExternalID(paymentExternalID string) {
f.paymentExternalID = paymentExternalID
}

func (f *FinalizeInvoiceResult) SetInvoiceNumber(number string) {
f.SetInvoiceNumber(number)
func (u *FinalizeInvoiceResult) GetInvoiceNumber() (string, bool) {
return u.invoiceNumber, u.invoiceNumber != ""
}

func (f *FinalizeInvoiceResult) SetInvoiceNumber(invoiceNumber string) {
f.invoiceNumber = invoiceNumber
}

type InvoicingApp interface {
Expand Down
4 changes: 4 additions & 0 deletions openmeter/billing/service/invoicestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ func (m *InvoiceStateMachine) finalizeInvoice(ctx context.Context) error {
if paymentExternalID, ok := results.GetPaymentExternalID(); ok {
m.Invoice.ExternalIDs.Payment = paymentExternalID
}

if invoiceNumber, ok := results.GetInvoiceNumber(); ok {
m.Invoice.Number = lo.ToPtr(invoiceNumber)
}
}

return nil
Expand Down

0 comments on commit 4a69be5

Please sign in to comment.