Skip to content

Commit

Permalink
Fix wallets request
Browse files Browse the repository at this point in the history
  • Loading branch information
MauAraujo committed May 16, 2024
1 parent 2d33d4c commit ecd6075
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/server/handlers/billing/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *IngestEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
}

plan, err := c.Config().BillingManager.LagoClient.GetCustomeActivePlan(ctx, proj.ID, proj.EnableSandbox)
plan, err := c.Config().BillingManager.LagoClient.GetCustomerActivePlan(ctx, proj.ID, proj.EnableSandbox)
if err != nil {
err := telemetry.Error(ctx, span, err, "error getting active subscription")
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
Expand Down
4 changes: 2 additions & 2 deletions api/server/handlers/billing/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *ListPlansHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

plan, err := c.Config().BillingManager.LagoClient.GetCustomeActivePlan(ctx, proj.ID, proj.EnableSandbox)
plan, err := c.Config().BillingManager.LagoClient.GetCustomerActivePlan(ctx, proj.ID, proj.EnableSandbox)
if err != nil {
err := telemetry.Error(ctx, span, err, "error getting active subscription")
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
Expand Down Expand Up @@ -154,7 +154,7 @@ func (c *ListCustomerUsageHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
return
}

plan, err := c.Config().BillingManager.LagoClient.GetCustomeActivePlan(ctx, proj.ID, proj.EnableSandbox)
plan, err := c.Config().BillingManager.LagoClient.GetCustomerActivePlan(ctx, proj.ID, proj.EnableSandbox)
if err != nil {
err := telemetry.Error(ctx, span, err, "error getting active subscription")
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
Expand Down
9 changes: 4 additions & 5 deletions internal/billing/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ 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) {
// GetCustomerActivePlan will return the active plan for the customer
func (m LagoClient) GetCustomerActivePlan(ctx context.Context, projectID uint, sandboxEnabled bool) (plan types.Plan, err error) {
ctx, span := telemetry.NewSpan(ctx, "get-active-subscription")
defer span.End()

Expand Down Expand Up @@ -283,13 +283,12 @@ func (m LagoClient) CreateCreditsGrant(ctx context.Context, projectID uint, name
Currency: lago.USD,
GrantedCredits: strconv.FormatInt(grantAmount, 10),
// Rate is 1 credit = 1 cent
RateAmount: "0.01",
ExpirationAt: expiresAt,
RateAmount: "0.01",
}

_, lagoErr := m.client.Wallet().Create(ctx, walletInput)
if lagoErr != nil {
return telemetry.Error(ctx, span, fmt.Errorf(lagoErr.ErrorCode), "failed to create credits grant")
return telemetry.Error(ctx, span, fmt.Errorf(lagoErr.ErrorCode), "failed to create wallet")
}

return nil
Expand Down

0 comments on commit ecd6075

Please sign in to comment.