Skip to content

: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.

feat(data-warehouse): make Stripe CustomerPaymentMethod webhook-capable (#66124)

Tom Owersef8b8f9d004e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py
index 17c467b13b28..b650e3d6c94f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py
@@ -47,6 +47,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.stripe.con
INVOICE_RESOURCE_NAME,
PRODUCT_RESOURCE_NAME,
RESOURCE_TO_STRIPE_OBJECT_TYPE,
+ RESOURCE_TO_STRIPE_WEBHOOK_EVENT,
SUBSCRIPTION_RESOURCE_NAME,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.stripe.settings import (
@@ -318,12 +319,13 @@ If automatic creation failed due to a permissions error and you're using a restr
SourceSchema(
name=endpoint,
supports_incremental=False,
- # Webhook-only endpoints (e.g. Discount) have no list API and therefore no
- # incremental fields, but they must still expose webhook support so the
- # warehouse pipeline can route events into the correct table.
+ # An endpoint supports webhooks iff a Stripe event emits its object type — i.e. it's in
+ # RESOURCE_TO_STRIPE_WEBHOOK_EVENT (the same map that drives event subscription) — or
+ # it's webhook-only (e.g. Discount, no list API). This is what lets CustomerPaymentMethod
+ # move to webhook sync after its initial backfill instead of re-sweeping every customer,
+ # while CustomerBalanceTransaction (no Stripe event) stays API-sweep-only.
supports_webhooks=(
- STRIPE_APPEND_ONLY_INCREMENTAL_FIELDS.get(endpoint, None) is not None
- or endpoint in STRIPE_WEBHOOK_ONLY_ENDPOINTS
+ endpoint in RESOURCE_TO_STRIPE_WEBHOOK_EVENT or endpoint in STRIPE_WEBHOOK_ONLY_ENDPOINTS
),
webhook_only=endpoint in STRIPE_WEBHOOK_ONLY_ENDPOINTS,
# nested resources are only full refresh and are not in STRIPE_APPEND_ONLY_INCREMENTAL_FIELDS
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.py
index fe6c61898132..7b5840a23b67 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
@@ -224,3 +224,19 @@ class TestWebhookEventMapping:
# CustomerPaymentMethod keeps its mapping, so payment_method.* events stay subscribed.
assert RESOURCE_TO_STRIPE_WEBHOOK_EVENT[CUSTOMER_PAYMENT_METHOD_RESOURCE_NAME] == "payment_method"
assert any(e.startswith("payment_method.") for e in _all_known_webhook_events())
+
+
+class TestSchemaWebhookCapability:
+ def setup_method(self):
+ self.source = StripeSource()
+ config = StripeSourceConfig(
+ auth_method=StripeAuthMethodConfig(selection="api_key", stripe_secret_key="sk_test_123")
+ )
+ self.by_name = {s.name: s for s in self.source.get_schemas(config, team_id=1)}
+
+ def test_webhook_capability_matches_event_map(self):
+ # supports_webhooks must track the webhook-event map exactly (plus webhook-only tables),
+ # so the capability and the actual event subscription never drift apart.
+ for name, schema in self.by_name.items():
+ expected = name in RESOURCE_TO_STRIPE_WEBHOOK_EVENT or schema.webhook_only
+ assert schema.supports_webhooks is expected, name