Skip to content
Merged
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,895 changes: 956 additions & 939 deletions api/api.gen.go

Large diffs are not rendered by default.

1,863 changes: 940 additions & 923 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions api/client/javascript/src/client/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4752,6 +4752,11 @@ export interface components {
/** @description Invoice a gathering invoice */
readonly invoice?: components['schemas']['InvoiceAvailableActionInvoiceDetails']
}
/**
* @description Reason code.
* @enum {string}
*/
InvoiceDiscountReason: 'maximum_spend' | 'ratecard_discount'
/** @description InvoiceDocumentRef is used to describe a reference to an existing document (invoice). */
InvoiceDocumentRef: components['schemas']['CreditNoteOriginalInvoiceRef']
/**
Expand Down Expand Up @@ -5108,9 +5113,13 @@ export interface components {
*/
readonly id: string
/** @description Reason code. */
readonly code?: string
readonly reason: components['schemas']['InvoiceDiscountReason']
/** @description Text description as to why the discount was applied. */
readonly description?: string
/** @description External IDs of the invoice in other apps such as Stripe. */
readonly externalIds?: components['schemas']['InvoiceLineAppExternalIds']
/** @description The discount from the rate card this discount is based on. */
readonly rateCardDiscount?: components['schemas']['Discount']
/**
* Amount in the currency of the invoice
* @description Fixed discount amount to apply (calculated if percent present).
Expand All @@ -5121,10 +5130,6 @@ export interface components {
* @enum {string}
*/
type: 'amount'
/** @description The discount from the rate card this discount is based on. */
readonly rateCardDiscount?: components['schemas']['Discount']
/** @description External IDs of the invoice in other apps such as Stripe. */
readonly externalIds?: components['schemas']['InvoiceLineAppExternalIds']
}
/** @description InvoiceLineDiscountUsage represents an usage-based discount applied to the line.
*
Expand Down Expand Up @@ -5157,9 +5162,13 @@ export interface components {
*/
readonly id: string
/** @description Reason code. */
readonly code?: string
readonly reason: components['schemas']['InvoiceDiscountReason']
/** @description Text description as to why the discount was applied. */
readonly description?: string
/** @description External IDs of the invoice in other apps such as Stripe. */
readonly externalIds?: components['schemas']['InvoiceLineAppExternalIds']
/** @description The discount from the rate card this discount is based on. */
readonly rateCardDiscount?: components['schemas']['Discount']
/**
* Usage quantity in the unit of the underlying meter
* @description The usage to apply.
Expand All @@ -5177,8 +5186,6 @@ export interface components {
* @enum {string}
*/
type: 'usage'
/** @description The discount from the rate card this discount is based on. */
readonly rateCardDiscount?: components['schemas']['Discount']
}
/**
* @description InvoiceLineManagedBy specifies who manages the line.
Expand Down Expand Up @@ -9030,6 +9037,8 @@ export type InvoiceAvailableActionInvoiceDetails =
components['schemas']['InvoiceAvailableActionInvoiceDetails']
export type InvoiceAvailableActions =
components['schemas']['InvoiceAvailableActions']
export type InvoiceDiscountReason =
components['schemas']['InvoiceDiscountReason']
export type InvoiceDocumentRef = components['schemas']['InvoiceDocumentRef']
export type InvoiceDocumentRefType =
components['schemas']['InvoiceDocumentRefType']
Expand Down
53 changes: 34 additions & 19 deletions api/openapi.cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13813,6 +13813,12 @@ components:
description: Invoice a gathering invoice
readOnly: true
description: InvoiceAvailableActions represents the actions that can be performed on the invoice.
InvoiceDiscountReason:
type: string
enum:
- maximum_spend
- ratecard_discount
description: Reason code.
InvoiceDocumentRef:
type: object
allOf:
Expand Down Expand Up @@ -14276,6 +14282,7 @@ components:
- createdAt
- updatedAt
- id
- reason
- amount
- type
properties:
Expand Down Expand Up @@ -14306,14 +14313,25 @@ components:
description: ID of the charge or discount.
example: 01G65Z755AFWAKHE12NY0CQ9FH
readOnly: true
code:
type: string
reason:
allOf:
- $ref: '#/components/schemas/InvoiceDiscountReason'
description: Reason code.
readOnly: true
description:
type: string
description: Text description as to why the discount was applied.
readOnly: true
externalIds:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIds'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
rateCardDiscount:
allOf:
- $ref: '#/components/schemas/Discount'
description: The discount from the rate card this discount is based on.
readOnly: true
amount:
allOf:
- $ref: '#/components/schemas/Numeric'
Expand All @@ -14326,23 +14344,14 @@ components:
- amount
description: The type of the discount.
readOnly: true
rateCardDiscount:
allOf:
- $ref: '#/components/schemas/Discount'
description: The discount from the rate card this discount is based on.
readOnly: true
externalIds:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIds'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
description: InvoiceLineDiscountAmount represents an amount deducted from the line, and will be applied before taxes.
InvoiceLineDiscountUsage:
type: object
required:
- createdAt
- updatedAt
- id
- reason
- quantity
- type
properties:
Expand Down Expand Up @@ -14373,14 +14382,25 @@ components:
description: ID of the charge or discount.
example: 01G65Z755AFWAKHE12NY0CQ9FH
readOnly: true
code:
type: string
reason:
allOf:
- $ref: '#/components/schemas/InvoiceDiscountReason'
description: Reason code.
readOnly: true
description:
type: string
description: Text description as to why the discount was applied.
readOnly: true
externalIds:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIds'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
rateCardDiscount:
allOf:
- $ref: '#/components/schemas/Discount'
description: The discount from the rate card this discount is based on.
readOnly: true
quantity:
allOf:
- $ref: '#/components/schemas/Numeric'
Expand All @@ -14402,11 +14422,6 @@ components:
- usage
description: The type of the discount.
readOnly: true
rateCardDiscount:
allOf:
- $ref: '#/components/schemas/Discount'
description: The discount from the rate card this discount is based on.
readOnly: true
description: |-
InvoiceLineDiscountUsage represents an usage-based discount applied to the line.

Expand Down
53 changes: 34 additions & 19 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13887,6 +13887,12 @@ components:
description: Invoice a gathering invoice
readOnly: true
description: InvoiceAvailableActions represents the actions that can be performed on the invoice.
InvoiceDiscountReason:
type: string
enum:
- maximum_spend
- ratecard_discount
description: Reason code.
InvoiceDocumentRef:
type: object
allOf:
Expand Down Expand Up @@ -14350,6 +14356,7 @@ components:
- createdAt
- updatedAt
- id
- reason
- amount
- type
properties:
Expand Down Expand Up @@ -14380,14 +14387,25 @@ components:
description: ID of the charge or discount.
example: 01G65Z755AFWAKHE12NY0CQ9FH
readOnly: true
code:
type: string
reason:
allOf:
- $ref: '#/components/schemas/InvoiceDiscountReason'
description: Reason code.
readOnly: true
description:
type: string
description: Text description as to why the discount was applied.
readOnly: true
externalIds:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIds'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
rateCardDiscount:
allOf:
- $ref: '#/components/schemas/Discount'
description: The discount from the rate card this discount is based on.
readOnly: true
amount:
allOf:
- $ref: '#/components/schemas/Numeric'
Expand All @@ -14400,23 +14418,14 @@ components:
- amount
description: The type of the discount.
readOnly: true
rateCardDiscount:
allOf:
- $ref: '#/components/schemas/Discount'
description: The discount from the rate card this discount is based on.
readOnly: true
externalIds:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIds'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
description: InvoiceLineDiscountAmount represents an amount deducted from the line, and will be applied before taxes.
InvoiceLineDiscountUsage:
type: object
required:
- createdAt
- updatedAt
- id
- reason
- quantity
- type
properties:
Expand Down Expand Up @@ -14447,14 +14456,25 @@ components:
description: ID of the charge or discount.
example: 01G65Z755AFWAKHE12NY0CQ9FH
readOnly: true
code:
type: string
reason:
allOf:
- $ref: '#/components/schemas/InvoiceDiscountReason'
description: Reason code.
readOnly: true
description:
type: string
description: Text description as to why the discount was applied.
readOnly: true
externalIds:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIds'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
rateCardDiscount:
allOf:
- $ref: '#/components/schemas/Discount'
description: The discount from the rate card this discount is based on.
readOnly: true
quantity:
allOf:
- $ref: '#/components/schemas/Numeric'
Expand All @@ -14476,11 +14496,6 @@ components:
- usage
description: The type of the discount.
readOnly: true
rateCardDiscount:
allOf:
- $ref: '#/components/schemas/Discount'
description: The discount from the rate card this discount is based on.
readOnly: true
description: |-
InvoiceLineDiscountUsage represents an usage-based discount applied to the line.

Expand Down
41 changes: 22 additions & 19 deletions api/spec/src/billing/invoices/discounts.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import "@typespec/openapi3";

namespace Invoices;

/**
* Reason code.
*/
@friendlyName("InvoiceDiscountReason")
enum InvoiceDiscountReason {
maximumSpend: "maximum_spend",
ratecardDiscount: "ratecard_discount",
}

