Skip to content

Commit

Permalink
feat(frontier): billing for organizations
Browse files Browse the repository at this point in the history
Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma committed Oct 21, 2023
1 parent a643dfe commit a524aeb
Show file tree
Hide file tree
Showing 2 changed files with 349 additions and 0 deletions.
258 changes: 258 additions & 0 deletions raystack/frontier/v1beta1/frontier.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,264 @@ service FrontierService {
description: "List a user preferences by ID.";
};
}

// Billing customer
rpc CreateBillingCustomer(CreateBillingCustomerRequest) returns (CreateBillingCustomerResponse) {
option (google.api.http) = {
post: "/v1beta1/billing/customers",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Billing";
summary: "Create billing customer";
description: "Create a new billing customer for an organization.";
};
}

rpc GetBillingCustomer(GetBillingCustomerRequest) returns (GetBillingCustomerResponse) {
option (google.api.http) = {get: "/v1beta1/billing/customers/{id}"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Billing";
summary: "Get billing customer";
description: "Get a billing customer by ID.";
};
}

rpc UpdateBillingCustomer(UpdateBillingCustomerRequest) returns (UpdateBillingCustomerResponse) {
option (google.api.http) = {
put: "/v1beta1/billing/customers/{id}",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Billing";
summary: "Update billing customer";
description: "Update a billing customer by ID.";
};
}

rpc ListBillingCustomers(ListBillingCustomersRequest) returns (ListBillingCustomersResponse) {
option (google.api.http) = {get: "/v1beta1/billing/customers"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Billing";
summary: "List billing customers";
description: "List billing customers of an organization.";
};
}

rpc DeleteBillingCustomer(DeleteBillingCustomerRequest) returns (DeleteBillingCustomerResponse) {
option (google.api.http) = {delete: "/v1beta1/billing/customers/{id}"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Billing";
summary: "Delete billing customer";
description: "Delete a billing customer by ID.";
};
}

// Subscriptions
rpc CreateSubscription(CreateSubscriptionRequest) returns (CreateSubscriptionResponse) {
option (google.api.http) = {
post: "/v1beta1/billing/customers/{customer_id}/subscriptions",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Subscription";
summary: "Create subscription";
description: "Create a new subscription for a billing customer.";
};
}

rpc GetSubscription(GetSubscriptionRequest) returns (GetSubscriptionResponse) {
option (google.api.http) = {get: "/v1beta1/billing/customers/{customer_id}/subscriptions/{id}"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Subscription";
summary: "Get subscription";
description: "Get a subscription by ID.";
};
}

rpc ListSubscriptions(ListSubscriptionsRequest) returns (ListSubscriptionsResponse) {
option (google.api.http) = {get: "/v1beta1/billing/customers/{customer_id}/subscriptions"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Subscription";
summary: "List subscriptions";
description: "List subscriptions of a billing customer.";
};
}

rpc UpdateSubscription(UpdateSubscriptionRequest) returns (UpdateSubscriptionResponse) {
option (google.api.http) = {
put: "/v1beta1/billing/customers/{customer_id}/subscriptions/{id}",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Subscription";
summary: "Update subscription";
description: "Update a subscription by ID.";
};
}

// Plans
rpc ListPlans(ListPlansRequest) returns (ListPlansResponse) {
option (google.api.http) = {get: "/v1beta1/billing/plans"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Plan";
summary: "List plans";
description: "List all plans.";
};
}

// Billing Entitlements
rpc CheckFeatureEntitlement(CheckFeatureEntitlementRequest) returns (CheckFeatureEntitlementResponse) {
option (google.api.http) = {
post: "/v1beta1/billing/check",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Entitlement";
summary: "Check entitlement";
description: "Check if a billing customer is entitled to a feature.";
};
}
}

// Billing

message BillingCustomerRequestBody {
string name = 1;
string email = 2;
string phone = 3;
BillingCustomer.Address address = 4;
string currency = 5;

google.protobuf.Struct metadata = 10;
}

message CreateBillingCustomerRequest {
// ID of the organization to create the billing customer for
string org_id = 1 [(validate.rules).string.min_len = 1];
// Billing customer to create.
BillingCustomerRequestBody body = 2;
}

message CreateBillingCustomerResponse {
// Created billing customer
BillingCustomer billing_customer = 1;
}

message GetBillingCustomerRequest {
// ID of the billing customer to get
string id = 1 [(validate.rules).string.min_len = 1];

string org_id = 2 [(validate.rules).string.min_len = 1];
}

message GetBillingCustomerResponse {
// Billing customer
BillingCustomer billing_customer = 1;
}

message UpdateBillingCustomerRequest {
// ID of the billing customer to update
string id = 1 [(validate.rules).string.min_len = 1];

string org_id = 2 [(validate.rules).string.min_len = 1];

// Billing customer to update.
BillingCustomerRequestBody body = 3;
}

