Skip to content

Commit

Permalink
feat(frontier): revert reported billing usage (#348)
Browse files Browse the repository at this point in the history
Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma authored Mar 31, 2024
1 parent 048f1ee commit 5dcd741
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
38 changes: 38 additions & 0 deletions raystack/frontier/v1beta1/admin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,23 @@ service AdminService {
description: "Lists all the billing accounts from all the organizations in a Frontier instance. It can be filtered by organization.";
};
}

// Usage
rpc RevertBillingUsage(RevertBillingUsageRequest) returns (RevertBillingUsageResponse) {
option (google.api.http) = {
post: "/v1beta1/admin/organizations/{org_id}/billing/{billing_id}/usage/{usage_id}/revert",
body: "*"
additional_bindings {
post: "/v1beta1/organizations/billing/usages/revert",
body: "*"
}
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Billing";
summary: "Revert billing usage";
description: "Revert billing usage for a billing account.";
};
}
}

message ListAllUsersRequest {
Expand Down Expand Up @@ -574,3 +591,24 @@ message ListAllBillingAccountsRequest {
message ListAllBillingAccountsResponse {
repeated BillingAccount billing_accounts = 1;
}

message RevertBillingUsageRequest {
// either provide org_id or infer org from project_id
string org_id = 1;
string project_id = 2;

// either provide billing_id of the org or API can infer the default
// billing ID from either org_id or project_id, not both
string billing_id = 3 [(validate.rules).string = {
ignore_empty: true,
uuid: true
}];

// usage id to revert, a usage can only be allowed to revert once
string usage_id = 4 [(validate.rules).string = {uuid: true}];

// amount should be equal or less than the usage amount
int64 amount = 5 [(validate.rules).int64 = {gte: 0}];
}

message RevertBillingUsageResponse {}
10 changes: 5 additions & 5 deletions raystack/frontier/v1beta1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,8 @@ message Plan {
"year"
]
}];
int64 on_start_credits = 7;
int64 trial_days = 8;
int64 on_start_credits = 7 [(validate.rules).int64 = {gte: 0}];
int64 trial_days = 8 [(validate.rules).int64 = {gte: 0}];

google.protobuf.Struct metadata = 20;
google.protobuf.Timestamp created_at = 21;
Expand Down Expand Up @@ -714,7 +714,7 @@ message Price {
string state = 9;
// currency like "usd", "eur", "gbp"
string currency = 10;
int64 amount = 11;
int64 amount = 11 [(validate.rules).int64 = {gte: 0}];
// metered_aggregate known aggregations are "sum", "last_during_period" and "max"
string metered_aggregate = 13 [(validate.rules).string = {
ignore_empty: true,
Expand Down Expand Up @@ -743,7 +743,7 @@ message BillingTransaction {
string customer_id = 2;
// additional metadata for storing event/service that triggered this usage
string source = 3;
int64 amount = 4;
int64 amount = 4 [(validate.rules).int64 = {gte: 0}];
string type = 5 [(validate.rules).string = {
ignore_empty: true,
in: [
Expand Down Expand Up @@ -779,7 +779,7 @@ message Usage {
"feature"
]
}];
int64 amount = 6;
int64 amount = 6 [(validate.rules).int64 = {gte: 0}];

// user_id is the user that triggered this usage
string user_id = 7;
Expand Down

0 comments on commit 5dcd741

Please sign in to comment.