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 4 missing tables to the Mollie source (#117825)

Tom Owersffc5546ae88e
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 f036fdea6916..2db8d35e8879 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
@@ -8096,10 +8096,10 @@ Diffed against: <https://raw.githubusercontent.com/mollie/openapi/main/specs.yam
- [x] `/v2/balances` — balance accounts that transactions and settlements roll up to; lookup for balanceId (high)
- [x] `/v2/profiles` — lookup resolving the profileId carried on payments, payment links and methods (high)
- [x] `/v2/customers/{customerId}/mandates` — SEPA/card mandates that subscriptions and recurring payments reference (high)
-- [ ] `/v2/payouts` — bank payouts of settled funds — needed to tie settlements to money received (high)
-- [ ] `/v2/payments/{paymentId}/captures` — capture events on authorized payments; without them captured vs authorized amounts can't be split (medium)
-- [ ] `/v2/invoices` — Mollie's own invoices to the merchant (fees charged) for cost analysis (medium)
-- [ ] `/v2/settlements/{settlementId}/payments` — join table mapping payments/refunds/captures/chargebacks to a settlement (medium)
+- [x] `/v2/payouts` — bank payouts of settled funds — needed to tie settlements to money received (high)
+- [x] `/v2/payments/{paymentId}/captures` — capture events on authorized payments; without them captured vs authorized amounts can't be split (medium)
+- [x] `/v2/invoices` — Mollie's own invoices to the merchant (fees charged) for cost analysis (medium)
+- [x] `/v2/settlements/{settlementId}/payments` — join table mapping payments/refunds/captures/chargebacks to a settlement (medium)
- [ ] `/v2/methods/all` — payment-method lookup resolving the method code on every payment (medium)
- [ ] `/v2/business-accounts/accounts/{businessAccountId}/transactions` — business account ledger for merchants using Mollie banking (medium)
- [ ] `/v2/balances/{balanceId}/report` — pre-aggregated balance report grouped by transaction category (low)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/canonical_descriptions.py
index 156a17788142..79932850e530 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/canonical_descriptions.py
@@ -175,4 +175,63 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
status="Status of the mandate: valid, pending, or invalid.",
),
},
+ "payouts": {
+ "description": "A transfer of funds from a Mollie balance to the bank account configured for that balance.",
+ "docs_url": "https://docs.mollie.com/reference/get-payout",
+ "columns": _columns(
+ balanceId="Identifier of the balance the payout was made from.",
+ amount="Amount of the payout, as a value/currency object.",
+ description="Description of the payout.",
+ status="Status of the payout, such as requested, initiated, processing-at-bank, completed, canceled or failed.",
+ statusReason="Reason for the current status of the payout, if any.",
+ initiatedAt="Time at which the payout was initiated, in ISO 8601 format.",
+ completedAt="Time at which the payout was sent to the destination bank account, in ISO 8601 format.",
+ canceledAt="Time at which the payout was canceled, in ISO 8601 format.",
+ ),
+ },
+ "invoices": {
+ "description": "An invoice that Mollie issued to your organization for the fees it charged.",
+ "docs_url": "https://docs.mollie.com/reference/get-invoice",
+ "columns": {
+ "id": "Unique identifier for the invoice (e.g. inv_xxx).",
+ "resource": "String describing the object's Mollie resource type ('invoice').",
+ "reference": "Reference number of the invoice, for example 2024.10000.",
+ "vatNumber": "VAT number to which the invoice was issued, if applicable.",
+ "status": "Status of the invoice: open, paid, or overdue.",
+ "netAmount": "Total amount of the invoice excluding VAT, as a value/currency object.",
+ "vatAmount": "VAT amount of the invoice, as a value/currency object.",
+ "grossAmount": "Total amount of the invoice including VAT, as a value/currency object.",
+ "lines": "Invoice lines, one per fee category and period.",
+ "issuedAt": "The invoice date, in YYYY-MM-DD format.",
+ "paidAt": "The date on which the invoice was paid, if applicable, in YYYY-MM-DD format.",
+ "dueAt": "The date on which the invoice is due, if applicable, in YYYY-MM-DD format.",
+ "_links": "HAL links to related resources, including the invoice PDF.",
+ },
+ },
+ "settlement_payments": {
+ "description": "A payment included in a Mollie settlement. Maps each settled payment to the settlement that paid it out.",
+ "docs_url": "https://docs.mollie.com/reference/list-settlement-payments",
+ "columns": _columns(
+ settlementId="Identifier of the settlement the payment is included in.",
+ status="Status of the payment: open, pending, authorized, paid, canceled, expired, or failed.",
+ amount="Amount of the payment, as a value/currency object.",
+ settlementAmount="Amount that is settled to your account for this payment, as a value/currency object.",
+ method="Payment method used (e.g. creditcard, ideal, paypal).",
+ profileId="Identifier of the profile the payment belongs to.",
+ paidAt="Time at which the payment turned paid, in ISO 8601 format.",
+ ),
+ },
+ "captures": {
+ "description": "A capture of funds on an authorized payment, for payment methods that separate authorization and capture.",
+ "docs_url": "https://docs.mollie.com/reference/get-capture",
+ "columns": _columns(
+ paymentId="Identifier of the payment the capture was created for.",
+ amount="Amount captured, as a value/currency object.",
+ description="Description of the capture.",
+ status="Status of the capture: pending, succeeded, or failed.",
+ metadata="Custom metadata attached to the capture.",
+ shipmentId="Identifier of the shipment that triggered the capture, if any.",
+ settlementId="Identifier of the settlement the capture was paid out in, if any.",
+ ),
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/mollie.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/mollie.py
index ea18221d2feb..4b627ece96ca 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/mollie.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/mollie.py
@@ -35,6 +35,18 @@ class MollieResumeConfig:
fanout_state: Optional[dict[str, Any]] = None
+def _only_payments_with_captures(payment: dict[str, Any]) -> dict[str, Any] | list[dict[str, Any]]:
+ # Mollie sets amountCaptured only on payments whose method supports captures. Dropping the
+ # other payments saves one captures request per payment that can never have a capture.
+ return payment if payment.get("amountCaptured") is not None else []
+
+
+# Per-child filters on the fan-out parent rows, keyed by the child endpoint name.
+_PARENT_DATA_MAPS: dict[str, Callable[[dict[str, Any]], dict[str, Any] | list[dict[str, Any]]]] = {
+ "captures": _only_payments_with_captures,
+}
+
+
def _source_response(endpoint: str, config: MollieEndpointConfig, items: Callable[[], Iterable[Any]]) -> SourceResponse:
return SourceResponse(
name=endpoint,
@@ -84,6 +96,7 @@ def mollie_source(
fanout=config.fanout,
client_config=client_config,
parent_endpoint_extra={"data_selector": f"_embedded.{parent_config.embedded_key}"},
+ parent_data_map=_PARENT_DATA_MAPS.get(endpoint),
child_endpoint_extra={"data_selector": f"_embedded.{config.embedded_key}"},
path_format_values={},
team_id=team_id,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/settings.py
index ca5b0906dee2..71d23cdebfac 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/settings.py
@@ -64,8 +64,20 @@ MOLLIE_ENDPOINTS: dict[str, MollieEndpointConfig] = {
path="/payment-links",
embedded_key="payment_links",
),
- # Balances, balance transactions, settlements and profiles are organization-level resources:
- # Mollie serves them only to access tokens, never to a profile API key.
+ "payouts": MollieEndpointConfig(
+ name="payouts",
+ path="/payouts",
+ embedded_key="payouts",
+ ),
+ # Balances, balance transactions, settlements, settlement payments, invoices and profiles are
+ # organization-level resources: Mollie serves them only to access tokens, never to a profile API key.
+ "invoices": MollieEndpointConfig(
+ name="invoices",
+ path="/invoices",
+ embedded_key="invoices",
+ # Invoices carry no createdAt; issuedAt is the fixed invoice date.
+ partition_key="issuedAt",
+ ),
"balances": MollieEndpointConfig(
name="balances",
path="/balances",
@@ -85,6 +97,19 @@ MOLLIE_ENDPOINTS: dict[str, MollieEndpointConfig] = {
parent_field_renames={"id": "balanceId"},
),
),
+ "settlement_payments": MollieEndpointConfig(
+ name="settlement_payments",
+ path="/settlements/{settlementId}/payments",
+ embedded_key="payments",
+ primary_keys=["settlementId", "id"],
+ fanout=DependentEndpointConfig(
+ parent_name="settlements",
+ resolve_param="settlementId",
+ resolve_field="id",
+ include_from_parent=["id"],
+ parent_field_renames={"id": "settlementId"},
+ ),
+ ),
"profiles": MollieEndpointConfig(
name="profiles",
path="/profiles",
@@ -103,6 +128,19 @@ MOLLIE_ENDPOINTS: dict[str, MollieEndpointConfig] = {
parent_field_renames={"id": "customerId"},
),
),
+ "captures": MollieEndpointConfig(
+ name="captures",
+ path="/payments/{paymentId}/captures",
+ embedded_key="captures",
+ primary_keys=["paymentId", "id"],
+ fanout=DependentEndpointConfig(
+ parent_name="payments",
+ resolve_param="paymentId",
+ resolve_field="id",
+ include_from_parent=["id"],
+ parent_field_renames={"id": "paymentId"},
+ ),
+ ),
}
ENDPOINTS = tuple(MOLLIE_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/source.py
index 4724d22f70a4..37517e322684 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/source.py
@@ -78,7 +78,7 @@ class MollieSource(ResumableSource[MollieSourceConfig, MollieResumeConfig]):
You can find your API key in the [Mollie dashboard](https://my.mollie.com/dashboard/developers/api-keys) under Developers > API keys. Use a live key (`live_...`) for production data — test keys only return test-mode data.
-The balances, balance transactions, settlements and profiles tables are organization-level data that Mollie only shares with an [organization access token](https://docs.mollie.com/docs/authentication). To sync them, connect an access token (`access_...`) that is scoped to your payment profile and has read permissions for those resources.""",
+The balances, balance transactions, settlements, settlement payments, invoices and profiles tables are organization-level data that Mollie only shares with an [organization access token](https://docs.mollie.com/docs/authentication). To sync them, connect an access token (`access_...`) that is scoped to your payment profile and has read permissions for those resources.""",
iconPath="/static/services/mollie.png",
docsUrl="https://posthog.com/docs/cdp/sources/mollie",
releaseStatus=ReleaseStatus.GA,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/tests/test_mollie.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/tests/test_mollie.py
index 7e3746fe1822..140f335f8cf9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/tests/test_mollie.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mollie/tests/test_mollie.py
@@ -29,18 +29,39 @@ def _response(embedded_key: str, items: list[dict[str, Any]], next_url: str | No
class TestPagination:
- def test_paginates_via_hal_next_link(self) -> None:
- next_url = "https://api.mollie.com/v2/payments?from=tr_next&limit=250"
+ @pytest.mark.parametrize(
+ "endpoint, path, partition_field, partition_value",
+ [
+ ("payments", "payments", "createdAt", "2025-03-01T10:00:00+00:00"),
+ ("payouts", "payouts", "createdAt", "2026-05-04T08:30:00+00:00"),
+ # Invoices carry only date fields, no createdAt.
+ ("invoices", "invoices", "issuedAt", "2025-02-01"),
+ ],
+ )
+ def test_paginates_via_hal_next_link(
+ self, endpoint: str, path: str, partition_field: str, partition_value: str
+ ) -> None:
+ next_url = f"https://api.mollie.com/v2/{path}?from=obj_next&limit=250"
result = _driver().run(
- "payments",
+ endpoint,
[
- _response("payments", [{"id": "tr_1"}, {"id": "tr_2"}], next_url=next_url),
- _response("payments", [{"id": "tr_3"}]),
+ _response(
+ endpoint,
+ [
+ {"id": "obj_1", partition_field: partition_value},
+ {"id": "obj_2", partition_field: partition_value},
+ ],
+ next_url=next_url,
+ ),
+ _response(endpoint, [{"id": "obj_3", partition_field: partition_value}]),
],
)
assert result.raised is None
- assert [row["id"] for row in result.rows] == ["tr_1", "tr_2", "tr_3"]
+ assert [row["id"] for row in result.rows] == ["obj_1", "obj_2", "obj_3"]
+ assert result.paths[0] == f"/v2/{path}"
+ assert result.response is not None
+ assert all(row[key] for row in result.rows for key in result.response.partition_keys or [])
# The next link is self-contained — the second request targets it directly.
assert result.urls[1] == next_url
# Checkpoint saved once after the first page (points at the next link); the short
@@ -68,34 +89,85 @@ class TestPagination:
assert result.rows == []
+# Each payment carries amountCaptured, so the captures fan-out keeps every parent.
+_CAPTURABLE = {"amountCaptured": {"currency": "EUR", "value": "10.00"}}
+
+
class TestFanOut:
- def test_mandates_walk_every_customer_and_carry_customer_id(self) -> None:
- child_next = "https://api.mollie.com/v2/customers/cst_1/mandates?from=mdt_2&limit=250"
+ @pytest.mark.parametrize(
+ "endpoint, parent_key, child_key, parent_id_column, parent_path, child_suffix, parent_extra",
+ [
+ ("mandates", "customers", "mandates", "customerId", "customers", "mandates", {}),
+ ("captures", "payments", "captures", "paymentId", "payments", "captures", _CAPTURABLE),
+ ("settlement_payments", "settlements", "payments", "settlementId", "settlements", "payments", {}),
+ ],
+ )
+ def test_walks_every_parent_and_carries_parent_id(
+ self,
+ endpoint: str,
+ parent_key: str,
+ child_key: str,
+ parent_id_column: str,
+ parent_path: str,
+ child_suffix: str,
+ parent_extra: dict[str, Any],
+ ) -> None:
+ child_next = f"https://api.mollie.com/v2/{parent_path}/p_1/{child_suffix}?from=c_2&limit=250"
result = _driver().run(
- "mandates",
+ endpoint,
[
- _response("customers", [{"id": "cst_1"}, {"id": "cst_2"}]),
- _response("mandates", [{"id": "mdt_1"}], next_url=child_next),
- _response("mandates", [{"id": "mdt_2"}]),
- _response("mandates", [{"id": "mdt_3"}]),
+ _response(parent_key, [{"id": "p_1", **parent_extra}, {"id": "p_2", **parent_extra}]),
+ _response(child_key, [{"id": "c_1"}], next_url=child_next),
+ _response(child_key, [{"id": "c_2"}]),
+ _response(child_key, [{"id": "c_3"}]),
],
)
assert result.raised is None
- assert [(r["customerId"], r["id"]) for r in result.rows] == [
- ("cst_1", "mdt_1"),
- ("cst_1", "mdt_2"),
- ("cst_2", "mdt_3"),
+ assert [(r[parent_id_column], r["id"]) for r in result.rows] == [
+ ("p_1", "c_1"),
+ ("p_1", "c_2"),
+ ("p_2", "c_3"),
]
- assert all("_customers_id" not in r for r in result.rows)
+ assert all(f"_{parent_key}_id" not in r for r in result.rows)
assert result.response is not None
- assert result.response.primary_keys == ["customerId", "id"]
- assert result.paths[1] == "/v2/customers/cst_1/mandates"
+ assert result.response.primary_keys == [parent_id_column, "id"]
+ assert result.paths[1] == f"/v2/{parent_path}/p_1/{child_suffix}"
assert result.urls[2] == child_next
- assert result.paths[3] == "/v2/customers/cst_2/mandates"
+ assert result.paths[3] == f"/v2/{parent_path}/p_2/{child_suffix}"
last_state = result.saved_states[-1]
assert last_state.next_url is None
- assert last_state.fanout_state["completed"] == ["/customers/cst_1/mandates", "/customers/cst_2/mandates"]
+ assert last_state.fanout_state["completed"] == [
+ f"/{parent_path}/p_1/{child_suffix}",
+ f"/{parent_path}/p_2/{child_suffix}",
+ ]
+
+ @pytest.mark.parametrize(
+ "payments, expected_paths",
+ [
+ # Payments whose method does not support captures carry no amountCaptured.
+ (
+ [{"id": "tr_1"}, {"id": "tr_2", **_CAPTURABLE}, {"id": "tr_3", "amountCaptured": None}],
+ ["/v2/payments", "/v2/payments/tr_2/captures"],
+ ),
+ # A zero amountCaptured still means the payment supports captures, which can be pending.
+ (
+ [{"id": "tr_1", "amountCaptured": {"currency": "EUR", "value": "0.00"}}],
+ ["/v2/payments", "/v2/payments/tr_1/captures"],
+ ),
+ ([{"id": "tr_1"}, {"id": "tr_2"}], ["/v2/payments"]),
+ ],
+ )
+ def test_captures_skip_payments_without_capture_support(
+ self, payments: list[dict[str, Any]], expected_paths: list[str]
+ ) -> None:
+ responses = [_response("payments", payments)]
+ responses += [_response("captures", [{"id": f"cpt_{i}"}]) for i in range(len(expected_paths) - 1)]
+ result = _driver().run("captures", responses)
+
+ assert result.raised is None
+ assert result.paths == expected_paths
+ assert len(result.rows) == len(expected_paths) - 1
def test_resume_skips_balances_already_finished(self) -> None:
result = _driver().run(