/**
* InvoiceDiscountBase represents a charge or discount that can be applied to a line or the entire invoice.
*/
Expand All @@ -21,13 +30,25 @@ model InvoiceDiscountBase {
* Reason code.
*/
@visibility(Lifecycle.Read)
code?: string;
reason: InvoiceDiscountReason;

/**
* Text description as to why the discount was applied.
*/
@visibility(Lifecycle.Read)
description?: string;

/**
* External IDs of the invoice in other apps such as Stripe.
*/
@visibility(Lifecycle.Read)
externalIds?: InvoiceLineAppExternalIds;

/**
* The discount from the rate card this discount is based on.
*/
@visibility(Lifecycle.Read)
rateCardDiscount?: OpenMeter.ProductCatalog.Discount;
}

/**
Expand Down Expand Up @@ -79,12 +100,6 @@ model InvoiceLineDiscountUsage {
*/
@visibility(Lifecycle.Read)
type: InvoiceLineDiscountType.usage;

/**
* The discount from the rate card this discount is based on.
*/
@visibility(Lifecycle.Read)
rateCardDiscount?: OpenMeter.ProductCatalog.Discount;
}

/**
Expand All @@ -106,16 +121,4 @@ model InvoiceLineDiscountAmount {
*/
@visibility(Lifecycle.Read)
type: InvoiceLineDiscountType.amount;

