Skip to content

Commit 6b1ecaa

Browse files
authored
feat: list invoices api (#226)
* adding list invoices api * making request params optional * optional invoice id * openapi for invoices * removing unused struct * billing as its own service * adding service summary
1 parent 872b03b commit 6b1ecaa

File tree

5 files changed

+268
-11
lines changed

5 files changed

+268
-11
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ all: lint
1313

1414
.PRECIOUS: ${PROTO_DIR}/openapi.yaml ${PROTO_DIR}/%.proto
1515

16-
COMPONENTS = api cache health auth observability management realtime search
16+
COMPONENTS = api cache health auth observability management realtime search billing
1717

1818
# Generate GRPC client/server, openapi spec, http server
1919
${GEN_DIR}/%.pb.go ${GEN_DIR}/%.pb.gw.go: ${PROTO_DIR}/%.proto

server/v1/api.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ option (openapi.v3.document) = {
7171
}, {
7272
name: "Search"
7373
description: "The search section provides you APIs that can be used to implement powerful apps with search experiences. You can manage storing documents on your own or you can simply integrate it with your database."
74+
}, {
75+
name: "Billing"
76+
description: "The billing section provides APIs for managing invoices and payments infrastructure."
7477
}]
7578
components: {
7679
security_schemes: {

server/v1/billing.proto

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright 2022-2023 Tigris Data, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
package tigrisdata.billing.v1;
18+
19+
import "google/api/annotations.proto";
20+
import "openapiv3/annotations.proto";
21+
import "google/protobuf/timestamp.proto";
22+
23+
option go_package = "github.com/tigrisdata/tigris/api";
24+
option java_package = "com.tigrisdata.db.api.v1.grpc";
25+
26+
message ListInvoicesRequest{
27+
//RFC 3339 timestamp (inclusive). Invoices will only be returned for billing periods that start at or after this time.
28+
optional google.protobuf.Timestamp starting_on = 1;
29+
//RFC 3339 timestamp (exclusive). Invoices will only be returned for billing periods that end before this time.
30+
optional google.protobuf.Timestamp ending_before = 2;
31+
// optionally filter by a specific invoice_id
32+
string invoice_id = 3;
33+
// maximum number of items to include in result set
34+
optional int32 page_size = 4;
35+
// pagination token for fetching a particular result page, first page will be fetched if `null`
36+
optional string next_page = 5;
37+
}
38+
39+
message ListInvoicesResponse {
40+
// Array of invoices
41+
repeated Invoice data = 1;
42+
// token for next page if it exists, else `null`
43+
optional string next_page = 2;
44+
}
45+
46+
message Invoice {
47+
// unique identifier for this invoice
48+
string id = 1;
49+
// entries that make up the invoice
50+
repeated InvoiceLineItem entries = 2;
51+
// RFC 3339 starting time for usage period during which items were added to this invoice
52+
google.protobuf.Timestamp start_time = 3;
53+
// RFC 3339 ending time for usage period during which items were added to this invoice
54+
google.protobuf.Timestamp end_time = 4;
55+
// invoice subtotal
56+
float subtotal = 5;
57+
// total invoice amount
58+
float total = 6;
59+
// Tigris price plan name
60+
string plan_name = 7;
61+
}
62+
63+
message InvoiceLineItem {
64+
// Product name
65+
string name = 1;
66+
// Quantity
67+
float quantity = 2;
68+
// Total amount for the product
69+
float total = 3;
70+
// Broken down charges
71+
repeated Charge charges = 4;
72+
}
73+
74+
message Charge {
75+
// Charge name
76+
string name = 1;
77+
float quantity = 2;
78+
float subtotal = 3;
79+
// Tiered charges, if any
80+
repeated ChargeTier tiers = 4;
81+
}
82+
83+
message ChargeTier {
84+
// Starting point where this Tier is applicable.
85+
// Ex - A charge could be tiered as "Tier 1 (0-5)", "Tier 2 (5-10)"; starting_at will be 0, 5 etc.
86+
float starting_at = 1;
87+
float quantity = 2;
88+
float price = 3;
89+
float subtotal = 4;
90+
}
91+
92+
service Billing {
93+
94+
// ListInvoices fetches past invoices for this user
95+
rpc ListInvoices(ListInvoicesRequest) returns (ListInvoicesResponse) {
96+
option (google.api.http) = {
97+
get: "/v1/billing/invoices"
98+
additional_bindings {
99+
get: "/v1/billing/invoices/{invoice_id}"
100+
}
101+
};
102+
option(openapi.v3.operation) = {
103+
summary: "Lists all invoices for the user",
104+
tags: "Billing"
105+
};
106+
}
107+
}

server/v1/management.proto

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ message DeleteNamespaceResponse {
7878
string status = 2;
7979
}
8080

81-
message NamespaceInfoRequest{
82-
// namespace id
83-
string id = 1;
84-
}
85-
86-
message NamespaceInfoResponse {
87-
// information about namespace
88-
NamespaceInfo namespace_info = 1;
89-
}
90-
9181
// Request user metadata
9282
message GetUserMetadataRequest {
9383
string metadataKey = 1;

server/v1/openapi.yaml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,67 @@ paths:
150150
application/json:
151151
schema:
152152
$ref: '#/components/schemas/Status'
153+
/v1/billing/invoices:
154+
get:
155+
tags:
156+
- Billing
157+
summary: Lists all invoices for the user
158+
description: ListInvoices fetches past invoices for this user
159+
operationId: Billing_ListInvoices
160+
parameters:
161+
- name: starting_on.seconds
162+
in: query
163+
description: Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.
164+
schema:
165+
type: integer
166+
format: int64
167+
- name: starting_on.nanos
168+
in: query
169+
description: Non-negative fractions of a second at nanosecond resolution. Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be from 0 to 999,999,999 inclusive.
170+
schema:
171+
type: integer
172+
format: int32
173+
- name: ending_before.seconds
174+
in: query
175+
description: Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.
176+
schema:
177+
type: integer
178+
format: int64
179+
- name: ending_before.nanos
180+
in: query
181+
description: Non-negative fractions of a second at nanosecond resolution. Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be from 0 to 999,999,999 inclusive.
182+
schema:
183+
type: integer
184+
format: int32
185+
- name: invoice_id
186+
in: query
187+
description: optionally filter by a specific invoice_id
188+
schema:
189+
type: string
190+
- name: page_size
191+
in: query
192+
description: maximum number of items to include in result set
193+
schema:
194+
type: integer
195+
format: int32
196+
- name: next_page
197+
in: query
198+
description: pagination token for fetching a particular result page, first page will be fetched if `null`
199+
schema:
200+
type: string
201+
responses:
202+
"200":
203+
description: OK
204+
content:
205+
application/json:
206+
schema:
207+
$ref: '#/components/schemas/ListInvoicesResponse'
208+
default:
209+
description: Default error response
210+
content:
211+
application/json:
212+
schema:
213+
$ref: '#/components/schemas/Status'
153214
/v1/health:
154215
get:
155216
tags:
@@ -2734,6 +2795,39 @@ components:
27342795
properties:
27352796
channel:
27362797
type: string
2798+
Charge:
2799+
type: object
2800+
properties:
2801+
name:
2802+
type: string
2803+
description: Charge name
2804+
quantity:
2805+
type: number
2806+
format: float
2807+
subtotal:
2808+
type: number
2809+
format: float
2810+
tiers:
2811+
type: array
2812+
items:
2813+
$ref: '#/components/schemas/ChargeTier'
2814+
description: Tiered charges, if any
2815+
ChargeTier:
2816+
type: object
2817+
properties:
2818+
starting_at:
2819+
type: number
2820+
description: Starting point where this Tier is applicable. Ex - A charge could be tiered as "Tier 1 (0-5)", "Tier 2 (5-10)"; starting_at will be 0, 5 etc.
2821+
format: float
2822+
quantity:
2823+
type: number
2824+
format: float
2825+
price:
2826+
type: number
2827+
format: float
2828+
subtotal:
2829+
type: number
2830+
format: float
27372831
Collation:
27382832
type: object
27392833
properties:
@@ -3725,6 +3819,55 @@ components:
37253819
invitation_sent_by_name:
37263820
type: string
37273821
description: Invitation sender name
3822+
Invoice:
3823+
type: object
3824+
properties:
3825+
id:
3826+
type: string
3827+
description: unique identifier for this invoice
3828+
entries:
3829+
type: array
3830+
items:
3831+
$ref: '#/components/schemas/InvoiceLineItem'
3832+
description: entries that make up the invoice
3833+
start_time:
3834+
type: string
3835+
description: RFC 3339 starting time for usage period during which items were added to this invoice
3836+
format: date-time
3837+
end_time:
3838+
type: string
3839+
description: RFC 3339 ending time for usage period during which items were added to this invoice
3840+
format: date-time
3841+
subtotal:
3842+
type: number
3843+
description: invoice subtotal
3844+
format: float
3845+
total:
3846+
type: number
3847+
description: total invoice amount
3848+
format: float
3849+
plan_name:
3850+
type: string
3851+
description: Tigris price plan name
3852+
InvoiceLineItem:
3853+
type: object
3854+
properties:
3855+
name:
3856+
type: string
3857+
description: Product name
3858+
quantity:
3859+
type: number
3860+
description: Quantity
3861+
format: float
3862+
total:
3863+
type: number
3864+
description: Total amount for the product
3865+
format: float
3866+
charges:
3867+
type: array
3868+
items:
3869+
$ref: '#/components/schemas/Charge'
3870+
description: Broken down charges
37283871
KeysResponse:
37293872
type: object
37303873
properties:
@@ -3784,6 +3927,17 @@ components:
37843927
type: array
37853928
items:
37863929
$ref: '#/components/schemas/Invitation'
3930+
ListInvoicesResponse:
3931+
type: object
3932+
properties:
3933+
data:
3934+
type: array
3935+
items:
3936+
$ref: '#/components/schemas/Invoice'
3937+
description: Array of invoices
3938+
next_page:
3939+
type: string
3940+
description: token for next page if it exists, else `null`
37873941
ListNamespacesResponse:
37883942
type: object
37893943
properties:
@@ -4596,6 +4750,9 @@ tags:
45964750
description: The application keys section provide APIs that can be used to manage application keys for your project. A single project can have one or more application keys.
45974751
- name: Authentication
45984752
description: 'The auth section of API provides OAuth 2.0 APIs. Tigris supports pluggable OAuth provider. Pass the token in the headers for authentication, as an example `-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6I"`(replace it with your token). All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.'
4753+
- name: Billing
4754+
description: The billing section provides APIs for managing invoices and payments infrastructure.
4755+
- name: Billing
45994756
- name: Cache
46004757
description: The cache section provide APIs that can be used to perform cache operations.
46014758
- name: Collections

0 commit comments

Comments
 (0)