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): add dodo payments discount customers and moderation usage tables (#126940)

Tom Owers926001b0be2c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 1922fbe610f7..ba8ccf86df2f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -3941,6 +3941,8 @@ Diffed against: <https://raw.githubusercontent.com/dodopayments/dodopayments-pyt
- [x] `Customer wallet ledger entries (GET /customers/{customer_id}/wallets/ledger-entries)` — reconcile wallet credits and debits with customer payment activity (medium)
- [x] `Entitlement grants (GET /entitlements/{id}/grants)` — associate entitlement definitions with customer access grants and subscription references (medium)
- [x] `Customer emails (GET /customers/{customer_id}/emails)` — analyze transactional email delivery activity by customer and message type (medium)
+- [x] `Discount customers (GET /discounts/{discount_id}/customers)` — see which customers each discount's allow list admits and join them to redemptions (medium)
+- [x] `Moderation usage (GET /moderation/usage)` — track billable moderation screens per day over the trailing 30 days (low)
Note: Extracted every GET path from the official Python SDK operation index and checked selected resource modules and response types. The advertised documentation spec URL returned HTML, so the SDK provided the usable reference. Existing tables cover top-level billing and catalog collections; missing resources need payment, payout, subscription, customer, or entitlement fan-out. Webhooks, payment-method plumbing, invoice PDFs, and duplicate CSV exports were excluded.
diff --git a/products/warehouse_sources/sources/dodopayments/canonical_descriptions.py b/products/warehouse_sources/sources/dodopayments/canonical_descriptions.py
index 6609eff6090f..245c04276bd2 100644
--- a/products/warehouse_sources/sources/dodopayments/canonical_descriptions.py
+++ b/products/warehouse_sources/sources/dodopayments/canonical_descriptions.py
@@ -557,4 +557,20 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"created_at": "Timestamp when the email was sent.",
},
},
+ "discount_customers": {
+ "description": "Customers on each discount's allow list, one row per discount and customer.",
+ "docs_url": f"{_DOCS_ROOT}/discounts/list-discount-customers",
+ "columns": {
+ "discount_id": "Discount whose allow list the customer is on.",
+ "customer_id": "Customer attached to the discount's allow list.",
+ },
+ },
+ "moderation_usage": {
+ "description": "Billable moderation screens per UTC day over the last 30 days. Days with no screens are left out.",
+ "docs_url": f"{_DOCS_ROOT}/moderation/get-usage",
+ "columns": {
+ "date": "The UTC day.",
+ "screens": "Billable screens on that day, charged or not.",
+ },
+ },
}
diff --git a/products/warehouse_sources/sources/dodopayments/dodopayments.py b/products/warehouse_sources/sources/dodopayments/dodopayments.py
index 835102987484..1c1c5d6a4ba6 100644
--- a/products/warehouse_sources/sources/dodopayments/dodopayments.py
+++ b/products/warehouse_sources/sources/dodopayments/dodopayments.py
@@ -118,10 +118,10 @@ def get_resource(
endpoint_config: Endpoint = {
"path": config.path,
"params": params,
- "data_selector": "items",
+ "data_selector": config.data_selector,
"paginator": DodoPaymentsPaginator() if config.paginated else "single_page",
- # Every list endpoint wraps its rows in `items`; a body without it is a response
- # shape change, which should fail loud rather than sync zero rows.
+ # Every endpoint wraps its rows in a known key; a body without it is a response shape
+ # change, which should fail loud rather than sync zero rows.
"data_selector_required": True,
"data_selector_empty_ok": True,
}
diff --git a/products/warehouse_sources/sources/dodopayments/settings.py b/products/warehouse_sources/sources/dodopayments/settings.py
index 8a172fa7f3b3..559c8eb9a3d7 100644
--- a/products/warehouse_sources/sources/dodopayments/settings.py
+++ b/products/warehouse_sources/sources/dodopayments/settings.py
@@ -51,6 +51,7 @@ class DodoPaymentsEndpointConfig:
partition_key: str | None = "created_at"
# `/brands` is the one list endpoint that takes no query parameters, so it is a single page.
paginated: bool = True
+ data_selector: str = "items"
# Fields on these resources are restated in place after creation, so incremental runs need
# the trailing re-read window above.
restated: bool = False
@@ -291,6 +292,31 @@ DODOPAYMENTS_ENDPOINTS: dict[str, DodoPaymentsEndpointConfig] = {
parent_field_renames={"customer_id": "customer_id"},
),
),
+ # A discount's customer allow list. Each row is only `{"customer_id": ...}`, so the discount id
+ # comes from the parent. There is no date filter, so this is full refresh only.
+ "discount_customers": DodoPaymentsEndpointConfig(
+ path="/discounts/{discount_id}/customers",
+ primary_keys=["discount_id", "customer_id"],
+ partition_key=None,
+ fanout=DependentEndpointConfig(
+ child_response_actions=SKIP_MISSING_PARENT,
+ parent_name="discounts",
+ resolve_param="discount_id",
+ resolve_field="discount_id",
+ include_from_parent=["discount_id"],
+ parent_field_renames={"discount_id": "discount_id"},
+ ),
+ ),
+ # Billable screens per UTC day over the trailing 30 days, as the `daily` array of one object.
+ # The current day's count grows until the day ends and there is no date filter, so this is
+ # full refresh only. Thirty rows at most need no partitioning.
+ "moderation_usage": DodoPaymentsEndpointConfig(
+ path="/moderation/usage",
+ primary_keys=["date"],
+ partition_key=None,
+ paginated=False,
+ data_selector="daily",
+ ),
}
ENDPOINTS = tuple(DODOPAYMENTS_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/sources/dodopayments/tests/test_dodopayments.py b/products/warehouse_sources/sources/dodopayments/tests/test_dodopayments.py
index f993a6fb462e..fadc71e75a02 100644
--- a/products/warehouse_sources/sources/dodopayments/tests/test_dodopayments.py
+++ b/products/warehouse_sources/sources/dodopayments/tests/test_dodopayments.py
@@ -114,17 +114,46 @@ class TestRequestParams:
assert result.raised is None
assert result.requests[0].param("created_at_gte") is None
- def test_catalog_endpoint_never_gets_a_date_filter(self) -> None:
- # `/products` exposes no date filter; sending one would be rejected.
+ @pytest.mark.parametrize(
+ "endpoint, body, expected_query, expected_rows",
+ [
+ # `/products` exposes no date filter; sending one would be rejected.
+ (
+ "products",
+ {"items": [{"product_id": "prod_1"}]},
+ {"page_size", "page_number"},
+ [{"product_id": "prod_1"}],
+ ),
+ # Moderation usage is one unpaginated object whose rows sit in `daily`, beside the totals.
+ (
+ "moderation_usage",
+ {
+ "daily": [{"date": "2026-10-06", "screens": 12}, {"date": "2026-10-07", "screens": 3}],
+ "unbilled_screens": 15,
+ "screens_to_next_block": 985,
+ },
+ set(),
+ [{"date": "2026-10-06", "screens": 12}, {"date": "2026-10-07", "screens": 3}],
+ ),
+ ],
+ )
+ def test_endpoint_without_a_filter_never_gets_a_date_filter(
+ self,
+ endpoint: str,
+ body: dict[str, Any],
+ expected_query: set[str],
+ expected_rows: list[dict[str, Any]],
+ ) -> None:
result = _driver().run(
- "products",
- [_response([{"product_id": "prod_1"}])],
+ endpoint,
+ [ScriptedResponse(json=body)],
should_use_incremental_field=True,
db_incremental_field_last_value=datetime(2024, 5, 1, tzinfo=UTC),
)
assert result.raised is None
- assert set(result.requests[0].query) == {"page_size", "page_number"}
+ assert set(result.requests[0].query) == expected_query
+ assert result.rows == expected_rows
class TestSourceResponseMetadata:
@@ -235,6 +264,14 @@ class TestFanout:
{"id": "cwt_1", "customer_id": "cus_1", "currency": "USD", "amount": 250, "is_credit": True},
{"id": "cwt_1", "customer_id": "cus_1", "currency": "USD", "amount": 250, "is_credit": True},
),
+ # Allow-list rows carry only the customer, so the discount id must come from the parent.
+ (
+ "discount_customers",
+ {"discount_id": "dsc_1", "code": "SPRING", "created_at": "2024-05-01T00:00:00Z"},
+ "/discounts/dsc_1/customers",
+ {"customer_id": "cus_1"},
+ {"customer_id": "cus_1", "discount_id": "dsc_1"},
+ ),
# The parent field is the entitlement's own `id`, bound into a path placeholder also named `id`.
(
"entitlement_grants",