Skip to content

Commit 08677be

Browse files
committed
feat: invoice delete v3 endpoints
1 parent 3bf58b9 commit 08677be

19 files changed

Lines changed: 2182 additions & 194 deletions

File tree

api/spec/packages/aip-client-javascript/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,16 @@ The full call path, HTTP route, and a short description are listed below.
194194

195195
### Invoices
196196

197-
| Method | HTTP | Description |
198-
| ------------------------ | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
199-
| `client.invoices.list` | `GET /openmeter/billing/invoices` | List billing invoices. Returns a page of invoices. Gathering invoices are never included. Use `filter` to narrow by status, customer, dates, or service period start. Use `sort` to control ordering. |
200-
| `client.invoices.get` | `GET /openmeter/billing/invoices/{invoiceId}` | Get a billing invoice by ID. Returns the full invoice resource including line items, status details, totals, and workflow configuration snapshot. |
201-
| `client.invoices.update` | `PUT /openmeter/billing/invoices/{invoiceId}` | Update a billing invoice. Only the mutable fields of the invoice can be edited: description, labels, supplier, customer, workflow settings, and top-level lines. Top-level lines are matched by `id`; lines without an `id` are created, and existing lines omitted from `lines` are deleted. Detailed (child) lines are always computed and cannot be edited directly. Only invoices in draft status can be updated. |
197+
| Method | HTTP | Description |
198+
| ------------------------------------ | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
199+
| `client.invoices.list` | `GET /openmeter/billing/invoices` | List billing invoices. Returns a page of invoices. Gathering invoices are never included. Use `filter` to narrow by status, customer, dates, or service period start. Use `sort` to control ordering. |
200+
| `client.invoices.get` | `GET /openmeter/billing/invoices/{invoiceId}` | Get a billing invoice by ID. Returns the full invoice resource including line items, status details, totals, and workflow configuration snapshot. |
201+
| `client.invoices.update` | `PUT /openmeter/billing/invoices/{invoiceId}` | Update a billing invoice. Only the mutable fields of the invoice can be edited: description, labels, supplier, customer, workflow settings, and top-level lines. Top-level lines are matched by `id`; lines without an `id` are created, and existing lines omitted from `lines` are deleted. Detailed (child) lines are always computed and cannot be edited directly. Only invoices in draft status can be updated. |
202+
| `client.invoices.delete` | `DELETE /openmeter/billing/invoices/{invoiceId}` | Delete a billing invoice. Only standard invoices in draft status can be deleted. Deleting an invoice will also delete all associated line items and workflow configuration. |
203+
| `client.invoices.advance` | `POST /openmeter/billing/invoices/{invoiceId}/advance` | Advance a billing invoice. Advances the invoice to the next workflow state. The next state is determined by the invoice's current status and workflow configuration. Only invoices in draft or issued status can be advanced. |
204+
| `client.invoices.approve` | `POST /openmeter/billing/invoices/{invoiceId}/approve` | Approve a billing invoice. This call instantly sends the invoice to the customer using the configured billing profile app. This call is valid in two invoice statuses: - draft: the invoice will be sent to the customer, the invoice state becomes issued - manual_approval_needed: the invoice will be sent to the customer, the invoice state becomes issued |
205+
| `client.invoices.retry` | `POST /openmeter/billing/invoices/{invoiceId}/retry` | Retry sending a billing invoice. Retry advancing the invoice after a failed attempt. The action can be called when the invoice's statusDetails' actions field contain the "retry" action. |
206+
| `client.invoices.snapshotQuantities` | `POST /openmeter/billing/invoices/{invoiceId}/snapshot-quantities` | Snapshot quantities for usage-based line items. This call will snapshot the quantities for all usage based line items in the invoice. This call is only valid in draft.waiting_for_collection status, where the collection period can be skipped using this action. |
202207

203208
### Tax
204209

