- commit
- e7dcc74
- parent
- 0eb5b0f
- author
- Eric Bower
- date
- 2024-10-15 14:45:39 +0000 UTC
fix(auth): associate payment history and `plus` feature flag
1 files changed,
+8,
-6
+8,
-6
1@@ -1892,26 +1892,28 @@ func (me *PsqlDB) AddPicoPlusUser(username, paymentType, txId string) error {
2 err = tx.Rollback()
3 }()
4
5+ var paymentHistoryId sql.NullString
6 if paymentType != "" {
7 data := db.PaymentHistoryData{
8 Notes: "",
9 TxID: txId,
10 }
11- _, err := tx.Exec(
12- `INSERT INTO payment_history (user_id, payment_type, amount, data) VALUES ($1, $2, 24 * 1000000, $3);`,
13+
14+ err := tx.QueryRow(
15+ `INSERT INTO payment_history (user_id, payment_type, amount, data) VALUES ($1, $2, 24 * 1000000, $3) RETURNING id;`,
16 user.ID,
17 paymentType,
18 data,
19- )
20+ ).Scan(&paymentHistoryId)
21 if err != nil {
22 return err
23 }
24 }
25
26 plus := me.createFeatureExpiresAt(user.ID, "plus")
27- plusQuery := `INSERT INTO feature_flags (user_id, name, data, expires_at)
28- VALUES ($1, 'plus', '{"storage_max":20000000000, "file_max":50000000}'::jsonb, $2);`
29- _, err = tx.Exec(plusQuery, user.ID, plus)
30+ plusQuery := `INSERT INTO feature_flags (user_id, name, data, expires_at, payment_history_id)
31+ VALUES ($1, 'plus', '{"storage_max":20000000000, "file_max":50000000}'::jsonb, $2, $3);`
32+ _, err = tx.Exec(plusQuery, user.ID, plus, paymentHistoryId)
33 if err != nil {
34 return err
35 }