Skip to content

Commit

Permalink
feat(invoice): commitment charge
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike committed Dec 20, 2024
1 parent 1ad5312 commit 93a8ab6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 10 additions & 1 deletion openmeter/app/stripe/entity/app/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,19 @@ func getStripeAddLinesLineParams(isInteger bool, line *billing.Line, calculator
}
}

amount := line.Totals.Amount

// Handle usage based commitments like minimum spend
if amount.IsZero() {
// ChargesTotal is the amount of value of the line that are due to additional charges.
// If the line is a commitment we use the total charges.
amount = line.Totals.ChargesTotal
}

// Otherwise we add the calculated total with with quantity one
return &stripe.InvoiceAddLinesLineParams{
Description: lo.ToPtr(name),
Amount: lo.ToPtr(calculator.RoundToAmount(line.Totals.Amount)),
Amount: lo.ToPtr(calculator.RoundToAmount(amount)),
Quantity: lo.ToPtr(int64(1)),
Period: period,
Metadata: map[string]string{
Expand Down
3 changes: 1 addition & 2 deletions test/app/stripe/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ func (s *StripeInvoiceTestSuite) TestComplexInvoice() {
},
},
{
// FIXME(pmarton): should be 162300
Amount: lo.ToPtr(int64(0)),
Amount: lo.ToPtr(int64(162300)),
Description: lo.ToPtr("UBP - Tiered volume: minimum spend"),
Period: &stripe.InvoiceAddLinesLinePeriodParams{
// TODO: check rounding
Expand Down

0 comments on commit 93a8ab6

Please sign in to comment.