api/spec/packages/aip-client-javascript/src/funcs/invoices.ts

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import type {
1111
GetInvoiceResponse,
1212
UpdateInvoiceRequest,
1313
UpdateInvoiceResponse,
14+
DeleteInvoiceRequest,
15+
DeleteInvoiceResponse,
16+
AdvanceInvoiceRequest,
17+
AdvanceInvoiceResponse,
18+
ApproveInvoiceRequest,
19+
ApproveInvoiceResponse,
20+
RetryInvoiceRequest,
21+
RetryInvoiceResponse,
22+
SnapshotQuantitiesInvoiceRequest,
23+
SnapshotQuantitiesInvoiceResponse,
1424
} from '../models/operations/invoices.js'
1525

1626
export function listInvoices(
@@ -94,3 +104,115 @@ export function updateInvoice(
94104
})
95105
})
96106
}
107+
108+
export function deleteInvoice(
109+
client: Client,
110+
req: DeleteInvoiceRequest,
111+
options?: RequestOptions,
112+
): Promise<Result<DeleteInvoiceResponse>> {
113+
return request(async () => {
114+
const path = `openmeter/billing/invoices/${(() => {
115+
if (req.invoiceId === undefined) {
116+
throw new Error('missing path parameter: invoiceId')
117+
}
118+
return encodeURIComponent(String(req.invoiceId))
119+
})()}`
120+
await http(client).delete(path, options)
121+
})
122+
}
123+
124+
export function advanceInvoice(
125+
client: Client,
126+
req: AdvanceInvoiceRequest,
127+
options?: RequestOptions,
128+
): Promise<Result<AdvanceInvoiceResponse>> {
129+
return request(() => {
130+
const path = `openmeter/billing/invoices/${(() => {
131+
if (req.invoiceId === undefined) {
132+
throw new Error('missing path parameter: invoiceId')
133+
}
134+
return encodeURIComponent(String(req.invoiceId))
135+
})()}/advance`
136+
return http(client)
137+
.post(path, options)
138+
.json()
139+
.then((data) => {
140+
if (client._options.validate) {
141+
assertValid(schemas.advanceInvoiceResponseWire, data)
142+
}
143+
return fromWire(data, schemas.advanceInvoiceResponse)
144+
})
145+
})
146+
}
147+
148+
export function approveInvoice(
149+
client: Client,
150+
req: ApproveInvoiceRequest,
151+
options?: RequestOptions,
152+
): Promise<Result<ApproveInvoiceResponse>> {
153+
return request(() => {
154+
const path = `openmeter/billing/invoices/${(() => {
155+
if (req.invoiceId === undefined) {
156+
throw new Error('missing path parameter: invoiceId')
157+
}
158+
return encodeURIComponent(String(req.invoiceId))
159+
})()}/approve`
160+
return http(client)
161+
.post(path, options)
162+
.json()
163+
.then((data) => {
164+
if (client._options.validate) {
165+
assertValid(schemas.approveInvoiceResponseWire, data)
166+
}
167+
return fromWire(data, schemas.approveInvoiceResponse)
168+
})
169+
})
170+
}
171+
172+
export function retryInvoice(
173+
client: Client,
174+
req: RetryInvoiceRequest,
175+
options?: RequestOptions,
176+
): Promise<Result<RetryInvoiceResponse>> {
177+
return request(() => {
178+
const path = `openmeter/billing/invoices/${(() => {
179+
if (req.invoiceId === undefined) {
180+
throw new Error('missing path parameter: invoiceId')
181+
}
182+
return encodeURIComponent(String(req.invoiceId))
183+
})()}/retry`
184+
return http(client)
185+
.post(path, options)
186+
.json()
187+
.then((data) => {
188+
if (client._options.validate) {
189+
assertValid(schemas.retryInvoiceResponseWire, data)
190+
}
191+
return fromWire(data, schemas.retryInvoiceResponse)
192+
})
193+
})
194+
}
195+
196+
export function snapshotQuantitiesInvoice(
197+
client: Client,
198+
req: SnapshotQuantitiesInvoiceRequest,
199+
options?: RequestOptions,
200+
): Promise<Result<SnapshotQuantitiesInvoiceResponse>> {
201+
return request(() => {
202+
const path = `openmeter/billing/invoices/${(() => {
203+
if (req.invoiceId === undefined) {
204+
throw new Error('missing path parameter: invoiceId')
205+
}
206+
return encodeURIComponent(String(req.invoiceId))
207+
})()}/snapshot-quantities`
208+
return http(client)
209+
.post(path, options)
210+
.json()
211+
.then((data) => {
212+
if (client._options.validate) {
213+
assertValid(schemas.snapshotQuantitiesInvoiceResponseWire, data)
214+
}
215+
return fromWire(data, schemas.snapshotQuantitiesInvoiceResponse)
216+
})
217+
})
218+
}

