From b7b42af01da96f900e1e06070bcdc4509ce73185 Mon Sep 17 00:00:00 2001 From: Mauricio Araujo Date: Fri, 10 May 2024 14:36:04 -0400 Subject: [PATCH] Linting --- internal/billing/usage.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/billing/usage.go b/internal/billing/usage.go index 06dcb6fa8f..e8cc0eef76 100644 --- a/internal/billing/usage.go +++ b/internal/billing/usage.go @@ -103,7 +103,9 @@ func (m LagoClient) CreateCustomerWithPlan(ctx context.Context, userEmail string expiresAt := time.Now().UTC().AddDate(0, 1, 0).Truncate(24 * time.Hour) err = m.CreateCreditsGrant(ctx, projectID, starterWalletName, defaultStarterCreditsCents, &expiresAt, sandboxEnabled) - + if err != nil { + return telemetry.Error(ctx, span, err, "error while creating starter credits grant") + } return nil } @@ -122,6 +124,7 @@ func (m LagoClient) CreateCustomerWithPlan(ctx context.Context, userEmail string return err } +// CheckIfCustomerExists will check if the customer exists in Lago func (m LagoClient) CheckIfCustomerExists(ctx context.Context, projectID uint, enableSandbox bool) (exists bool, err error) { ctx, span := telemetry.NewSpan(ctx, "check-lago-customer-exists") defer span.End() @@ -139,6 +142,7 @@ func (m LagoClient) CheckIfCustomerExists(ctx context.Context, projectID uint, e return true, nil } +// GetCustomeActivePlan will return the active plan for the customer func (m LagoClient) GetCustomeActivePlan(ctx context.Context, projectID uint, sandboxEnabled bool) (plan types.Plan, err error) { ctx, span := telemetry.NewSpan(ctx, "get-active-subscription") defer span.End() @@ -234,7 +238,6 @@ func (m LagoClient) ListCustomerCredits(ctx context.Context, projectID uint, san if err != nil { return credits, telemetry.Error(ctx, span, err, "failed to get customer credits") } - defer resp.Body.Close() type ListWalletsResponse struct { Wallets []types.Wallet `json:"wallets"` @@ -256,6 +259,11 @@ func (m LagoClient) ListCustomerCredits(ctx context.Context, projectID uint, san response.RemainingBalanceCents += wallet.OngoingBalanceCents } + err = resp.Body.Close() + if err != nil { + return credits, telemetry.Error(ctx, span, err, "failed to close response body") + } + return response, nil } @@ -321,7 +329,6 @@ func (m LagoClient) ListCustomerUsage(ctx context.Context, customerID string, su }, } } - } return usage, nil @@ -344,9 +351,7 @@ func (m LagoClient) IngestEvents(ctx context.Context, subscriptionID string, eve batch := events[i:end] batchInput := make([]lago.EventInput, len(batch)) - for i := range batch { - externalSubscriptionID := subscriptionID if enableSandbox { // This hack has to be done because we can't infer the project id from the