Skip to content

Commit 32a8c89

Browse files
author
Andrew Farries
committed
Make run command use new Stripe client
Give an instance of the stripe client to the stripe billing controller.
1 parent 619525a commit 32a8c89

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

components/usage/cmd/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ func run() *cobra.Command {
4747
var billingController controller.BillingController = &controller.NoOpBillingController{}
4848

4949
if apiKeyFile != "" {
50-
err = stripe.Authenticate(apiKeyFile)
50+
c, err := stripe.Authenticate(apiKeyFile)
5151
if err != nil {
5252
log.WithError(err).Fatal("Failed to initialize stripe client.")
5353
}
54-
billingController = &controller.StripeBillingController{}
54+
billingController = controller.NewStripeBillingController(c)
5555
}
5656

5757
ctrl, err := controller.New(schedule, controller.NewUsageReconciler(conn, billingController))

components/usage/pkg/controller/billing.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@ type BillingController interface {
1111
}
1212

1313
type NoOpBillingController struct{}
14-
type StripeBillingController struct{}
1514

1615
func (b *NoOpBillingController) Reconcile(report []TeamUsage) {}
1716

17+
type StripeBillingController struct {
18+
sc *stripe.Client
19+
}
20+
21+
func NewStripeBillingController(sc *stripe.Client) *StripeBillingController {
22+
return &StripeBillingController{sc: sc}
23+
}
24+
1825
func (b *StripeBillingController) Reconcile(report []TeamUsage) {
1926
// Convert the usage report to sum all entries for the same team.
2027
var summedReport = make(map[string]int64)
2128
for _, usageEntry := range report {
2229
summedReport[usageEntry.TeamID] += usageEntry.WorkspaceSeconds
2330
}
2431

25-
stripe.UpdateUsage(summedReport)
32+
b.sc.UpdateUsage(summedReport)
2633
}

0 commit comments

Comments
 (0)