Skip to content
Draft
Show file tree
Hide file tree
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
1,556 changes: 782 additions & 774 deletions api/api.gen.go

Large diffs are not rendered by default.

2,259 changes: 1,134 additions & 1,125 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions api/client/javascript/src/client/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5720,11 +5720,6 @@ export interface components {
* External calls always create valid lines, other line types are managed by the
* billing engine of OpenMeter. */
readonly status: components['schemas']['InvoiceLineStatus']
/** @description Discounts detailes applied to this line.
*
* New discounts can be added via the invoice's discounts API, to facilitate
* discounts that are affecting multiple lines. */
readonly discounts?: components['schemas']['InvoiceLineDiscounts']
/** @description The invoice this item belongs to. */
invoice?: components['schemas']['InvoiceReference']
/** @description The currency of this line. */
Expand Down Expand Up @@ -5781,13 +5776,25 @@ export interface components {
* @default regular
*/
readonly category?: components['schemas']['InvoiceDetailedLineCostCategory']
/** @description Discounts detailes applied to this line.
*
* New discounts can be added via the invoice's discounts API, to facilitate
* discounts that are affecting multiple lines. */
readonly discounts?: components['schemas']['InvoiceDetailedLineDiscounts']
}
/**
* @description InvoiceDetailedLineCostCategory determines if the flat fee is a regular fee due to use due to a
* commitment.
* @enum {string}
*/
InvoiceDetailedLineCostCategory: 'regular' | 'commitment'
/** @description InvoiceLineDiscounts represents the discounts applied to the invoice line by type. */
InvoiceDetailedLineDiscounts: {
/** @description Amount based discounts applied to the line.
*
* Amount based discounts are deduced from the total price of the line. */
amount?: components['schemas']['InvoiceLineAmountDiscount'][]
}
/** @description InvoiceDetailedLineRateCard represents the rate card (intent) for a flat fee line. */
InvoiceDetailedLineRateCard: {
/**
Expand Down Expand Up @@ -6083,7 +6090,7 @@ export interface components {
* @description Line status specifies the status of the line.
* @enum {string}
*/
InvoiceLineStatus: 'valid' | 'detail' | 'split'
InvoiceLineStatus: 'valid' | 'detailed' | 'split'
/** @description InvoiceLineSubscriptionReference contains the references to the subscription that this line is related to. */
InvoiceLineSubscriptionReference: {
/** @description The subscription. */
Expand Down Expand Up @@ -10950,6 +10957,8 @@ export type InvoiceAvailableActions =
export type InvoiceDetailedLine = components['schemas']['InvoiceDetailedLine']
export type InvoiceDetailedLineCostCategory =
components['schemas']['InvoiceDetailedLineCostCategory']
export type InvoiceDetailedLineDiscounts =
components['schemas']['InvoiceDetailedLineDiscounts']
export type InvoiceDetailedLineRateCard =
components['schemas']['InvoiceDetailedLineRateCard']
export type InvoiceDocumentRef = components['schemas']['InvoiceDocumentRef']
Expand Down
32 changes: 22 additions & 10 deletions api/openapi.cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16814,15 +16814,6 @@ components:
External calls always create valid lines, other line types are managed by the
billing engine of OpenMeter.
readOnly: true
discounts:
allOf:
- $ref: '#/components/schemas/InvoiceLineDiscounts'
description: |-
Discounts detailes applied to this line.

New discounts can be added via the invoice's discounts API, to facilitate
discounts that are affecting multiple lines.
readOnly: true
invoice:
allOf:
- $ref: '#/components/schemas/InvoiceReference'
Expand Down Expand Up @@ -16902,6 +16893,15 @@ components:
description: Category of the flat fee.
default: regular
readOnly: true
discounts:
allOf:
- $ref: '#/components/schemas/InvoiceDetailedLineDiscounts'
description: |-
Discounts detailes applied to this line.

New discounts can be added via the invoice's discounts API, to facilitate
discounts that are affecting multiple lines.
readOnly: true
description: InvoiceDetailedLine represents a line item that is sold to the customer as a manually added fee.
InvoiceDetailedLineCostCategory:
type: string
Expand All @@ -16911,6 +16911,18 @@ components:
description: |-
InvoiceDetailedLineCostCategory determines if the flat fee is a regular fee due to use due to a
commitment.
InvoiceDetailedLineDiscounts:
type: object
properties:
amount:
type: array
items:
$ref: '#/components/schemas/InvoiceLineAmountDiscount'
description: |-
Amount based discounts applied to the line.

Amount based discounts are deduced from the total price of the line.
description: InvoiceLineDiscounts represents the discounts applied to the invoice line by type.
InvoiceDetailedLineRateCard:
type: object
required:
Expand Down Expand Up @@ -17351,7 +17363,7 @@ components:
type: string
enum:
- valid
- detail
- detailed
- split
description: Line status specifies the status of the line.
InvoiceLineSubscriptionReference:
Expand Down
32 changes: 22 additions & 10 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17174,15 +17174,6 @@ components:
External calls always create valid lines, other line types are managed by the
billing engine of OpenMeter.
readOnly: true
discounts:
allOf:
- $ref: '#/components/schemas/InvoiceLineDiscounts'
description: |-
Discounts detailes applied to this line.

New discounts can be added via the invoice's discounts API, to facilitate
discounts that are affecting multiple lines.
readOnly: true
invoice:
allOf:
- $ref: '#/components/schemas/InvoiceReference'
Expand Down Expand Up @@ -17262,6 +17253,15 @@ components:
description: Category of the flat fee.
default: regular
readOnly: true
discounts:
allOf:
- $ref: '#/components/schemas/InvoiceDetailedLineDiscounts'
description: |-
Discounts detailes applied to this line.

New discounts can be added via the invoice's discounts API, to facilitate
discounts that are affecting multiple lines.
readOnly: true
description: InvoiceDetailedLine represents a line item that is sold to the customer as a manually added fee.
InvoiceDetailedLineCostCategory:
type: string
Expand All @@ -17271,6 +17271,18 @@ components:
description: |-
InvoiceDetailedLineCostCategory determines if the flat fee is a regular fee due to use due to a
commitment.
InvoiceDetailedLineDiscounts:
type: object
properties:
amount:
type: array
items:
$ref: '#/components/schemas/InvoiceLineAmountDiscount'
description: |-
Amount based discounts applied to the line.

Amount based discounts are deduced from the total price of the line.
description: InvoiceLineDiscounts represents the discounts applied to the invoice line by type.
InvoiceDetailedLineRateCard:
type: object
required:
Expand Down Expand Up @@ -17902,7 +17914,7 @@ components:
type: string
enum:
- valid
- detail
- detailed
- split
description: Line status specifies the status of the line.
InvoiceLineSubscriptionReference:
Expand Down
27 changes: 25 additions & 2 deletions api/spec/src/billing/invoices/invoice.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ enum InvoiceLineTypes {
/**
* Line status specifies the status of the line.
*/
// TODO[v2]: Deprecate this type altogether
@friendlyName("InvoiceLineStatus")
enum InvoiceLineStatus {
/**
Expand All @@ -474,7 +475,7 @@ enum InvoiceLineStatus {
* The line is a detail line which is used to detail the individual
* charges and discounts of a valid line.
*/
detail: "detail",
detailed: "detailed",

/**
* The line has been split into multiple valid lines due to progressive
Expand Down Expand Up @@ -762,7 +763,7 @@ model InvoiceDetailedLineRateCard {
*/
@friendlyName("InvoiceDetailedLine")
model InvoiceDetailedLine {
...OmitProperties<InvoiceLineBase, "type">;
...OmitProperties<InvoiceLineBase, "type" | "discounts">;

/**
* Type of the line.
Expand Down Expand Up @@ -804,6 +805,28 @@ model InvoiceDetailedLine {
*/
@visibility(Lifecycle.Read)
category?: InvoiceDetailedLineCostCategory = InvoiceDetailedLineCostCategory.regular;

/**
* Discounts detailes applied to this line.
*
* New discounts can be added via the invoice's discounts API, to facilitate
* discounts that are affecting multiple lines.
*/
@visibility(Lifecycle.Read)
discounts?: InvoiceDetailedLineDiscounts;
}

/**
* InvoiceLineDiscounts represents the discounts applied to the invoice line by type.
*/
@friendlyName("InvoiceDetailedLineDiscounts")
model InvoiceDetailedLineDiscounts {
/**
* Amount based discounts applied to the line.
*
* Amount based discounts are deduced from the total price of the line.
*/
amount?: InvoiceLineAmountDiscount[];
}

/**
Expand Down
28 changes: 14 additions & 14 deletions openmeter/app/stripe/entity/app/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ func (a App) createInvoice(ctx context.Context, invoice billing.Invoice) (*billi
// Add lines to the Stripe invoice
var stripeLineAdd []*stripe.InvoiceItemParams

leafLines := invoice.GetLeafLinesWithConsolidatedTaxBehavior()
leafLines := invoice.GetDetailedLinesWithConsolidatedTaxBehavior()

// Iterate over the leaf lines
for _, line := range leafLines {
// Add discounts for line if any
for _, discount := range line.Discounts.Amount {
for _, discount := range line.AmountDiscounts {
stripeLineAdd = append(stripeLineAdd, getDiscountStripeAddInvoiceItemParams(calculator, line, discount, stripeCustomerData.StripeCustomerID))
}

Expand Down Expand Up @@ -304,7 +304,7 @@ func (a App) updateInvoice(ctx context.Context, invoice billing.Invoice) (*billi
stripeLinesRemove []string
)

leafLines := invoice.GetLeafLinesWithConsolidatedTaxBehavior()
leafLines := invoice.GetDetailedLinesWithConsolidatedTaxBehavior()

// Helper to get a Stripe line item by ID
stripeLinesByID := make(map[string]*stripe.InvoiceLineItem)
Expand All @@ -319,7 +319,7 @@ func (a App) updateInvoice(ctx context.Context, invoice billing.Invoice) (*billi

// Iterate over the leaf lines
for _, line := range leafLines {
amountDiscountsById, err := line.Discounts.Amount.GetByID()
amountDiscountsById, err := line.AmountDiscounts.GetByID()
if err != nil {
return nil, fmt.Errorf("failed to get amount discounts by ID: %w", err)
}
Expand Down Expand Up @@ -452,7 +452,7 @@ func sortInvoiceLines[K StripeInvoiceLineOperationParams](stripeLineAdd []*K) {
// getDiscountStripeUpdateInvoiceItemParams returns the Stripe line item for a discount
func getDiscountStripeUpdateInvoiceItemParams(
calculator StripeCalculator,
line *billing.Line,
line billing.DetailedLine,
discount billing.AmountLineDiscountManaged,
stripeLine *stripe.InvoiceLineItem,
) *stripeclient.StripeInvoiceItemWithID {
Expand All @@ -463,7 +463,7 @@ func getDiscountStripeUpdateInvoiceItemParams(
}

// getDiscountStripeInvoiceItemParams returns the Stripe line item for a discount
func getDiscountStripeInvoiceItemParams(calculator StripeCalculator, line *billing.Line, discount billing.AmountLineDiscountManaged) *stripe.InvoiceItemParams {
func getDiscountStripeInvoiceItemParams(calculator StripeCalculator, line billing.DetailedLine, discount billing.AmountLineDiscountManaged) *stripe.InvoiceItemParams {
name := getDiscountLineName(line, discount)
period := getPeriod(line)

Expand All @@ -480,14 +480,14 @@ func getDiscountStripeInvoiceItemParams(calculator StripeCalculator, line *billi
return applyTaxSettingsToInvoiceItem(addParams, line)
}

func getDiscountStripeAddInvoiceItemParams(calculator StripeCalculator, line *billing.Line, discount billing.AmountLineDiscountManaged, stripeCustomerID string) *stripe.InvoiceItemParams {
func getDiscountStripeAddInvoiceItemParams(calculator StripeCalculator, line billing.DetailedLine, discount billing.AmountLineDiscountManaged, stripeCustomerID string) *stripe.InvoiceItemParams {
params := getDiscountStripeInvoiceItemParams(calculator, line, discount)
// Customer is required for adds
params.Customer = stripe.String(stripeCustomerID)
return params
}

func applyTaxSettingsToInvoiceItem(add *stripe.InvoiceItemParams, line *billing.Line) *stripe.InvoiceItemParams {
func applyTaxSettingsToInvoiceItem(add *stripe.InvoiceItemParams, line billing.DetailedLine) *stripe.InvoiceItemParams {
if line.TaxConfig != nil && !lo.IsEmpty(line.TaxConfig) {
if line.TaxConfig.Behavior != nil {
add.TaxBehavior = getStripeTaxBehavior(line.TaxConfig.Behavior)
Expand All @@ -504,7 +504,7 @@ func applyTaxSettingsToInvoiceItem(add *stripe.InvoiceItemParams, line *billing.
// getStripeUpdateInvoiceItemParams returns the Stripe update line params
func getStripeUpdateInvoiceItemParams(
calculator StripeCalculator,
line *billing.Line,
line billing.DetailedLine,
stripeLine *stripe.InvoiceLineItem,
) *stripeclient.StripeInvoiceItemWithID {
return &stripeclient.StripeInvoiceItemWithID{
Expand All @@ -514,7 +514,7 @@ func getStripeUpdateInvoiceItemParams(
}

// getStripeAddLinesLineParams returns the Stripe line item
func getStripeInvoiceItemParams(line *billing.Line, calculator StripeCalculator) *stripe.InvoiceItemParams {
func getStripeInvoiceItemParams(line billing.DetailedLine, calculator StripeCalculator) *stripe.InvoiceItemParams {
description := getLineName(line)
period := getPeriod(line)
amount := line.Totals.Amount
Expand Down Expand Up @@ -551,22 +551,22 @@ func getStripeInvoiceItemParams(line *billing.Line, calculator StripeCalculator)
}

// getStripeAddInvoiceItemParams returns the Stripe line item
func getStripeAddInvoiceItemParams(line *billing.Line, calculator StripeCalculator, stripeCustomerID string) *stripe.InvoiceItemParams {
func getStripeAddInvoiceItemParams(line billing.DetailedLine, calculator StripeCalculator, stripeCustomerID string) *stripe.InvoiceItemParams {
params := getStripeInvoiceItemParams(line, calculator)
params.Customer = stripe.String(stripeCustomerID)
return params
}

// getPeriod returns the period
func getPeriod(line *billing.Line) *stripe.InvoiceItemPeriodParams {
func getPeriod(line billing.DetailedLine) *stripe.InvoiceItemPeriodParams {
return &stripe.InvoiceItemPeriodParams{
Start: lo.ToPtr(line.Period.Start.Unix()),
End: lo.ToPtr(line.Period.End.Unix()),
}
}

// getDiscountLineName returns the line name
func getDiscountLineName(line *billing.Line, discount billing.AmountLineDiscountManaged) string {
func getDiscountLineName(line billing.DetailedLine, discount billing.AmountLineDiscountManaged) string {
name := line.Name
if discount.Description != nil {
name = fmt.Sprintf("%s (%s)", name, *discount.Description)
Expand All @@ -576,7 +576,7 @@ func getDiscountLineName(line *billing.Line, discount billing.AmountLineDiscount
}

// getLineName returns the line name
func getLineName(line *billing.Line) string {
func getLineName(line billing.DetailedLine) string {
name := line.Name
if line.Description != nil {
name = fmt.Sprintf("%s (%s)", name, *line.Description)
Expand Down
Loading
Loading