@@ -13,6 +13,7 @@ import (
1313 "github.com/openmeterio/openmeter/openmeter/billing/charges"
1414 chargesasyncadvance "github.com/openmeterio/openmeter/openmeter/billing/charges/worker/asyncadvance"
1515 "github.com/openmeterio/openmeter/openmeter/billing/worker/asyncadvance"
16+ billingworkercollect "github.com/openmeterio/openmeter/openmeter/billing/worker/collect"
1617 "github.com/openmeterio/openmeter/openmeter/billing/worker/subscriptionsync"
1718 "github.com/openmeterio/openmeter/openmeter/subscription"
1819 "github.com/openmeterio/openmeter/openmeter/watermill/eventbus"
@@ -30,6 +31,7 @@ type WorkerOptions struct {
3031
3132 BillingService billing.Service
3233 BillingSubscriptionSync subscriptionsync.Service
34+ BillingCollector * billingworkercollect.InvoiceCollector
3335 // ChargesService is optional; when non-nil the worker handles AdvanceChargesEvent.
3436 ChargesService charges.ChargeService
3537 // External connectors
@@ -67,6 +69,10 @@ func (w WorkerOptions) Validate() error {
6769 return fmt .Errorf ("billing subscription sync handler is required" )
6870 }
6971
72+ if w .BillingCollector == nil {
73+ return fmt .Errorf ("billing collector is required" )
74+ }
75+
7076 return nil
7177}
7278
@@ -75,6 +81,7 @@ type Worker struct {
7581
7682 billingService billing.Service
7783 subscriptionSync subscriptionsync.Service
84+ invoiceCollector * billingworkercollect.InvoiceCollector
7885 asyncAdvanceHandler * asyncadvance.Handler
7986 asyncAdvanceChargesHandler * chargesasyncadvance.Handler
8087 nonPublishingHandler * grouphandler.NoPublishingHandler
@@ -109,6 +116,7 @@ func New(opts WorkerOptions) (*Worker, error) {
109116 worker := & Worker {
110117 billingService : opts .BillingService ,
111118 subscriptionSync : opts .BillingSubscriptionSync ,
119+ invoiceCollector : opts .BillingCollector ,
112120 asyncAdvanceHandler : asyncAdvancer ,
113121 asyncAdvanceChargesHandler : asyncAdvanceChargesHandler ,
114122 lockdownNamespaces : opts .LockdownNamespaces ,
@@ -199,6 +207,13 @@ func (w *Worker) eventHandler(opts WorkerOptions) (*grouphandler.NoPublishingHan
199207
200208 return w .asyncAdvanceHandler .Handle (ctx , event )
201209 }),
210+ grouphandler .NewGroupEventHandler (func (ctx context.Context , event * billing.CollectCustomerInvoicesEvent ) error {
211+ if event != nil && slices .Contains (w .lockdownNamespaces , event .Namespace ) {
212+ return nil
213+ }
214+
215+ return w .invoiceCollector .HandleCollectCustomerInvoicesEvent (ctx , event )
216+ }),
202217 grouphandler .NewGroupEventHandler (func (ctx context.Context , event * charges.AdvanceChargesEvent ) error {
203218 if w .asyncAdvanceChargesHandler == nil {
204219 return nil
0 commit comments