Skip to content

Commit 5dcd40d

Browse files
committed
fix(invoice): cost customer filter
1 parent 61e113d commit 5dcd40d

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

openmeter/billing/httpdriver/handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/openmeterio/openmeter/openmeter/app"
1111
appstripe "github.com/openmeterio/openmeter/openmeter/app/stripe"
1212
"github.com/openmeterio/openmeter/openmeter/billing"
13+
"github.com/openmeterio/openmeter/openmeter/customer"
1314
"github.com/openmeterio/openmeter/openmeter/meter"
1415
"github.com/openmeterio/openmeter/openmeter/namespace/namespacedriver"
1516
"github.com/openmeterio/openmeter/openmeter/productcatalog/feature"
@@ -65,6 +66,7 @@ type handler struct {
6566
streamingService streaming.Connector
6667
meterService meter.Service
6768
featureService feature.FeatureConnector
69+
customerService customer.Service
6870
namespaceDecoder namespacedriver.NamespaceDecoder
6971
featureSwitches config.BillingFeatureSwitchesConfiguration
7072
options []httptransport.HandlerOption
@@ -89,6 +91,7 @@ func New(
8991
streamingService streaming.Connector,
9092
featureService feature.FeatureConnector,
9193
meterService meter.Service,
94+
customerService customer.Service,
9295
options ...httptransport.HandlerOption,
9396
) Handler {
9497
return &handler{
@@ -100,5 +103,6 @@ func New(
100103
streamingService: streamingService,
101104
meterService: meterService,
102105
featureService: featureService,
106+
customerService: customerService,
103107
}
104108
}

openmeter/billing/httpdriver/invoicecost.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/openmeterio/openmeter/api"
1313
"github.com/openmeterio/openmeter/openmeter/billing"
14+
"github.com/openmeterio/openmeter/openmeter/customer"
1415
"github.com/openmeterio/openmeter/openmeter/meter"
1516
"github.com/openmeterio/openmeter/openmeter/streaming"
1617
"github.com/openmeterio/openmeter/pkg/framework/commonhttp"
@@ -111,10 +112,24 @@ func (h *handler) GetInvoiceLineCost() GetInvoiceLineCostHandler {
111112
meterGroupByFilters[k] = []string{v}
112113
}
113114

115+
// Get the customer
116+
customer, err := h.customerService.GetCustomer(ctx, customer.GetCustomerInput{
117+
CustomerID: lo.ToPtr(invoice.CustomerID()),
118+
})
119+
if err != nil {
120+
return GetInvoiceLineCostResponse{}, err
121+
}
122+
123+
if customer == nil {
124+
return GetInvoiceLineCostResponse{}, fmt.Errorf("customer cannot be nil")
125+
}
126+
127+
// Query the meter
114128
meterQueryParams := streaming.QueryParams{
115-
From: &line.Period.Start,
116-
To: &line.Period.End,
117-
FilterGroupBy: meterGroupByFilters,
129+
From: &line.Period.Start,
130+
To: &line.Period.End,
131+
FilterGroupBy: meterGroupByFilters,
132+
FilterCustomer: []streaming.Customer{*customer},
118133
}
119134

120135
if request.Params.GroupBy != nil {

openmeter/server/router/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ func NewRouter(config Config) (*Router, error) {
365365
config.StreamingConnector,
366366
config.FeatureConnector,
367367
config.MeterManageService,
368+
config.Customer,
368369
httptransport.WithErrorHandler(config.ErrorHandler),
369370
)
370371

0 commit comments

Comments
 (0)