api/spec/packages/aip-client-javascript/src/models/operations/invoices.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,34 @@ export type UpdateInvoiceRequest = {
4848
export type UpdateInvoiceResponse = z.output<
4949
typeof schemas.updateInvoiceResponse
5050
>
51+
52+
export type DeleteInvoiceRequest = {
53+
invoiceId: string
54+
}
55+
export type DeleteInvoiceResponse = void
56+
57+
export type AdvanceInvoiceRequest = {
58+
invoiceId: string
59+
}
60+
export type AdvanceInvoiceResponse = z.output<
61+
typeof schemas.advanceInvoiceResponse
62+
>
63+
64+
export type ApproveInvoiceRequest = {
65+
invoiceId: string
66+
}
67+
export type ApproveInvoiceResponse = z.output<
68+
typeof schemas.approveInvoiceResponse
69+
>
70+
71+
export type RetryInvoiceRequest = {
72+
invoiceId: string
73+
}
74+
export type RetryInvoiceResponse = z.output<typeof schemas.retryInvoiceResponse>
75+
76+
export type SnapshotQuantitiesInvoiceRequest = {
77+
invoiceId: string
78+
}
79+
export type SnapshotQuantitiesInvoiceResponse = z.output<
80+
typeof schemas.snapshotQuantitiesInvoiceResponse
81+
>

api/spec/packages/aip-client-javascript/src/models/schemas.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6120,6 +6120,34 @@ export const updateInvoiceBody = updateInvoiceRequest
61206120

61216121
export const updateInvoiceResponse = invoice
61226122

6123+
export const deleteInvoicePathParams = z.object({
6124+
invoiceId: ulid,
6125+
})
6126+
6127+
export const advanceInvoicePathParams = z.object({
6128+
invoiceId: ulid,
6129+
})
6130+
6131+
export const advanceInvoiceResponse = invoice
6132+
6133+
export const approveInvoicePathParams = z.object({
6134+
invoiceId: ulid,
6135+
})
6136+
6137+
export const approveInvoiceResponse = invoice
6138+
6139+
export const retryInvoicePathParams = z.object({
6140+
invoiceId: ulid,
6141+
})
6142+
6143+
export const retryInvoiceResponse = invoice
6144+
6145+
export const snapshotQuantitiesInvoicePathParams = z.object({
6146+
invoiceId: ulid,
6147+
})
6148+
6149+
export const snapshotQuantitiesInvoiceResponse = invoice
6150+
61236151
export const createTaxCodeBody = createTaxCodeRequest
61246152

61256153
export const createTaxCodeResponse = taxCode
@@ -12654,6 +12682,34 @@ export const updateInvoiceBodyWire = updateInvoiceRequestWire
1265412682

1265512683
export const updateInvoiceResponseWire = invoiceWire
1265612684

12685+
export const deleteInvoicePathParamsWire = z.object({
12686+
invoiceId: ulidWire,
12687+
})
12688+
12689+
export const advanceInvoicePathParamsWire = z.object({
12690+
invoiceId: ulidWire,
12691+
})
12692+
12693+
export const advanceInvoiceResponseWire = invoiceWire
12694+
12695+
export const approveInvoicePathParamsWire = z.object({
12696+
invoiceId: ulidWire,
12697+
})
12698+
12699+
export const approveInvoiceResponseWire = invoiceWire
12700+
12701+
export const retryInvoicePathParamsWire = z.object({
12702+
invoiceId: ulidWire,
12703+
})
12704+
12705+
export const retryInvoiceResponseWire = invoiceWire
12706+
12707+
export const snapshotQuantitiesInvoicePathParamsWire = z.object({
12708+
invoiceId: ulidWire,
12709+
})
12710+
12711+
export const snapshotQuantitiesInvoiceResponseWire = invoiceWire
12712+
1265712713
export const createTaxCodeBodyWire = createTaxCodeRequestWire
1265812714

1265912715
export const createTaxCodeResponseWire = taxCodeWire

api/spec/packages/aip-client-javascript/src/sdk/invoices.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
import { type Client } from '../core.js'
22
import { unwrap, type RequestOptions } from '../lib/types.js'
3-
import { listInvoices, getInvoice, updateInvoice } from '../funcs/invoices.js'
3+
import {
4+
listInvoices,
5+
getInvoice,
6+
updateInvoice,
7+
deleteInvoice,
8+
advanceInvoice,
9+
approveInvoice,
10+
retryInvoice,
11+
snapshotQuantitiesInvoice,
12+
} from '../funcs/invoices.js'
413
import type {
514
ListInvoicesRequest,
615
ListInvoicesResponse,
716
GetInvoiceRequest,
817
GetInvoiceResponse,
918
UpdateInvoiceRequest,
1019
UpdateInvoiceResponse,
20+
DeleteInvoiceRequest,
21+
DeleteInvoiceResponse,
22+
AdvanceInvoiceRequest,
23+
AdvanceInvoiceResponse,
24+
ApproveInvoiceRequest,
25+
ApproveInvoiceResponse,
26+
RetryInvoiceRequest,
27+
RetryInvoiceResponse,
28+
SnapshotQuantitiesInvoiceRequest,
29+
SnapshotQuantitiesInvoiceResponse,
1130
} from '../models/operations/invoices.js'
1231

1332
export class Invoices {
@@ -33,4 +52,41 @@ export class Invoices {
3352
): Promise<UpdateInvoiceResponse> {
3453
return unwrap(await updateInvoice(this._client, request, options))
3554
}
55+
56+
async delete(
57+
request: DeleteInvoiceRequest,
58+
options?: RequestOptions,
59+
): Promise<DeleteInvoiceResponse> {
60+
return unwrap(await deleteInvoice(this._client, request, options))
61+
}
62+
63+
async advance(
64+
request: AdvanceInvoiceRequest,
65+
options?: RequestOptions,
66+
): Promise<AdvanceInvoiceResponse> {
67+
return unwrap(await advanceInvoice(this._client, request, options))
68+
}
69+
70+
async approve(
71+
request: ApproveInvoiceRequest,
72+
options?: RequestOptions,
73+
): Promise<ApproveInvoiceResponse> {
74+
return unwrap(await approveInvoice(this._client, request, options))
75+
}
76+
77+
async retry(
78+
request: RetryInvoiceRequest,
79+
options?: RequestOptions,
80+
): Promise<RetryInvoiceResponse> {
81+
return unwrap(await retryInvoice(this._client, request, options))
82+
}
83+
84+
async snapshotQuantities(
85+
request: SnapshotQuantitiesInvoiceRequest,
86+
options?: RequestOptions,
87+
): Promise<SnapshotQuantitiesInvoiceResponse> {
88+
return unwrap(
89+
await snapshotQuantitiesInvoice(this._client, request, options),
90+
)
91+
}
3692
}

0 commit comments

Comments
 (0)