diff --git a/auth/api.go b/auth/api.go index ba0af0cb..9e9f03d5 100644 --- a/auth/api.go +++ b/auth/api.go @@ -555,7 +555,7 @@ func paymentWebhookHandler(apiConfig *shared.ApiConfig) http.HandlerFunc { return } - err = dbpool.AddPicoPlusUser(username, "lemonsqueezy", txID) + err = dbpool.AddPicoPlusUser(username, email, "lemonsqueezy", txID) if err != nil { log.Error("failed to add pico+ user", "err", err) w.WriteHeader(http.StatusOK) diff --git a/auth/api_test.go b/auth/api_test.go index fdf1824e..bc0c3dd4 100644 --- a/auth/api_test.go +++ b/auth/api_test.go @@ -197,7 +197,7 @@ type AuthDb struct { *stub.StubDB } -func (a *AuthDb) AddPicoPlusUser(username, from, txid string) error { +func (a *AuthDb) AddPicoPlusUser(username, email, from, txid string) error { return nil } diff --git a/cmd/scripts/pico-plus/main.go b/cmd/scripts/pico-plus/main.go index dad94e44..3bfede55 100644 --- a/cmd/scripts/pico-plus/main.go +++ b/cmd/scripts/pico-plus/main.go @@ -30,7 +30,7 @@ func main() { "txId", txId, ) - err := dbpool.AddPicoPlusUser(username, paymentType, txId) + err := dbpool.AddPicoPlusUser(username, "test@pico.sh", paymentType, txId) if err != nil { logger.Error("Failed to add pico+ user", "err", err) os.Exit(1) diff --git a/db/db.go b/db/db.go index a9a5bcc0..d325e2b2 100644 --- a/db/db.go +++ b/db/db.go @@ -381,7 +381,7 @@ type DB interface { VisitSummary(opts *SummaryOpts) (*SummaryVisits, error) FindVisitSiteList(opts *SummaryOpts) ([]*VisitUrl, error) - AddPicoPlusUser(username string, paymentType, txId string) error + AddPicoPlusUser(username, email, paymentType, txId string) error FindFeatureForUser(userID string, feature string) (*FeatureFlag, error) FindFeaturesForUser(userID string) ([]*FeatureFlag, error) HasFeatureForUser(userID string, feature string) bool diff --git a/db/postgres/storage.go b/db/postgres/storage.go index 8818594e..44302529 100644 --- a/db/postgres/storage.go +++ b/db/postgres/storage.go @@ -1919,7 +1919,7 @@ func (me *PsqlDB) createFeatureExpiresAt(userID, name string) time.Time { return ff.ExpiresAt.AddDate(1, 0, 0) } -func (me *PsqlDB) AddPicoPlusUser(username, paymentType, txId string) error { +func (me *PsqlDB) AddPicoPlusUser(username, email, paymentType, txId string) error { user, err := me.FindUserForName(username) if err != nil { return err @@ -1953,8 +1953,8 @@ func (me *PsqlDB) AddPicoPlusUser(username, paymentType, txId string) error { } plus := me.createFeatureExpiresAt(user.ID, "plus") - plusQuery := `INSERT INTO feature_flags (user_id, name, data, expires_at, payment_history_id) - VALUES ($1, 'plus', '{"storage_max":10000000000, "file_max":50000000}'::jsonb, $2, $3);` + plusQuery := fmt.Sprintf(`INSERT INTO feature_flags (user_id, name, data, expires_at, payment_history_id) + VALUES ($1, 'plus', '{"storage_max":10000000000, "file_max":50000000, "email": "%s"}'::jsonb, $2, $3);`, email) _, err = tx.Exec(plusQuery, user.ID, plus, paymentHistoryId) if err != nil { return err diff --git a/db/stub/stub.go b/db/stub/stub.go index 08816b07..a08c4f7b 100644 --- a/db/stub/stub.go +++ b/db/stub/stub.go @@ -281,6 +281,6 @@ func (me *StubDB) RemoveFeature(userID string, name string) error { return notImpl } -func (me *StubDB) AddPicoPlusUser(username, paymentType, txId string) error { +func (me *StubDB) AddPicoPlusUser(username, email, paymentType, txId string) error { return notImpl }