Skip to content

Commit

Permalink
feat: list all billing accounts via admin APIs
Browse files Browse the repository at this point in the history
- raystack/proton#340

Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma committed Feb 26, 2024
1 parent 32afd8b commit 7d2b56b
Show file tree
Hide file tree
Showing 8 changed files with 806 additions and 208 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TAG := $(shell git rev-list --tags --max-count=1)
VERSION := $(shell git describe --tags ${TAG})
.PHONY: build check fmt lint test test-race vet test-cover-html help install proto ui
.DEFAULT_GOAL := build
PROTON_COMMIT := "7946dab27af53879cbc694da726432727e85c336"
PROTON_COMMIT := "af92b2d5dbd43c1aa8a9054449ee662f22e01442"

ui:
@echo " > generating ui build"
Expand Down
24 changes: 24 additions & 0 deletions internal/api/v1beta1/billing_customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ func (h Handler) CreateBillingAccount(ctx context.Context, request *frontierv1be
}, nil
}

func (h Handler) ListAllBillingAccounts(ctx context.Context, request *frontierv1beta1.ListAllBillingAccountsRequest) (*frontierv1beta1.ListAllBillingAccountsResponse, error) {
logger := grpczap.Extract(ctx)
var customers []*frontierv1beta1.BillingAccount
customerList, err := h.customerService.List(ctx, customer.Filter{
OrgID: request.GetOrgId(),
})
if err != nil {
logger.Error(err.Error())
return nil, grpcInternalServerError
}
for _, v := range customerList {
customerPB, err := transformCustomerToPB(v)
if err != nil {
logger.Error(err.Error())
return nil, grpcInternalServerError
}
customers = append(customers, customerPB)
}

return &frontierv1beta1.ListAllBillingAccountsResponse{
BillingAccounts: customers,
}, nil
}

func (h Handler) ListBillingAccounts(ctx context.Context, request *frontierv1beta1.ListBillingAccountsRequest) (*frontierv1beta1.ListBillingAccountsResponse, error) {
logger := grpczap.Extract(ctx)
if request.GetOrgId() == "" {
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/interceptors/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,9 @@ var authorizationValidationMap = map[string]func(ctx context.Context, handler *v
"/raystack.frontier.v1beta1.AdminService/ListAllInvoices": func(ctx context.Context, handler *v1beta1.Handler, req any) error {
return handler.IsSuperUser(ctx)
},
"/raystack.frontier.v1beta1.AdminService/ListAllBillingAccounts": func(ctx context.Context, handler *v1beta1.Handler, req any) error {
return handler.IsSuperUser(ctx)
},
}

// stripeTestClockEnabledEndpoints is a map of endpoints that are allowed to use stripe test clock
Expand Down
49 changes: 49 additions & 0 deletions proto/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,47 @@ paths:
$ref: '#/definitions/rpcStatus'
tags:
- Authz
/v1beta1/admin/billing/accounts:
get:
summary: List all billing accounts
description: Lists all the billing accounts from all the organizations in a Frontier instance. It can be filtered by organization.
operationId: AdminService_ListAllBillingAccounts
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1beta1ListAllBillingAccountsResponse'
"400":
description: Bad Request - The request was malformed or contained invalid parameters.
schema:
$ref: '#/definitions/rpcStatus'
"401":
description: Unauthorized - Authentication is required
schema:
$ref: '#/definitions/rpcStatus'
"403":
description: Forbidden - User does not have permission to access the resource
schema:
$ref: '#/definitions/rpcStatus'
"404":
description: Not Found - The requested resource was not found
schema:
$ref: '#/definitions/rpcStatus'
"500":
description: Internal Server Error. Returned when theres is something wrong with Frontier server.
schema:
$ref: '#/definitions/rpcStatus'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/rpcStatus'
parameters:
- name: org_id
in: query
required: false
type: string
tags:
- Billing
/v1beta1/admin/billing/invoices:
get:
summary: List all invoices
Expand Down Expand Up @@ -9023,6 +9064,14 @@ definitions:
type: string
title: RSA private key as string
readOnly: true
v1beta1ListAllBillingAccountsResponse:
type: object
properties:
billing_accounts:
type: array
items:
type: object
$ref: '#/definitions/v1beta1BillingAccount'
v1beta1ListAllInvoicesResponse:
type: object
properties:
Expand Down
570 changes: 363 additions & 207 deletions proto/v1beta1/admin.pb.go

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions proto/v1beta1/admin.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d2b56b

Please sign in to comment.