Skip to content

Commit 71615a8

Browse files
authored
Fix wallets request (#4651)
1 parent 2d33d4c commit 71615a8

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

api/server/handlers/billing/create.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7-
"time"
87

98
"github.com/porter-dev/porter/api/server/handlers"
109
"github.com/porter-dev/porter/api/server/shared"
@@ -147,12 +146,9 @@ func (c *CreateBillingHandler) grantRewardIfReferral(ctx context.Context, referr
147146
}
148147

149148
if referral != nil && referral.Status != models.ReferralStatusCompleted {
150-
// Lago requires an expiration to be passed in, so we set it to 5 years which in
151-
// practice will mean the credits will most likely run out before expiring
152-
expiresAt := time.Now().AddDate(5, 0, 0)
153149
name := "Referral reward"
154150
rewardAmount := c.Config().BillingManager.LagoClient.DefaultRewardAmountCents
155-
err := c.Config().BillingManager.LagoClient.CreateCreditsGrant(ctx, referrerProject.ID, name, rewardAmount, &expiresAt, referrerProject.EnableSandbox)
151+
err := c.Config().BillingManager.LagoClient.CreateCreditsGrant(ctx, referrerProject.ID, name, rewardAmount, referrerProject.EnableSandbox)
156152
if err != nil {
157153
return telemetry.Error(ctx, span, err, "failed to grand credits reward")
158154
}

api/server/handlers/billing/ingest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (c *IngestEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
7171
}
7272
}
7373

74-
plan, err := c.Config().BillingManager.LagoClient.GetCustomeActivePlan(ctx, proj.ID, proj.EnableSandbox)
74+
plan, err := c.Config().BillingManager.LagoClient.GetCustomerActivePlan(ctx, proj.ID, proj.EnableSandbox)
7575
if err != nil {
7676
err := telemetry.Error(ctx, span, err, "error getting active subscription")
7777
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))

api/server/handlers/billing/plan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (c *ListPlansHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4343
return
4444
}
4545

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

157-
plan, err := c.Config().BillingManager.LagoClient.GetCustomeActivePlan(ctx, proj.ID, proj.EnableSandbox)
157+
plan, err := c.Config().BillingManager.LagoClient.GetCustomerActivePlan(ctx, proj.ID, proj.EnableSandbox)
158158
if err != nil {
159159
err := telemetry.Error(ctx, span, err, "error getting active subscription")
160160
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))

internal/billing/usage.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ func (m LagoClient) CreateCustomerWithPlan(ctx context.Context, userEmail string
100100
}
101101

102102
walletName := "Porter Credits"
103-
expiresAt := time.Now().UTC().AddDate(0, 1, 0).Truncate(24 * time.Hour)
104-
105-
err = m.CreateCreditsGrant(ctx, projectID, walletName, defaultStarterCreditsCents, &expiresAt, sandboxEnabled)
103+
err = m.CreateCreditsGrant(ctx, projectID, walletName, defaultStarterCreditsCents, sandboxEnabled)
106104
if err != nil {
107105
return telemetry.Error(ctx, span, err, "error while creating starter credits grant")
108106
}
@@ -145,8 +143,8 @@ func (m LagoClient) CheckIfCustomerExists(ctx context.Context, projectID uint, e
145143
return true, nil
146144
}
147145

148-
// GetCustomeActivePlan will return the active plan for the customer
149-
func (m LagoClient) GetCustomeActivePlan(ctx context.Context, projectID uint, sandboxEnabled bool) (plan types.Plan, err error) {
146+
// GetCustomerActivePlan will return the active plan for the customer
147+
func (m LagoClient) GetCustomerActivePlan(ctx context.Context, projectID uint, sandboxEnabled bool) (plan types.Plan, err error) {
150148
ctx, span := telemetry.NewSpan(ctx, "get-active-subscription")
151149
defer span.End()
152150

@@ -261,7 +259,7 @@ func (m LagoClient) CheckCustomerCouponExpiration(ctx context.Context, projectID
261259
}
262260

263261
// CreateCreditsGrant will create a new credit grant for the customer with the specified amount
264-
func (m LagoClient) CreateCreditsGrant(ctx context.Context, projectID uint, name string, grantAmount int64, expiresAt *time.Time, sandboxEnabled bool) (err error) {
262+
func (m LagoClient) CreateCreditsGrant(ctx context.Context, projectID uint, name string, grantAmount int64, sandboxEnabled bool) (err error) {
265263
ctx, span := telemetry.NewSpan(ctx, "create-credits-grant")
266264
defer span.End()
267265

@@ -283,13 +281,12 @@ func (m LagoClient) CreateCreditsGrant(ctx context.Context, projectID uint, name
283281
Currency: lago.USD,
284282
GrantedCredits: strconv.FormatInt(grantAmount, 10),
285283
// Rate is 1 credit = 1 cent
286-
RateAmount: "0.01",
287-
ExpirationAt: expiresAt,
284+
RateAmount: "0.01",
288285
}
289286

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

295292
return nil

0 commit comments

Comments
 (0)