@@ -60,15 +60,17 @@ func (s *SubscriptionService) CreateCheckoutSession(user *core.Record, plan stri
6060 return "" , ErrPlanInvalid
6161 }
6262
63- _ , err := s .CheckValidSubscription (user .Original ())
64-
65- if ! errors .Is (err , sql .ErrNoRows ) {
63+ sub , err := s .CheckValidSubscription (user .Original ())
6664
65+ // 情况 A: 找到了有效订阅 (err == nil)
66+ if err == nil && sub != nil {
6767 return "" , ErrAlreadySubscribed
6868 }
6969
70- if err != nil {
71- s .app .Logger ().Warn ("Failed to create checkout session" , err )
70+ // 情况 B: 发生了真正的数据库错误 (不是“没找到”)
71+ if err != nil && ! errors .Is (err , sql .ErrNoRows ) {
72+ // 结构化日志修复:使用 key-value
73+ s .app .Logger ().Error ("Failed to check subscription" , "error" , err .Error (), "userId" , user .Id )
7274 return "" , errors .New ("check subscription failed" )
7375 }
7476
@@ -122,8 +124,6 @@ func (s *SubscriptionService) HandleInvoicePaid(inv stripe.Invoice) error {
122124
123125 record := core .NewRecord (collection )
124126
125- fmt .Println (inv .Lines .Data [0 ].Pricing .PriceDetails .Price )
126-
127127 priceID := inv .Lines .Data [0 ].Pricing .PriceDetails .Price
128128
129129 priceIDMap := s .cfg .PriceToPlan [priceID ]
@@ -135,8 +135,6 @@ func (s *SubscriptionService) HandleInvoicePaid(inv stripe.Invoice) error {
135135 }
136136
137137 expiresAt := time .Unix (inv .Lines .Data [0 ].Period .End , 0 ).UTC ()
138- fmt .Println ("Expires at:" , expiresAt )
139- fmt .Println (inv .Lines .Data [0 ].Period .End )
140138
141139 record .Set ("user_id" , user .Id )
142140 record .Set ("plan" , priceIDMap )
0 commit comments