:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-warehouse): say what to do when Stripe blocks a connected-account webhook (#95612)
Tom Owersf77496247046
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.pyindex 65db09013929..17fe07d284ba 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py@@ -1487,6 +1487,18 @@ def _is_stripe_webhook_limit_error(error_str: str) -> bool:return "maximum of" in lowered and "webhook endpoint" in lowered+def _is_stripe_connected_account_webhook_error(error_str: str) -> bool:+ """Detect Stripe's refusal to manage webhook endpoints on a connected account.++ A Connect request (platform key plus a ``stripe_account`` header, which every OAuth+ connection uses) can never create the endpoint on the connected account, so the message+ carries "permission" and would otherwise land in the generic permission branch and tell the+ user to widen a scope or reconnect. Neither can lift the restriction.+ """+ lowered = error_str.lower()+ return "connected account" in lowered and "webhook endpoint" in lowered++def create_webhook(api_key: str,stripe_account_id: str | None,@@ -1553,6 +1565,15 @@ def create_webhook(),)+ if _is_stripe_connected_account_webhook_error(error_str):+ return WebhookCreationResult(+ success=False,+ error=(+ "Stripe doesn't allow creating a webhook endpoint on a connected account. "+ "Set up the webhook manually below, on your platform account in Stripe."+ ),+ )+if _is_stripe_webhook_limit_error(error_str):return WebhookCreationResult(success=False,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.pyindex 596441577ac2..ded7890cec4c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py@@ -1458,17 +1458,27 @@ class TestSchemaWebhookCapability:class TestCreateWebhookPermissionErrorCopy:# Regression test: a permission-denied webhook creation used to always tell the user to add# the "Write" permission to their API key, even when the source was connected via OAuth and- # has no API key to edit.+ # has no API key to edit. Stripe's connected-account refusal also reads as a permission+ # error, but neither a wider scope nor a reconnect can lift it.@parameterized.expand([- ("api_key", "add the 'Write' permission for 'Webhook endpoints' to your API key"),- ("oauth", "reconnect your Stripe integration"),+ (+ "api_key",+ "forbidden",+ "add the 'Write' permission for 'Webhook endpoints' to your API key",+ ),+ ("oauth", "forbidden", "reconnect your Stripe integration"),+ (+ "oauth",+ "You do not have permission to configure webhook endpoints on connected accounts.",+ "on your platform account in Stripe",+ ),])- def test_permission_error_message_matches_auth_method(self, auth_method, expected_phrase):+ def test_permission_error_message_matches_auth_method(self, auth_method, stripe_message, expected_phrase):with patch.object(stripe_module, "StripeClient") as mock_client_cls:mock_client = mock_client_cls.return_value- mock_client.webhook_endpoints.create.side_effect = stripe_lib.PermissionError("forbidden")+ mock_client.webhook_endpoints.create.side_effect = stripe_lib.PermissionError(stripe_message)result = create_webhook(api_key="sk_test_123",