/**
* The discount from the rate card this discount is based on.
*/
@visibility(Lifecycle.Read)
rateCardDiscount?: OpenMeter.ProductCatalog.Discount;

/**
* External IDs of the invoice in other apps such as Stripe.
*/
@visibility(Lifecycle.Read)
externalIds?: InvoiceLineAppExternalIds;
}
1 change: 1 addition & 0 deletions openmeter/billing/adapter/invoicelinemapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func (a *adapter) mapInvoiceLineWithoutReferences(dbLine *db.BillingInvoiceLine)
UpdatedAt: discount.UpdatedAt.In(time.UTC),
DeletedAt: convert.TimePtrIn(discount.DeletedAt, time.UTC),

Reason: discount.Reason,
Amount: discount.Amount,
Description: discount.Description,
ChildUniqueReferenceID: discount.ChildUniqueReferenceID,
Expand Down
1 change: 1 addition & 0 deletions openmeter/billing/adapter/invoicelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (a *adapter) UpsertInvoiceLines(ctx context.Context, inputIn billing.Upsert
SetID(d.Discount.ID).
SetNamespace(d.Line.Namespace).
SetLineID(d.Line.ID).
SetReason(d.Discount.Reason).
SetNillableDeletedAt(d.Discount.DeletedAt).
SetAmount(d.Discount.Amount).
SetNillableChildUniqueReferenceID(d.Discount.ChildUniqueReferenceID).
Expand Down
2 changes: 1 addition & 1 deletion openmeter/billing/httpdriver/invoiceline.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ func mapDiscountToAPI(discount billing.LineDiscount) (api.InvoiceLineDiscount, e
DeletedAt: discount.DeletedAt,
UpdatedAt: discount.UpdatedAt,

Reason: api.InvoiceDiscountReason(discount.Reason),
Description: discount.Description,
Amount: discount.Amount.String(),
Code: discount.ChildUniqueReferenceID,
ExternalIds: &api.InvoiceLineAppExternalIds{
Invoicing: lo.EmptyableToPtr(discount.ExternalIDs.Invoicing),
},
Expand Down
Loading
Loading