: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
feat(warehouse-sources): add asaas invoices, splits, pix and statement tables (#116956)
Tom Owers46502fb3f77c
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.mdindex 7c682b9b10c9..6a901d6e8f93 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@@ -853,15 +853,15 @@ Note: Diffed against the upstream swagger spec (82 paths). PostHog's deployment_## Asaas — **thin**-Today (5): `Customers`, `Installments`, `Payments`, `Subscriptions`, `Transfers`+Today (9): `Customers`, `FinancialTransactions`, `Installments`, `Invoices`, `Payments`, `PixTransactions`, `ReceivedSplits`, `Subscriptions`, `Transfers`Diffed against: <https://docs.asaas.com/reference/llms.txt>- [ ] `Payment links (GET /v3/paymentLinks)` — resolves paymentLink IDs in Payments and identifies the checkout offers that produced revenue (high)-- [ ] `Pix transactions (GET /v3/pix/transactions)` — resolves pixTransaction IDs in Payments and supports reconciliation of incoming and outgoing Pix transfers (high)-- [ ] `Financial statement (GET /v3/financialTransactions)` — reconciles account credits, debits, and fees to calculate cash movements (high)-- [ ] `Invoices (GET /v3/invoices)` — connects fiscal invoice status and tax details to customers and payments (high)-- [ ] `Received splits (GET /v3/payments/splits/received)` — measures marketplace revenue received from payments created by other accounts (high)+- [x] `Pix transactions (GET /v3/pix/transactions)` — resolves pixTransaction IDs in Payments and supports reconciliation of incoming and outgoing Pix transfers (high)+- [x] `Financial statement (GET /v3/financialTransactions)` — reconciles account credits, debits, and fees to calculate cash movements (high)+- [x] `Invoices (GET /v3/invoices)` — connects fiscal invoice status and tax details to customers and payments (high)+- [x] `Received splits (GET /v3/payments/splits/received)` — measures marketplace revenue received from payments created by other accounts (high)- [ ] `Anticipations (GET /v3/anticipations)` — measures receivable advances, financing costs, and their effects on cash flow (medium)- [ ] `Paid splits (GET /v3/payments/splits/paid)` — adds settlement dates and account relationships beyond the split details embedded in Payments (medium)- [ ] `Bill payments (GET /v3/bill)` — tracks outgoing bill payments and their status for cash flow analysis (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/asaas.py b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/asaas.pyindex c89d8ee40960..22c0403f5750 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/asaas.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/asaas.py@@ -4,7 +4,9 @@ from typing import Any, Optionalfrom posthog.dataclasses import frozenfrom products.warehouse_sources.backend.temporal.data_imports.sources.asaas.settings import (- INCREMENTAL_DATE_PARAM,+ ENDPOINT_PARAMS,+ ENDPOINT_PATHS,+ INCREMENTAL_DATE_PARAMS,INCREMENTAL_FIELDS,TABLE_NAMES,)@@ -37,7 +39,7 @@ def base_url(environment: str) -> str:def format_date_param(value: Any) -> str:- """Format an incremental watermark for Asaas's `dateCreated[ge]` filter (`YYYY-MM-DD`)."""+ """Format an incremental watermark for Asaas's date filters (`YYYY-MM-DD`)."""if isinstance(value, datetime):return value.date().isoformat()if isinstance(value, date):@@ -47,13 +49,13 @@ def format_date_param(value: Any) -> str:def get_resource(endpoint: str, should_use_incremental_field: bool) -> EndpointResource:table_name = TABLE_NAMES[endpoint]- is_incremental_endpoint = should_use_incremental_field and endpoint in INCREMENTAL_FIELDS+ is_incremental_endpoint = should_use_incremental_field and endpoint in INCREMENTAL_DATE_PARAMS- params: dict[str, Any] = {}+ params: dict[str, Any] = dict(ENDPOINT_PARAMS.get(endpoint, {}))if is_incremental_endpoint:- params[INCREMENTAL_DATE_PARAM] = {+ params[INCREMENTAL_DATE_PARAMS[endpoint]] = {"type": "incremental",- "cursor_path": "dateCreated",+ "cursor_path": INCREMENTAL_FIELDS[endpoint][0]["field"],# Well before Asaas existed, so an unset watermark still fetches full history."initial_value": "2000-01-01","convert": format_date_param,@@ -70,7 +72,7 @@ def get_resource(endpoint: str, should_use_incremental_field: bool) -> EndpointRelse "replace","endpoint": {"data_selector": "data[*]",- "path": f"{API_PATH}/{table_name}",+ "path": f"{API_PATH}/{ENDPOINT_PATHS[endpoint]}","params": params,},"table_format": "delta",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/canonical_descriptions.pyindex 495eb9a6a409..59c9a3f89ff3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/canonical_descriptions.py@@ -120,4 +120,107 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"deleted": "Whether the installment plan has been deleted.",},},+ "ReceivedSplits": {+ "description": "A split received by this account from a payment created by another Asaas account.",+ "docs_url": "https://docs.asaas.com/reference/listar-splits-recebidos",+ "columns": {+ "id": "Unique identifier of the split.",+ "walletId": "Identifier of the Asaas wallet that receives the split.",+ "fixedValue": "Fixed amount transferred to this account when the payment is received, in BRL.",+ "percentualValue": "Percentage of the payment's net value transferred to this account.",+ "totalValue": "Amount split to this account, in BRL.",+ "cancellationReason": "Reason the split was cancelled, if it was.",+ "status": "Split status (e.g. PENDING, AWAITING_CREDIT, DONE, CANCELLED, REFUNDED).",+ "externalReference": "Identifier for this split in the caller's own system.",+ "description": "Free-text description of the split.",+ "originAccountId": "Identifier of the account the split comes from.",+ "destinationAccountId": "Identifier of the account the split goes to.",+ "creditDate": "Date the split is credited to this account (YYYY-MM-DD).",+ "payment": "Summary of the originating payment: id, confirmed date, invoice number, and external reference.",+ },+ },+ "Invoices": {+ "description": "A fiscal service invoice (nota fiscal de serviço) issued for a customer, payment, or installment.",+ "docs_url": "https://docs.asaas.com/reference/listar-notas-fiscais",+ "columns": {+ "id": "Unique identifier of the invoice.",+ "status": "Current invoice status (e.g. SCHEDULED, AUTHORIZED, CANCELED, ERROR).",+ "customer": "Identifier of the customer the invoice is issued to.",+ "payment": "Identifier of the payment the invoice belongs to, if any.",+ "installment": "Identifier of the installment plan the invoice belongs to, if any.",+ "type": "Invoice type.",+ "statusDescription": "Description of the current invoice status.",+ "serviceDescription": "Description of the invoiced services.",+ "pdfUrl": "Link to the PDF of the issued invoice.",+ "xmlUrl": "Link to the XML of the issued invoice.",+ "rpsSerie": "Invoice series.",+ "rpsNumber": "RPS number converted into the invoice.",+ "number": "Invoice number.",+ "validationCode": "Invoice verification code.",+ "value": "Total invoice value, in BRL.",+ "deductions": "Deductions applied to the tax base. They don't change the total invoice value.",+ "effectiveDate": "Invoice issue date (YYYY-MM-DD).",+ "observations": "Additional notes on the invoice.",+ "estimatedTaxesDescription": "Estimated taxes on the invoice.",+ "externalReference": "Identifier for this invoice in the caller's own system.",+ "taxes": "Tax details: ISS, PIS, COFINS, CSLL, INSS, IR, IBS, and CBS rates and values.",+ "municipalServiceId": "Identifier of the municipal service.",+ "municipalServiceCode": "Municipal service code.",+ "municipalServiceName": "Name of the municipal service.",+ },+ },+ "FinancialTransactions": {+ "description": "An account statement (extrato) entry: a single credit, debit, or fee that changed the account balance.",+ "docs_url": "https://docs.asaas.com/reference/recuperar-extrato",+ "columns": {+ "id": "Unique identifier of the statement entry.",+ "value": "Entry value in BRL. Negative values are debits.",+ "balance": "Account balance right after the entry, in BRL.",+ "type": "Kind of entry (e.g. PAYMENT_RECEIVED, PAYMENT_FEE, TRANSFER, TRANSFER_FEE).",+ "date": "Date of the entry (YYYY-MM-DD).",+ "description": "Free-text description of the entry.",+ "paymentId": "Identifier of the related payment, if any.",+ "splitId": "Identifier of the related split, if any.",+ "transferId": "Identifier of the related transfer, if any.",+ "anticipationId": "Identifier of the related anticipation, if any.",+ "billId": "Identifier of the related bill payment, if any.",+ "invoiceId": "Identifier of the related invoice, if any.",+ "paymentDunningId": "Identifier of the related payment dunning, if any.",+ "creditBureauReportId": "Identifier of the related credit bureau (Serasa) report, if any.",+ },+ },+ "PixTransactions": {+ "description": "An incoming or outgoing Pix transaction on the account.",+ "docs_url": "https://docs.asaas.com/reference/listar-transacoes",+ "columns": {+ "id": "Unique identifier of the Pix transaction.",+ "endToEndIdentifier": "Identifier of the Pix transaction at the Central Bank.",+ "finality": "Purpose of a cash-value transaction (withdrawal or change).",+ "value": "Transaction or withdrawal value, in BRL.",+ "changeValue": "Change value, in BRL.",+ "refundedValue": "Value refunded, in BRL.",+ "effectiveDate": "Date the transaction happened.",+ "scheduledDate": "Date the transaction is scheduled for.",+ "status": "Transaction status.",+ "type": "Transaction type (e.g. CREDIT, DEBIT, DEBIT_REFUND).",+ "originType": "How the transaction was started (e.g. Pix key, QR code, manual).",+ "conciliationIdentifier": "Identifier of the QR code linked to the transaction.",+ "description": "Free-text description of the transaction.",+ "transactionReceiptUrl": "Link to the transaction receipt, available once confirmed.",+ "refusalReason": "Reason the transaction was declined, if it was.",+ "canBeCanceled": "Whether the transaction can still be cancelled.",+ "originalTransaction": "Original transaction this one refunds, if any.",+ "externalAccount": "Counterparty account: institution, name, CPF/CNPJ, and Pix key.",+ "qrCode": "QR code details: payer, original value, due date, interest, fine, and discount.",+ "payment": "Identifier of the related payment, if any.",+ "canBeRefunded": "Whether the transaction can still be refunded.",+ "refundDisabledReason": "Reason the transaction can't be refunded.",+ "chargedFeeValue": "Fee charged or credited for the transaction, in BRL.",+ "dateCreated": "Date the transaction was created.",+ "addressKey": "Pix key that received the transaction, for credits.",+ "addressKeyType": "Type of the Pix key (e.g. CPF, CNPJ, EMAIL, PHONE, EVP).",+ "transferId": "Identifier of the related transfer, if any.",+ "externalReference": "Identifier for this transaction in the caller's own system.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/settings.pyindex 6b150af27a11..0f78c1227800 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/settings.py@@ -1,6 +1,5 @@from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType-# Maps our schema/endpoint name to the API resource path segment and merge primary key.# All ids are account-wide unique (no fan-out), so every endpoint uses a plain "id" key.ENDPOINTS = ("Customers",@@ -8,6 +7,10 @@ ENDPOINTS = ("Subscriptions","Transfers","Installments",+ "ReceivedSplits",+ "Invoices",+ "FinancialTransactions",+ "PixTransactions",)TABLE_NAMES: dict[str, str] = {@@ -16,21 +19,52 @@ TABLE_NAMES: dict[str, str] = {"Subscriptions": "subscriptions","Transfers": "transfers","Installments": "installments",+ "ReceivedSplits": "received_splits",+ "Invoices": "invoices",+ "FinancialTransactions": "financial_transactions",+ "PixTransactions": "pix_transactions",}-# A stable, never-mutated per-row field to partition on for every endpoint.+# API resource path under `/v3`.+ENDPOINT_PATHS: dict[str, str] = {+ "Customers": "customers",+ "Payments": "payments",+ "Subscriptions": "subscriptions",+ "Transfers": "transfers",+ "Installments": "installments",+ "ReceivedSplits": "payments/splits/received",+ "Invoices": "invoices",+ "FinancialTransactions": "financialTransactions",+ "PixTransactions": "pix/transactions",+}++# Static query params sent on every request for the endpoint.+ENDPOINT_PARAMS: dict[str, dict[str, str]] = {+ "FinancialTransactions": {"order": "asc"},+}++# A stable, never-mutated per-row field to partition on. Received splits only carry a+# nullable `creditDate` and invoices a reschedulable `effectiveDate`, so they aren't partitioned.PARTITION_KEYS: dict[str, str] = {"Customers": "dateCreated","Payments": "dateCreated","Subscriptions": "dateCreated","Transfers": "dateCreated","Installments": "dateCreated",+ "FinancialTransactions": "date",+ "PixTransactions": "dateCreated",}-# Only endpoints that document a server-side `dateCreated[ge]` range filter are incremental.-# Customers, Subscriptions, and Installments only accept `offset`/`limit` plus non-date-# filters, so a client-side "since" cursor there would still re-fetch every page every run.-INCREMENTAL_DATE_PARAM = "dateCreated[ge]"+# Only endpoints that document a server-side date range filter are incremental.+# Customers, Subscriptions, Installments, and Pix transactions only accept `offset`/`limit` plus+# non-date filters, so a client-side "since" cursor there would still re-fetch every page every run.+# Received splits and invoices filter on dates that move after creation (`creditDate` is set on+# settlement, `effectiveDate` can be rescheduled), so they stay full refresh too.+INCREMENTAL_DATE_PARAMS: dict[str, str] = {+ "Payments": "dateCreated[ge]",+ "Transfers": "dateCreated[ge]",+ "FinancialTransactions": "startDate",+}INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {"Payments": [@@ -49,4 +83,12 @@ INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {"field_type": IncrementalFieldType.Date,},],+ "FinancialTransactions": [+ {+ "label": "date",+ "type": IncrementalFieldType.Date,+ "field": "date",+ "field_type": IncrementalFieldType.Date,+ },+ ],}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/source.pyindex 5ab144038dab..181f2e97c033 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/source.py@@ -17,6 +17,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.asaas.asaafrom products.warehouse_sources.backend.temporal.data_imports.sources.asaas.settings import (ENDPOINTS,INCREMENTAL_FIELDS,+ PARTITION_KEYS,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSourcefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (@@ -101,13 +102,14 @@ class AsaasSource(ResumableSource[AsaasSourceConfig, AsaasResumeConfig]):if inputs.should_use_incremental_fieldelse None,)+ partition_key = PARTITION_KEYS.get(inputs.schema_name)return SourceResponse(name=resource.name,items=lambda: resource,primary_keys=["id"],- partition_mode="datetime",- partition_format="month",- partition_keys=["dateCreated"],+ partition_mode="datetime" if partition_key else None,+ partition_format="month" if partition_key else None,+ partition_keys=[partition_key] if partition_key else None,)@property@@ -118,7 +120,8 @@ class AsaasSource(ResumableSource[AsaasSourceConfig, AsaasResumeConfig]):label="Asaas",caption=("Connect your Asaas account using an API key to sync customers, payments, "- "subscriptions, transfers, and installments. Find your key in Asaas under "+ "subscriptions, transfers, installments, invoices, received splits, Pix "+ "transactions, and your account statement. Find your key in Asaas under ""**Integrações** > **API**."),keywords=["billing", "payments", "brazil"],diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/tests/test_asaas.py b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/tests/test_asaas.pyindex bb8b00d16544..732baf99c0a2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/tests/test_asaas.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/asaas/tests/test_asaas.py@@ -23,8 +23,19 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.tes)from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.asaas import AsaasSourceConfig-_INCREMENTAL_ENDPOINTS = {"Payments", "Transfers"}-_FULL_REFRESH_ENDPOINTS = {"Customers", "Subscriptions", "Installments"}+_INCREMENTAL_ENDPOINTS = [+ ("Payments", "dateCreated[ge]"),+ ("Transfers", "dateCreated[ge]"),+ ("FinancialTransactions", "startDate"),+]+_FULL_REFRESH_ENDPOINTS = {+ "Customers",+ "Subscriptions",+ "Installments",+ "ReceivedSplits",+ "Invoices",+ "PixTransactions",+}VALIDATE_PATCH = ("products.warehouse_sources.backend.temporal.data_imports.sources.asaas.source.validate_asaas_credentials"@@ -67,24 +78,24 @@ class TestFormatDateParam:class TestGetResource:- @parameterized.expand(sorted(_INCREMENTAL_ENDPOINTS))- def test_incremental_endpoint_adds_date_filter_when_requested(self, endpoint: str) -> None:+ @parameterized.expand(_INCREMENTAL_ENDPOINTS)+ def test_incremental_endpoint_adds_date_filter_when_requested(self, endpoint: str, date_param: str) -> None:resource = get_resource(endpoint, should_use_incremental_field=True)assert resource["write_disposition"] == {"disposition": "merge", "strategy": "upsert"}endpoint_config = cast(Endpoint, resource["endpoint"])params = endpoint_config["params"]assert params is not None- assert "dateCreated[ge]" in params- assert params["dateCreated[ge]"]["type"] == "incremental"+ assert date_param in params+ assert params[date_param]["type"] == "incremental"- @parameterized.expand(sorted(_INCREMENTAL_ENDPOINTS))- def test_incremental_endpoint_omits_filter_when_not_requested(self, endpoint: str) -> None:+ @parameterized.expand(_INCREMENTAL_ENDPOINTS)+ def test_incremental_endpoint_omits_filter_when_not_requested(self, endpoint: str, date_param: str) -> None:resource = get_resource(endpoint, should_use_incremental_field=False)assert resource["write_disposition"] == "replace"endpoint_config = cast(Endpoint, resource["endpoint"])- assert endpoint_config["params"] == {}+ assert date_param not in (endpoint_config["params"] or {})@parameterized.expand(sorted(_FULL_REFRESH_ENDPOINTS))def test_full_refresh_endpoint_never_adds_date_filter(self, endpoint: str) -> None:@@ -170,18 +181,40 @@ class TestAsaasSource:assert (is_valid, error_message) == (expected_valid, expected_message)mock_validate.assert_called_once_with("test-key", "production")- def test_source_for_pipeline_plumbs_arguments(self) -> None:+ @parameterized.expand(+ [+ ("Payments", "/v3/payments", {"dateCreated[ge]": "2026-01-01"}),+ ("FinancialTransactions", "/v3/financialTransactions", {"startDate": "2026-01-01", "order": "asc"}),+ ]+ )+ def test_source_for_pipeline_plumbs_arguments(+ self, endpoint: str, expected_path: str, expected_params: dict[str, str]+ ) -> None:result = _driver().run(- "Payments",- [_page([{"id": "payment-1", "dateCreated": "2026-01-01"}], 1)],+ endpoint,+ [_page([{"id": "row-1", "dateCreated": "2026-01-01", "date": "2026-01-01"}], 1)],should_use_incremental_field=True,db_incremental_field_last_value="2026-01-01",)assert result.raised is None- assert result.paths == ["/v3/payments"]+ assert result.paths == [expected_path]assert result.requests[0].headers["access_token"] == "test-key"- assert result.requests[0].param("dateCreated[ge]") == "2026-01-01"+ for name, value in expected_params.items():+ assert result.requests[0].param(name) == value++ @parameterized.expand(+ [+ ("ReceivedSplits", "/v3/payments/splits/received"),+ ("Invoices", "/v3/invoices"),+ ("PixTransactions", "/v3/pix/transactions"),+ ]+ )+ def test_full_refresh_endpoint_requests_vendor_path(self, endpoint: str, expected_path: str) -> None:+ result = _driver().run(endpoint, [_page([{"id": "row-1"}], 1)])++ assert result.raised is None+ assert result.paths == [expected_path]def test_source_for_pipeline_omits_cursor_when_not_incremental(self) -> None:inputs = mock.MagicMock()