tenseleyflow/shithub / 987485f

Browse files

web/auth/billing: gate Manage CTA on subscription_id, not customer_id

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
987485fed6d6fb0f59be5543a74560f1fab83a31
Parents
b03b58d
Tree
600ca68

1 changed file

StatusFile+-
M internal/web/handlers/auth/billing_settings.go 17 11
internal/web/handlers/auth/billing_settings.gomodified
@@ -207,17 +207,23 @@ func (h *Handlers) renderUserSettingsBilling(w http.ResponseWriter, r *http.Requ
207207
 		debug = h.userBillingDebugView(r, state)
208208
 	}
209209
 	_ = h.d.Render.RenderPage(w, r, "settings/billing", map[string]any{
210
-		"Title":                 "Billing and plans",
211
-		"SettingsActive":        "billing",
212
-		"CSRFToken":             middleware.CSRFTokenForRequest(r),
213
-		"Username":              username,
214
-		"BillingEnabled":        h.d.BillingEnabled,
215
-		"Error":                 errMsg,
216
-		"Notice":                notice,
217
-		"BillingAlert":          userBillingAlertForState(state),
218
-		"Summary":               userBillingSummary(state),
219
-		"CanStartCheckout":      h.billingConfiguredForUser(),
220
-		"CanManageSubscription": h.billingConfiguredForUser() && state.StripeCustomerID.Valid && strings.TrimSpace(state.StripeCustomerID.String) != "",
210
+		"Title":            "Billing and plans",
211
+		"SettingsActive":   "billing",
212
+		"CSRFToken":        middleware.CSRFTokenForRequest(r),
213
+		"Username":         username,
214
+		"BillingEnabled":   h.d.BillingEnabled,
215
+		"Error":            errMsg,
216
+		"Notice":           notice,
217
+		"BillingAlert":     userBillingAlertForState(state),
218
+		"Summary":          userBillingSummary(state),
219
+		"CanStartCheckout": h.billingConfiguredForUser(),
220
+		// Gate on StripeSubscriptionID, not StripeCustomerID. A
221
+		// customer record is created when the Checkout Session is
222
+		// minted (before payment); a subscription id only appears
223
+		// after customer.subscription.created lands. Gating on the
224
+		// customer id surfaced "Manage or cancel" buttons for users
225
+		// who abandoned checkout without paying.
226
+		"CanManageSubscription": h.billingConfiguredForUser() && state.StripeSubscriptionID.Valid && strings.TrimSpace(state.StripeSubscriptionID.String) != "",
221227
 		"GracePeriodLabel":      userFormatGracePeriod(h.d.BillingGracePeriod),
222228
 		"Invoices":              userBillingInvoiceViews(invoices),
223229
 		"IsSiteAdmin":           viewer.IsSiteAdmin,