Skip to content

Commit

Permalink
feat: expose external ids (#1933)
Browse files Browse the repository at this point in the history
  • Loading branch information
turip authored Dec 9, 2024
1 parent 8eb5d7b commit 7054e80
Show file tree
Hide file tree
Showing 6 changed files with 898 additions and 714 deletions.
1,460 changes: 746 additions & 714 deletions api/api.gen.go

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions api/openapi.cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11139,6 +11139,11 @@ components:
$ref: '#/components/schemas/ValidationIssue'
description: Validation issues reported by the invoice workflow.
readOnly: true
externalIDs:
allOf:
- $ref: '#/components/schemas/InvoiceAppExternalIDs'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
description: Invoice represents an invoice in the system.
InvoiceAction:
type: string
Expand All @@ -11149,6 +11154,22 @@ components:
- retry
- void
description: InvoiceAction represents the actions that can be performed on an invoice.
InvoiceAppExternalIDs:
type: object
properties:
Invoicing:
type: string
description: The external ID of the invoice in the invoicing app if available.
readOnly: true
Tax:
type: string
description: The external ID of the invoice in the tax app if available.
readOnly: true
Payment:
type: string
description: The external ID of the invoice in the payment app if available.
readOnly: true
description: InvoiceAppExternalIDs contains the external IDs of the invoice in other apps such as Stripe.
InvoiceDocumentRef:
type: object
allOf:
Expand Down Expand Up @@ -11302,6 +11323,11 @@ components:
format: date-time
example: 2023-01-01T01:01:01.001Z
description: The time this line item should be invoiced.
externalIDs:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIDs'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
type:
type: string
enum:
Expand Down Expand Up @@ -11489,6 +11515,18 @@ components:
usage_based: '#/components/schemas/InvoiceUsageBasedLine'
flat_fee: '#/components/schemas/InvoiceFlatFeeLine'
description: BillingInvoiceLine represents a line item that is sold to the customer based on a specific (unit) price.
InvoiceLineAppExternalIDs:
type: object
properties:
Invoicing:
type: string
description: The external ID of the invoice in the invoicing app if available.
readOnly: true
Tax:
type: string
description: The external ID of the invoice in the tax app if available.
readOnly: true
description: InvoiceLineAppExternalIDs contains the external IDs of the invoice in other apps such as Stripe.
InvoiceLineDiscount:
type: object
required:
Expand Down Expand Up @@ -11934,6 +11972,11 @@ components:
format: date-time
example: 2023-01-01T01:01:01.001Z
description: The time this line item should be invoiced.
externalIDs:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIDs'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
type:
type: string
enum:
Expand Down
43 changes: 43 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10829,6 +10829,11 @@ components:
$ref: '#/components/schemas/ValidationIssue'
description: Validation issues reported by the invoice workflow.
readOnly: true
externalIDs:
allOf:
- $ref: '#/components/schemas/InvoiceAppExternalIDs'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
description: Invoice represents an invoice in the system.
InvoiceAction:
type: string
Expand All @@ -10839,6 +10844,22 @@ components:
- retry
- void
description: InvoiceAction represents the actions that can be performed on an invoice.
InvoiceAppExternalIDs:
type: object
properties:
Invoicing:
type: string
description: The external ID of the invoice in the invoicing app if available.
readOnly: true
Tax:
type: string
description: The external ID of the invoice in the tax app if available.
readOnly: true
Payment:
type: string
description: The external ID of the invoice in the payment app if available.
readOnly: true
description: InvoiceAppExternalIDs contains the external IDs of the invoice in other apps such as Stripe.
InvoiceDocumentRef:
type: object
allOf:
Expand Down Expand Up @@ -10992,6 +11013,11 @@ components:
format: date-time
example: 2023-01-01T01:01:01.001Z
description: The time this line item should be invoiced.
externalIDs:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIDs'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
type:
type: string
enum:
Expand Down Expand Up @@ -11179,6 +11205,18 @@ components:
usage_based: '#/components/schemas/InvoiceUsageBasedLine'
flat_fee: '#/components/schemas/InvoiceFlatFeeLine'
description: BillingInvoiceLine represents a line item that is sold to the customer based on a specific (unit) price.
InvoiceLineAppExternalIDs:
type: object
properties:
Invoicing:
type: string
description: The external ID of the invoice in the invoicing app if available.
readOnly: true
Tax:
type: string
description: The external ID of the invoice in the tax app if available.
readOnly: true
description: InvoiceLineAppExternalIDs contains the external IDs of the invoice in other apps such as Stripe.
InvoiceLineDiscount:
type: object
required:
Expand Down Expand Up @@ -11624,6 +11662,11 @@ components:
format: date-time
example: 2023-01-01T01:01:01.001Z
description: The time this line item should be invoiced.
externalIDs:
allOf:
- $ref: '#/components/schemas/InvoiceLineAppExternalIDs'
description: External IDs of the invoice in other apps such as Stripe.
readOnly: true
type:
type: string
enum:
Expand Down
54 changes: 54 additions & 0 deletions api/spec/src/billing/invoices/invoice.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ model Invoice {
*/
@visibility("read")
validationIssues?: ValidationIssue[];

/**
* External IDs of the invoice in other apps such as Stripe.
*/
@visibility("read")
externalIDs?: InvoiceAppExternalIDs;
}

/**
Expand Down Expand Up @@ -568,6 +574,12 @@ model InvoiceLineBase {
*/
@visibility("read", "create", "update")
invoiceAt: DateTime;

/**
* External IDs of the invoice in other apps such as Stripe.
*/
@visibility("read")
externalIDs?: InvoiceLineAppExternalIDs;
}