message UpdateBillingCustomerResponse {
// Updated billing customer
BillingCustomer billing_customer = 1;
}

message ListBillingCustomersRequest {
// ID of the organization to list billing customers for
string org_id = 1 [(validate.rules).string.min_len = 1];
}

message ListBillingCustomersResponse {
// List of billing customers
repeated BillingCustomer billing_customers = 1;
}

message DeleteBillingCustomerRequest {
// ID of the billing customer to delete
string id = 1 [(validate.rules).string.min_len = 1];

string org_id = 2 [(validate.rules).string.min_len = 1];
}

message DeleteBillingCustomerResponse {}

message SubscriptionRequestBody {
string plan = 1;
string success_url = 2;
string cancel_url = 3;
int32 trail_days = 4;
}

message CreateSubscriptionRequest {
// ID of the billing customer to create the subscription for
string customer_id = 1 [(validate.rules).string.min_len = 1];
// Subscription to create
SubscriptionRequestBody body = 2;
}

message CreateSubscriptionResponse {
// Created subscription
Subscription subscription = 1;
}

message GetSubscriptionRequest {
// ID of the billing customer to get the subscription for
string customer_id = 1 [(validate.rules).string.min_len = 1];
// ID of the subscription to get
string id = 2 [(validate.rules).string.min_len = 1];
}

message GetSubscriptionResponse {
Subscription subscription = 1;
}

message ListSubscriptionsRequest {
// ID of the billing customer to list subscriptions for
string customer_id = 1 [(validate.rules).string.min_len = 1];
}

message ListSubscriptionsResponse {
// List of subscriptions
repeated Subscription subscriptions = 1;
}

message UpdateSubscriptionRequest {
// ID of the billing customer to update the subscription for
string customer_id = 1 [(validate.rules).string.min_len = 1];
// ID of the subscription to update
string id = 2 [(validate.rules).string.min_len = 1];
// Subscription to update
SubscriptionRequestBody body = 3;
}

message UpdateSubscriptionResponse {
// Updated subscription
Subscription subscription = 1;
}

message ListPlansRequest {}

message ListPlansResponse {
// List of plans
repeated Plan plans = 1;
}

message CheckFeatureEntitlementRequest {
string customer_id = 1 [(validate.rules).string.min_len = 1];
string feature = 2 [(validate.rules).string.min_len = 1];
}

message CheckFeatureEntitlementResponse {
bool status = 1;
}

// Authentication
Expand Down
91 changes: 91 additions & 0 deletions raystack/frontier/v1beta1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,97 @@ message Preference {
}];
}

message BillingCustomer {
message Address {
string line1 = 1;
string line2 = 2;
string city = 3;
string state = 4;
string postal_code = 5;
string country = 6;
}

string id = 1;
string org_id = 2;

string name = 3;
string email = 4;
string phone = 5;
Address address = 6;
string provider_id = 7;
string provider = 8;
string currency = 9;
string state = 10;

google.protobuf.Struct metadata = 20;
google.protobuf.Timestamp created_at = 21;
google.protobuf.Timestamp updated_at = 22;
}

message Subscription {
string id = 1;
string customer_id = 2;
string provider_id = 3;
string plan_id = 4;

string state = 5;
string success_url = 6;
string cancel_url = 7;
string checkout_url = 8;
int32 trial_days = 9;

google.protobuf.Struct metadata = 10;
google.protobuf.Timestamp created_at = 11;
google.protobuf.Timestamp updated_at = 12;
google.protobuf.Timestamp canceled_at = 13;
}

message Plan {
string id = 1;
string name = 2;
string title = 3;
string description = 4;
repeated Feature features = 5;
string interval = 6; // known intervals are "day", "week", "month", and "year"

google.protobuf.Struct metadata = 20;
google.protobuf.Timestamp created_at = 21;
google.protobuf.Timestamp updated_at = 22;
}

message Feature {
string id = 1;
string name = 2;
string title = 3;
string description = 4;
string plan_id = 5;
string state = 6;

Price price = 7;

google.protobuf.Struct metadata = 20;
google.protobuf.Timestamp created_at = 21;
google.protobuf.Timestamp updated_at = 22;
}

message Price {
string id = 1;
string feature_id = 2;
string provider_id = 3;
string name = 4;
string usage_type = 7; // known types are "licensed" and "metered"
string billing_scheme = 8; // known schemes are "tiered" and "flat"
string state = 9;
string currency = 10; // like "usd", "eur", "gbp"
int64 amount = 11;
string metered_aggregate = 13; // known aggregations are "sum", "last_during_period" and "max"
string tier_mode = 14; // known modes are "graduated" and "volume"

google.protobuf.Struct metadata = 20;
google.protobuf.Timestamp created_at = 21;
google.protobuf.Timestamp updated_at = 22;
}

// Model crud body

message RoleRequestBody {
Expand Down

0 comments on commit a524aeb

Please sign in to comment.