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(braintree): support Braintree API version 2026-07-14 (#71653)

Tom Owers81c289817d2c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/braintree.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/braintree.py
index d2870f9cd8b7..266e5091d75c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/braintree.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/braintree.py
@@ -19,8 +19,9 @@ BRAINTREE_HOSTS = {
"production": "https://payments.braintree-api.com/graphql",
"sandbox": "https://payments.sandbox.braintree-api.com/graphql",
}
-# Pinned GraphQL API version (date-versioned header, required).
-BRAINTREE_VERSION = "2019-01-01"
+# GraphQL API version (date-versioned header, required). Opaque vendor labels — never parsed.
+BRAINTREE_VERSION_2019_01_01 = "2019-01-01"
+BRAINTREE_VERSION_2026_07_14 = "2026-07-14"
PAGE_SIZE = 100
# Braintree recommends generous timeouts due to async transaction processing.
REQUEST_TIMEOUT_SECONDS = 120
@@ -42,9 +43,9 @@ class BraintreeResumeConfig:
after: str
-def _get_session(public_key: str, private_key: str) -> requests.Session:
+def _get_session(public_key: str, private_key: str, api_version: str) -> requests.Session:
session = make_tracked_session(
- headers={"Braintree-Version": BRAINTREE_VERSION},
+ headers={"Braintree-Version": api_version},
redact_values=(private_key,),
)
session.auth = (public_key, private_key)
@@ -116,10 +117,10 @@ class _NoopLogger:
return None
-def validate_credentials(environment: str, public_key: str, private_key: str) -> bool:
+def validate_credentials(environment: str, public_key: str, private_key: str, api_version: str) -> bool:
"""Confirm the key pair is valid with the GraphQL ping query."""
try:
- session = _get_session(public_key, private_key)
+ session = _get_session(public_key, private_key, api_version)
data = _execute(session, _base_url(environment), "query { ping }", {}, _NoopLogger()) # type: ignore[arg-type]
return data.get("ping") == "pong"
except Exception:
@@ -131,13 +132,14 @@ def get_rows(
public_key: str,
private_key: str,
endpoint: str,
+ api_version: str,
logger: FilteringBoundLogger,
resumable_source_manager: ResumableSourceManager[BraintreeResumeConfig],
should_use_incremental_field: bool = False,
db_incremental_field_last_value: Any = None,
) -> Iterator[list[dict[str, Any]]]:
config = BRAINTREE_ENDPOINTS[endpoint]
- session = _get_session(public_key, private_key)
+ session = _get_session(public_key, private_key, api_version)
url = _base_url(environment)
query = _build_query(config)
@@ -186,6 +188,7 @@ def braintree_source(
public_key: str,
private_key: str,
endpoint: str,
+ api_version: str,
logger: FilteringBoundLogger,
resumable_source_manager: ResumableSourceManager[BraintreeResumeConfig],
should_use_incremental_field: bool = False,
@@ -200,6 +203,7 @@ def braintree_source(
public_key=public_key,
private_key=private_key,
endpoint=endpoint,
+ api_version=api_version,
logger=logger,
resumable_source_manager=resumable_source_manager,
should_use_incremental_field=should_use_incremental_field,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/source.py
index c744c478bf1c..1308100824ab 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/source.py
@@ -16,6 +16,8 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline
SourceResponse,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.braintree.braintree import (
+ BRAINTREE_VERSION_2019_01_01,
+ BRAINTREE_VERSION_2026_07_14,
BraintreeResumeConfig,
braintree_source,
validate_credentials as validate_braintree_credentials,
@@ -41,8 +43,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class BraintreeSource(ResumableSource[BraintreeSourceConfig, BraintreeResumeConfig]):
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
- supported_versions = ("2019-01-01",)
- default_version = "2019-01-01"
+ supported_versions = (BRAINTREE_VERSION_2019_01_01, BRAINTREE_VERSION_2026_07_14)
+ default_version = BRAINTREE_VERSION_2026_07_14
api_docs_url = "https://graphql.braintreepayments.com/"
@property
@@ -121,7 +123,9 @@ You can find your public and private keys in the [Braintree control panel](https
def validate_credentials(
self, config: BraintreeSourceConfig, team_id: int, schema_name: Optional[str] = None
) -> tuple[bool, str | None]:
- if validate_braintree_credentials(config.environment, config.public_key, config.private_key):
+ if validate_braintree_credentials(
+ config.environment, config.public_key, config.private_key, self.resolve_api_version(None)
+ ):
return True, None
return False, "Invalid Braintree API keys"
@@ -140,6 +144,7 @@ You can find your public and private keys in the [Braintree control panel](https
public_key=config.public_key,
private_key=config.private_key,
endpoint=inputs.schema_name,
+ api_version=self.resolve_api_version(inputs.api_version),
logger=inputs.logger,
resumable_source_manager=resumable_source_manager,
should_use_incremental_field=inputs.should_use_incremental_field,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree.py
index 30bfb54f6880..03ce28e00f3d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree.py
@@ -5,6 +5,8 @@ import pytest
from unittest import mock
from products.warehouse_sources.backend.temporal.data_imports.sources.braintree.braintree import (
+ BRAINTREE_VERSION_2019_01_01,
+ BRAINTREE_VERSION_2026_07_14,
PAGE_SIZE,
BraintreeGraphQLError,
BraintreeResumeConfig,
@@ -21,6 +23,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.braintree.
)
_MODULE = "products.warehouse_sources.backend.temporal.data_imports.sources.braintree.braintree"
+_VERSION = BRAINTREE_VERSION_2026_07_14
def _make_manager(resume_state: BraintreeResumeConfig | None = None) -> mock.MagicMock:
@@ -92,7 +95,7 @@ class TestValidateCredentials:
resp.ok = True
mock_session.return_value.post.return_value = resp
- assert validate_credentials("production", "pub", "priv") is True
+ assert validate_credentials("production", "pub", "priv", _VERSION) is True
@mock.patch(f"{_MODULE}.make_tracked_session")
def test_invalid_on_graphql_error(self, mock_session):
@@ -102,12 +105,12 @@ class TestValidateCredentials:
resp.ok = True
mock_session.return_value.post.return_value = resp
- assert validate_credentials("production", "pub", "priv") is False
+ assert validate_credentials("production", "pub", "priv", _VERSION) is False
@mock.patch(f"{_MODULE}.make_tracked_session")
def test_invalid_on_exception(self, mock_session):
mock_session.return_value.post.side_effect = Exception("boom")
- assert validate_credentials("production", "pub", "priv") is False
+ assert validate_credentials("production", "pub", "priv", _VERSION) is False
class TestGetRows:
@@ -119,7 +122,7 @@ class TestGetRows:
]
manager = _make_manager()
- batches = list(get_rows("production", "pub", "priv", "transactions", mock.MagicMock(), manager))
+ batches = list(get_rows("production", "pub", "priv", "transactions", _VERSION, mock.MagicMock(), manager))
assert [item["id"] for batch in batches for item in batch] == ["t1", "t2", "t3"]
manager.save_state.assert_called_once()
@@ -139,6 +142,7 @@ class TestGetRows:
"pub",
"priv",
"transactions",
+ _VERSION,
mock.MagicMock(),
manager,
should_use_incremental_field=True,
@@ -154,7 +158,7 @@ class TestGetRows:
mock_session.return_value.post.return_value = _search_response("transactions", [])
manager = _make_manager()
- list(get_rows("production", "pub", "priv", "transactions", mock.MagicMock(), manager))
+ list(get_rows("production", "pub", "priv", "transactions", _VERSION, mock.MagicMock(), manager))
variables = mock_session.return_value.post.call_args.kwargs["json"]["variables"]
assert variables["input"] is None
@@ -164,7 +168,7 @@ class TestGetRows:
mock_session.return_value.post.return_value = _search_response("transactions", [])
manager = _make_manager(BraintreeResumeConfig(after="cur-resume"))
- list(get_rows("production", "pub", "priv", "transactions", mock.MagicMock(), manager))
+ list(get_rows("production", "pub", "priv", "transactions", _VERSION, mock.MagicMock(), manager))
variables = mock_session.return_value.post.call_args.kwargs["json"]["variables"]
assert variables["after"] == "cur-resume"
@@ -179,25 +183,26 @@ class TestGetRows:
manager = _make_manager()
with pytest.raises(BraintreeGraphQLError):
- list(get_rows("production", "pub", "priv", "transactions", mock.MagicMock(), manager))
+ list(get_rows("production", "pub", "priv", "transactions", _VERSION, mock.MagicMock(), manager))
+ @pytest.mark.parametrize("api_version", [BRAINTREE_VERSION_2019_01_01, BRAINTREE_VERSION_2026_07_14])
@mock.patch(f"{_MODULE}.make_tracked_session")
- def test_session_uses_basic_auth_and_version_header(self, mock_session):
+ def test_session_uses_basic_auth_and_version_header(self, mock_session, api_version):
mock_session.return_value.post.return_value = _search_response("transactions", [])
manager = _make_manager()
- list(get_rows("production", "pub", "priv", "transactions", mock.MagicMock(), manager))
+ list(get_rows("production", "pub", "priv", "transactions", api_version, mock.MagicMock(), manager))
assert mock_session.return_value.auth == ("pub", "priv")
headers = mock_session.call_args.kwargs["headers"]
- assert headers["Braintree-Version"]
+ assert headers["Braintree-Version"] == api_version
class TestBraintreeSourceResponse:
@pytest.mark.parametrize("endpoint", list(ENDPOINTS))
def test_response_metadata_per_endpoint(self, endpoint):
config = BRAINTREE_ENDPOINTS[endpoint]
- response = braintree_source("production", "pub", "priv", endpoint, mock.MagicMock(), _make_manager())
+ response = braintree_source("production", "pub", "priv", endpoint, _VERSION, mock.MagicMock(), _make_manager())
assert response.name == endpoint
assert response.primary_keys == [config.primary_key]
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree_source.py
index 849385c813d9..79bc84ab2e46 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree_source.py
@@ -111,7 +111,7 @@ class TestBraintreeSource:
assert is_valid is expected_valid
assert error_message == expected_message
- mock_validate.assert_called_once_with("production", "pub", "priv")
+ mock_validate.assert_called_once_with("production", "pub", "priv", "2026-07-14")
def test_get_resumable_source_manager_binds_resume_config(self):
inputs = mock.MagicMock()
@@ -150,3 +150,40 @@ class TestBraintreeSource:
self.source.source_for_pipeline(self.config, mock.MagicMock(), inputs)
assert mock_bt_source.call_args.kwargs["db_incremental_field_last_value"] is None
+
+ def test_supported_versions_and_default(self):
+ assert self.source.supported_versions == ("2019-01-01", "2026-07-14")
+ # New sources start on the latest version; the default must stay in supported.
+ assert self.source.default_version == "2026-07-14"
+ assert self.source.default_version in self.source.supported_versions
+
+ @pytest.mark.parametrize(
+ "pinned, expected",
+ [
+ ("2019-01-01", "2019-01-01"),
+ ("2026-07-14", "2026-07-14"),
+ (None, "2026-07-14"),
+ ("", "2026-07-14"),
+ ],
+ )
+ def test_resolve_api_version(self, pinned, expected):
+ assert self.source.resolve_api_version(pinned) == expected
+
+ @pytest.mark.parametrize(
+ "pinned, expected",
+ [
+ ("2019-01-01", "2019-01-01"),
+ ("2026-07-14", "2026-07-14"),
+ (None, "2026-07-14"),
+ ],
+ )
+ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.braintree.source.braintree_source")
+ def test_source_for_pipeline_dispatches_resolved_version(self, mock_bt_source, pinned, expected):
+ inputs = mock.MagicMock()
+ inputs.schema_name = "transactions"
+ inputs.should_use_incremental_field = False
+ inputs.api_version = pinned
+
+ self.source.source_for_pipeline(self.config, mock.MagicMock(), inputs)
+
+ assert mock_bt_source.call_args.kwargs["api_version"] == expected