tenseleyflow/shithub / 575cecb

Browse files

web/orgs/billing_webhook: subscription.deleted for unknown subject is 200 no-op

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
575cecb655f86de1179238ea766851e0639fb020
Parents
3b56264
Tree
22e599c

1 changed file

StatusFile+-
M internal/web/handlers/orgs/billing_webhook.go 13 0
internal/web/handlers/orgs/billing_webhook.gomodified
@@ -189,6 +189,19 @@ func (h *Handlers) applyStripeSubscriptionEvent(ctx context.Context, event strip
189189
 	}
190190
 	principal, err := h.resolvePrincipalFromSubscription(ctx, &sub)
191191
 	if err != nil {
192
+		// PRO08 D5: customer.subscription.deleted for a sub that's
193
+		// not in our DB (no metadata match, no customer-id match, no
194
+		// subscription-id match) — log + 200 no-op so Stripe stops
195
+		// retrying. Loud-failure here only triggers infinite retries
196
+		// against state we'll never own. Other event types still
197
+		// surface the error so the operator notices misconfiguration.
198
+		if string(event.Type) == "customer.subscription.deleted" {
199
+			h.d.Logger.InfoContext(ctx, "org billing: subscription.deleted for unknown subject — no-op",
200
+				"event_id", event.ID,
201
+				"stripe_subscription_id", strings.TrimSpace(sub.ID),
202
+				"error", err)
203
+			return nil
204
+		}
192205
 		return err
193206
 	}
194207
 	h.recordWebhookSubject(ctx, event.ID, principal)