: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(data-warehouse): add asaas payment link, dunning, and bill payment tables (#117698)
Tom Owers84f856579c72
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 160cdb2b7413..530afc0d1817 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,20 +853,20 @@ Note: Diffed against the upstream swagger spec (82 paths). PostHog's deployment_## Asaas — **thin**-Today (9): `Customers`, `FinancialTransactions`, `Installments`, `Invoices`, `Payments`, `PixTransactions`, `ReceivedSplits`, `Subscriptions`, `Transfers`+Today (13): `BillPayments`, `Customers`, `FinancialTransactions`, `Installments`, `Invoices`, `PaymentDunningHistory`, `PaymentDunnings`, `PaymentLinks`, `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)+- [x] `Payment links (GET /v3/paymentLinks)` — resolves paymentLink IDs in Payments and identifies the checkout offers that produced revenue (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)-- [ ] `Payment dunnings (GET /v3/paymentDunnings)` — tracks debt recovery requests and outcomes for overdue receivables (medium)-- [ ] `Dunning event history (GET /v3/paymentDunnings/{id}/history)` — shows debt recovery progress and time spent in each state (medium)+- [x] `Bill payments (GET /v3/bill)` — tracks outgoing bill payments and their status for cash flow analysis (medium)+- [x] `Payment dunnings (GET /v3/paymentDunnings)` — tracks debt recovery requests and outcomes for overdue receivables (medium)+- [x] `Dunning event history (GET /v3/paymentDunnings/{id}/history)` — shows debt recovery progress and time spent in each state (medium)Note: Used the official reference index and parsed embedded OpenAPI JSON from its linked operation pages. Compared Payments response schemas with nested resources before selecting gaps. Refunds and chargebacks already appear in Payments; paid split reads add settlement detail, while received splits cover other accounts. Dunning history needs parent requests; excluded API keys, webhooks, document uploads, and settings.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 22c0403f5750..1c94f3f415a5 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@@ -6,6 +6,8 @@ from posthog.dataclasses import frozenfrom products.warehouse_sources.backend.temporal.data_imports.sources.asaas.settings import (ENDPOINT_PARAMS,ENDPOINT_PATHS,+ FANOUT_PARENT_ID_COLUMNS,+ FANOUT_PARENTS,INCREMENTAL_DATE_PARAMS,INCREMENTAL_FIELDS,TABLE_NAMES,@@ -14,11 +16,18 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.httfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (RESTAPIConfig,rest_api_resource,+ rest_api_resources,+)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (+ rename_parent_fields,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (OffsetPaginator,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import EndpointResource+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (+ ClientConfig,+ EndpointResource,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerSANDBOX_BASE_URL = "https://api-sandbox.asaas.com"@@ -79,6 +88,22 @@ def get_resource(endpoint: str, should_use_incremental_field: bool) -> EndpointR}+def get_fanout_resource(endpoint: str) -> EndpointResource:+ parent = FANOUT_PARENTS[endpoint]+ return {+ "name": endpoint,+ "table_name": TABLE_NAMES[endpoint],+ "write_disposition": "replace",+ "include_from_parent": ["id"],+ "endpoint": {+ "data_selector": "data[*]",+ "path": f"{API_PATH}/{ENDPOINT_PATHS[endpoint]}",+ "params": {"id": {"type": "resolve", "resource": parent, "field": "id"}},+ },+ "table_format": "delta",+ }++def asaas_source(api_key: str,environment: str,@@ -89,20 +114,39 @@ def asaas_source(db_incremental_field_last_value: Optional[Any],should_use_incremental_field: bool = False,):- config: RESTAPIConfig = {- "client": {- "base_url": base_url(environment),- "auth": {- "type": "api_key",- "name": "access_token",- "api_key": api_key,- "location": "header",- },- "paginator": OffsetPaginator(limit=PAGE_SIZE, total_path="totalCount"),- # Reject redirects: the `access_token` header must never be replayed onto- # a host other than the one it was issued for.- "allow_redirects": False,+ client: ClientConfig = {+ "base_url": base_url(environment),+ "auth": {+ "type": "api_key",+ "name": "access_token",+ "api_key": api_key,+ "location": "header",},+ "paginator": OffsetPaginator(limit=PAGE_SIZE, total_path="totalCount"),+ # Reject redirects: the `access_token` header must never be replayed onto+ # a host other than the one it was issued for.+ "allow_redirects": False,+ }++ if endpoint in FANOUT_PARENTS:+ parent = FANOUT_PARENTS[endpoint]+ # The fan-out resume state (completed parents + child page) doesn't fit AsaasResumeConfig,+ # so a resumed run restarts the fan-out from the first dunning.+ resources = rest_api_resources(+ {+ "client": client,+ "resource_defaults": {},+ "resources": [get_resource(parent, False), get_fanout_resource(endpoint)],+ },+ team_id,+ job_id,+ None,+ )+ child = next(resource for resource in resources if resource.name == endpoint)+ return child.add_map(rename_parent_fields(parent, {"id": FANOUT_PARENT_ID_COLUMNS[endpoint]}))++ config: RESTAPIConfig = {+ "client": client,"resource_defaults": {"write_disposition": {"disposition": "merge",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 59c9a3f89ff3..08a0913ef763 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@@ -223,4 +223,82 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"externalReference": "Identifier for this transaction in the caller's own system.",},},+ "PaymentLinks": {+ "description": "A payment link: a shareable checkout page that creates payments, installments, or subscriptions when a payer completes it.",+ "docs_url": "https://docs.asaas.com/reference/listar-links-de-pagamentos",+ "columns": {+ "id": "Unique identifier of the payment link. Payments created through the link reference it in `paymentLink`.",+ "name": "Name of the payment link.",+ "value": "Amount of the payment link, in BRL. Empty when the payer chooses the amount.",+ "active": "Whether the payment link is active.",+ "chargeType": "Kind of charge the link creates (DETACHED, RECURRENT, or INSTALLMENT).",+ "url": "Public URL of the payment link.",+ "billingType": "Payment method the link accepts (UNDEFINED, BOLETO, CREDIT_CARD, or PIX).",+ "subscriptionCycle": "Billing cycle of subscriptions created by a RECURRENT link.",+ "description": "Description of the payment link.",+ "endDate": "Date the payment link stops accepting payments.",+ "deleted": "Whether the payment link has been removed.",+ "viewCount": "Number of times the payment link has been viewed.",+ "maxInstallmentCount": "Maximum number of installments a payer can split the amount into.",+ "dueDateLimitDays": "Business days a payer has to pay a boleto after it is generated.",+ "notificationEnabled": "Whether customers created through the link receive notifications.",+ "isAddressRequired": "Whether the payer must fill in an address.",+ "externalReference": "Identifier for this payment link in the caller's own system.",+ },+ },+ "PaymentDunnings": {+ "description": "A payment dunning (negativação): a request to recover an overdue payment through a credit bureau or debt recovery assistance.",+ "docs_url": "https://docs.asaas.com/reference/list-payment-dunnings",+ "columns": {+ "id": "Unique identifier of the payment dunning.",+ "dunningNumber": "Sequential number of the payment dunning.",+ "status": "Status of the payment dunning (e.g. PENDING, PROCESSED, PAID, PARTIALLY_PAID, DENIED, CANCELLED).",+ "type": "Type of payment dunning (CREDIT_BUREAU or DEBT_RECOVERY_ASSISTANCE).",+ "requestDate": "Date the payment dunning was requested.",+ "description": "Description of the payment dunning.",+ "value": "Amount of the payment being recovered, in BRL.",+ "feeValue": "Cost or fee of the payment dunning, in BRL.",+ "netValue": "Net amount to be recovered, in BRL.",+ "receivedInCashFeeValue": "Fee charged when the payment is received in cash, in BRL.",+ "denialReason": "Reason the payment dunning was denied, if it was.",+ "cancellationFeeValue": "Fee charged if the payment dunning is cancelled, in BRL.",+ "canBeCancelled": "Whether the payment dunning can still be cancelled.",+ "cannotBeCancelledReason": "Reason the payment dunning can't be cancelled.",+ "isNecessaryResendDocumentation": "Whether the documentation must be sent again.",+ "payment": "Identifier of the overdue payment being recovered.",+ },+ },+ "PaymentDunningHistory": {+ "description": "An event in the history of a payment dunning, from the start of the dunning onwards.",+ "docs_url": "https://docs.asaas.com/reference/event-history-lists",+ "columns": {+ "paymentDunning": "Identifier of the payment dunning the event belongs to.",+ "status": "Status of the dunning after the event (IN_NEGOTIATION, NEGOTIATION_FAIL, NEGOTIATED, or PAID).",+ "description": "Description of the event.",+ "eventDate": "Date the event occurred.",+ },+ },+ "BillPayments": {+ "description": "A bill payment: an outgoing payment of a boleto or utility bill made from the Asaas account.",+ "docs_url": "https://docs.asaas.com/reference/list-bill-payments",+ "columns": {+ "id": "Unique identifier of the bill payment.",+ "status": "Status of the bill payment (e.g. PENDING, BANK_PROCESSING, PAID, FAILED, CANCELLED, REFUNDED).",+ "value": "Amount to be paid, in BRL.",+ "discount": "Discount applied to the payment, in BRL.",+ "interest": "Interest applied to the payment, in BRL.",+ "fine": "Fine applied to the payment, in BRL.",+ "identificationField": "Digitable line of the bill being paid.",+ "dueDate": "Due date of the bill.",+ "scheduleDate": "Date the payment is scheduled for.",+ "paymentDate": "Date the payment was made.",+ "fee": "Asaas fee for the bill payment, in BRL.",+ "description": "Description of the bill payment.",+ "companyName": "Company or agency that issued the bill.",+ "transactionReceiptUrl": "Link to the proof of payment.",+ "canBeCancelled": "Whether the bill payment can still be cancelled.",+ "externalReference": "Identifier for this bill payment in the caller's own system.",+ "failReasons": "Reasons the payment failed, if it did.",+ },+ },}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 0f78c1227800..6e36264d1c3a 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-# All ids are account-wide unique (no fan-out), so every endpoint uses a plain "id" key.ENDPOINTS = ("Customers","Payments",@@ -11,6 +10,10 @@ ENDPOINTS = ("Invoices","FinancialTransactions","PixTransactions",+ "PaymentLinks",+ "PaymentDunnings",+ "PaymentDunningHistory",+ "BillPayments",)TABLE_NAMES: dict[str, str] = {@@ -23,6 +26,10 @@ TABLE_NAMES: dict[str, str] = {"Invoices": "invoices","FinancialTransactions": "financial_transactions","PixTransactions": "pix_transactions",+ "PaymentLinks": "payment_links",+ "PaymentDunnings": "payment_dunnings",+ "PaymentDunningHistory": "payment_dunning_history",+ "BillPayments": "bill_payments",}# API resource path under `/v3`.@@ -36,11 +43,32 @@ ENDPOINT_PATHS: dict[str, str] = {"Invoices": "invoices","FinancialTransactions": "financialTransactions","PixTransactions": "pix/transactions",+ "PaymentLinks": "paymentLinks",+ "PaymentDunnings": "paymentDunnings",+ "PaymentDunningHistory": "paymentDunnings/{id}/history",+ "BillPayments": "bill",+}++# Fan-out children: endpoint -> parent endpoint whose `id` fills the `{id}` path placeholder.+FANOUT_PARENTS: dict[str, str] = {+ "PaymentDunningHistory": "PaymentDunnings",+}++# Column the fan-out parent's `id` is written to on each child row.+FANOUT_PARENT_ID_COLUMNS: dict[str, str] = {+ "PaymentDunningHistory": "paymentDunning",+}++# Top-level ids are account-wide unique. History events carry no id of their own.+PRIMARY_KEYS: dict[str, list[str]] = {+ "PaymentDunningHistory": ["paymentDunning", "eventDate", "status", "description"],}# Static query params sent on every request for the endpoint.ENDPOINT_PARAMS: dict[str, dict[str, str]] = {"FinancialTransactions": {"order": "asc"},+ # Payments keep pointing at a payment link after it's removed, so keep removed links resolvable.+ "PaymentLinks": {"includeDeleted": "true"},}# A stable, never-mutated per-row field to partition on. Received splits only carry a@@ -53,13 +81,16 @@ PARTITION_KEYS: dict[str, str] = {"Installments": "dateCreated","FinancialTransactions": "date","PixTransactions": "dateCreated",+ "PaymentDunnings": "requestDate",}# 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.+# settlement, `effectiveDate` can be rescheduled), so they stay full refresh too. Payment dunnings+# accept `requestStartDate`, but their status keeps moving long after the request date, so a+# request-date window would freeze outcomes and they stay full refresh as well.INCREMENTAL_DATE_PARAMS: dict[str, str] = {"Payments": "dateCreated[ge]","Transfers": "dateCreated[ge]",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 3b9c079de977..070310c82c8f 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,8 +17,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.asaas.asaa)from products.warehouse_sources.backend.temporal.data_imports.sources.asaas.settings import (ENDPOINTS,+ FANOUT_PARENTS,INCREMENTAL_FIELDS,PARTITION_KEYS,+ PRIMARY_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 (@@ -109,10 +111,12 @@ class AsaasSource(ResumableSource[AsaasSourceConfig, AsaasResumeConfig]):return SourceResponse(name=resource.name,items=lambda: resource,- primary_keys=["id"],+ primary_keys=PRIMARY_KEYS.get(inputs.schema_name, ["id"]),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,+ # The fan-out saves no checkpoint, so a shutdown hand-off would only restart the sweep.+ supports_resume=inputs.schema_name not in FANOUT_PARENTS,)@property@@ -124,7 +128,8 @@ class AsaasSource(ResumableSource[AsaasSourceConfig, AsaasResumeConfig]):caption=("Connect your Asaas account using an API key to sync customers, payments, ""subscriptions, transfers, installments, invoices, received splits, Pix "- "transactions, and your account statement. Find your key in Asaas under "+ "transactions, payment links, dunnings, bill payments, 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 732baf99c0a2..0785c3332025 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@@ -205,16 +205,48 @@ class TestAsaasSource:@parameterized.expand([- ("ReceivedSplits", "/v3/payments/splits/received"),- ("Invoices", "/v3/invoices"),- ("PixTransactions", "/v3/pix/transactions"),+ ("ReceivedSplits", "/v3/payments/splits/received", {}),+ ("Invoices", "/v3/invoices", {}),+ ("PixTransactions", "/v3/pix/transactions", {}),+ ("PaymentLinks", "/v3/paymentLinks", {"includeDeleted": "true"}),+ ("PaymentDunnings", "/v3/paymentDunnings", {}),+ ("BillPayments", "/v3/bill", {}),])- def test_full_refresh_endpoint_requests_vendor_path(self, endpoint: str, expected_path: str) -> None:+ def test_full_refresh_endpoint_requests_vendor_path(+ self, endpoint: str, expected_path: str, expected_params: dict[str, str]+ ) -> None:result = _driver().run(endpoint, [_page([{"id": "row-1"}], 1)])assert result.raised is Noneassert result.paths == [expected_path]+ for name, value in expected_params.items():+ assert result.requests[0].param(name) == value++ def test_dunning_history_fans_out_per_dunning_and_tags_rows_with_the_dunning(self) -> None:+ result = _driver().run(+ "PaymentDunningHistory",+ [+ _page([{"id": "dunning-1"}, {"id": "dunning-2"}], 2),+ _page([{"status": "IN_NEGOTIATION", "description": "Started", "eventDate": "2026-01-02"}], 1),+ _page([{"status": "PAID", "description": "Paid", "eventDate": "2026-01-05"}], 1),+ ],+ )++ assert result.raised is None+ assert result.paths == [+ "/v3/paymentDunnings",+ "/v3/paymentDunnings/dunning-1/history",+ "/v3/paymentDunnings/dunning-2/history",+ ]+ assert [(row["paymentDunning"], row["status"]) for row in result.rows] == [+ ("dunning-1", "IN_NEGOTIATION"),+ ("dunning-2", "PAID"),+ ]+ assert all("_PaymentDunnings_id" not in row for row in result.rows)+ assert result.response is not None+ assert result.response.primary_keys == ["paymentDunning", "eventDate", "status", "description"]+ assert result.response.supports_resume is Falsedef test_source_for_pipeline_omits_cursor_when_not_incremental(self) -> None:inputs = mock.MagicMock()