diff --git a/billing/invoice/service.go b/billing/invoice/service.go index 15b4fb896..d7b0d0578 100644 --- a/billing/invoice/service.go +++ b/billing/invoice/service.go @@ -363,6 +363,10 @@ func (s *Service) upsert(ctx context.Context, customerID string, existingInvoice.HostedURL = stripeInvoice.HostedInvoiceURL updateNeeded = true } + if existingInvoice.Amount != stripeInvoice.Total { + existingInvoice.Amount = stripeInvoice.Total + updateNeeded = true + } if updateNeeded { if _, err := s.repository.UpdateByID(ctx, *existingInvoice); err != nil { diff --git a/internal/store/postgres/billing_invoice_repository.go b/internal/store/postgres/billing_invoice_repository.go index c1d36d791..f80d4f383 100644 --- a/internal/store/postgres/billing_invoice_repository.go +++ b/internal/store/postgres/billing_invoice_repository.go @@ -297,6 +297,9 @@ func (r BillingInvoiceRepository) UpdateByID(ctx context.Context, toUpdate invoi if toUpdate.HostedURL != "" { updateRecord["hosted_url"] = toUpdate.HostedURL } + // Do not guard this with `!= 0` like the fields above: an invoice can + // be credited down to zero, and that zero must be saved. + updateRecord["amount"] = toUpdate.Amount query, params, err := dialect.Update(TABLE_BILLING_INVOICES).Set(updateRecord).Where(goqu.Ex{ "id": toUpdate.ID,