/**
Expand Down Expand Up @@ -836,3 +848,45 @@ model ValidationIssue {
@visibility("read")
metadata?: Metadata;
}

/**
* InvoiceAppExternalIDs contains the external IDs of the invoice in other apps such as Stripe.
*/
@friendlyName("InvoiceAppExternalIDs")
model InvoiceAppExternalIDs {
/**
* The external ID of the invoice in the invoicing app if available.
*/
@visibility("read")
Invoicing?: string;

/**
* The external ID of the invoice in the tax app if available.
*/
@visibility("read")
Tax?: string;

/**
* The external ID of the invoice in the payment app if available.
*/
@visibility("read")
Payment?: string;
}

/**
* InvoiceLineAppExternalIDs contains the external IDs of the invoice in other apps such as Stripe.
*/
@friendlyName("InvoiceLineAppExternalIDs")
model InvoiceLineAppExternalIDs {
/**
* The external ID of the invoice in the invoicing app if available.
*/
@visibility("read")
Invoicing?: string;

/**
* The external ID of the invoice in the tax app if available.
*/
@visibility("read")
Tax?: string;
}
4 changes: 4 additions & 0 deletions openmeter/billing/httpdriver/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ func mapInvoiceToAPI(invoice billing.Invoice) (api.Invoice, error) {
Field: lo.EmptyableToPtr(v.Path),
}
})),
ExternalIDs: lo.EmptyableToPtr(api.InvoiceAppExternalIDs{
Invoicing: lo.EmptyableToPtr(invoice.ExternalIDs.Invoicing),
Payment: lo.EmptyableToPtr(invoice.ExternalIDs.Payment),
}),
}

if invoice.Workflow != nil {
Expand Down
8 changes: 8 additions & 0 deletions openmeter/billing/httpdriver/invoiceline.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ func mapFeeLineToAPI(line *billing.Line) (api.InvoiceLine, error) {
Discounts: mapDiscountsToAPI(line.Discounts),
Totals: mapTotalsToAPI(line.Totals),
Children: children,

ExternalIDs: &api.InvoiceLineAppExternalIDs{
Invoicing: lo.EmptyableToPtr(line.ExternalIDs.Invoicing),
},
}

out := api.InvoiceLine{}
Expand Down Expand Up @@ -556,6 +560,10 @@ func mapUsageBasedLineToAPI(line *billing.Line) (api.InvoiceLine, error) {
Discounts: mapDiscountsToAPI(line.Discounts),
Children: children,
Totals: mapTotalsToAPI(line.Totals),

ExternalIDs: lo.EmptyableToPtr(api.InvoiceLineAppExternalIDs{
Invoicing: lo.EmptyableToPtr(line.ExternalIDs.Invoicing),
}),
}

out := api.InvoiceLine{}
Expand Down

0 comments on commit 7054e80

Please sign in to comment.