dex-connector-braintree 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dex_connector_braintree-0.1.0/.gitignore +16 -0
- dex_connector_braintree-0.1.0/LICENSE +21 -0
- dex_connector_braintree-0.1.0/PKG-INFO +15 -0
- dex_connector_braintree-0.1.0/README.md +3 -0
- dex_connector_braintree-0.1.0/examples/transaction_read/README.md +5 -0
- dex_connector_braintree-0.1.0/examples/transaction_read/__init__.py +3 -0
- dex_connector_braintree-0.1.0/examples/transaction_read/flow.py +79 -0
- dex_connector_braintree-0.1.0/examples/transaction_read/integration_test.py +85 -0
- dex_connector_braintree-0.1.0/examples/transaction_read/worker.py +52 -0
- dex_connector_braintree-0.1.0/pyproject.toml +37 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/__init__.py +22 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/_generated/__init__.py +2 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/_generated/config.py +27 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/_generated/connection.py +139 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/_generated/definitions.py +40 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/_generated/mock.py +74 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/_generated/models.py +26 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/_generated/steps.py +81 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/braintreemock/__init__.py +6 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/client.py +290 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/connection.py +8 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/dex-connector.json +65 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/models.py +8 -0
- dex_connector_braintree-0.1.0/src/dex_connectors/braintree/steps.py +5 -0
- dex_connector_braintree-0.1.0/tests/test_configuration_guidance.py +33 -0
- dex_connector_braintree-0.1.0/tests/test_conformance.py +35 -0
- dex_connector_braintree-0.1.0/tests/test_manifest_contract.py +15 -0
- dex_connector_braintree-0.1.0/uv.lock +932 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
node_modules/
|
|
5
|
+
dist/
|
|
6
|
+
sdkpython/dist/dex_connectors_sdk-0.1.0-py3-none-any.whl
|
|
7
|
+
/.bin/dexcli
|
|
8
|
+
/.bin/dex-server-zd
|
|
9
|
+
/sdkpython/.dexcli-data/
|
|
10
|
+
site/.catalog.yaml
|
|
11
|
+
coverage/
|
|
12
|
+
*.out
|
|
13
|
+
*.test
|
|
14
|
+
go.work
|
|
15
|
+
go.work.sum
|
|
16
|
+
.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-braintree
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Braintree connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: dex-connectors-sdk==0.1.0
|
|
9
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Braintree Python connector
|
|
14
|
+
|
|
15
|
+
Implements `getTransaction`, returning one GraphQL transaction ID and status. Go-recorded conformance checks exact requests, branches, retries, and outputs. Configure `publicKey` and secret `privateKey` using the [connection guide](../README.md). See the [runnable Dex Flow](examples/transaction_read/README.md). Live provider authorization remains unverified.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Braintree Python connector
|
|
2
|
+
|
|
3
|
+
Implements `getTransaction`, returning one GraphQL transaction ID and status. Go-recorded conformance checks exact requests, branches, retries, and outputs. Configure `publicKey` and secret `privateKey` using the [connection guide](../README.md). See the [runnable Dex Flow](examples/transaction_read/README.md). Live provider authorization remains unverified.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Braintree Python transaction lookup
|
|
2
|
+
|
|
3
|
+
This runnable Flow reads one Braintree transaction with `getTransaction` through the static `braintree` connection and persists its profile. Configure `publicKey` and secret `privateKey` in Dex Web Connections using the [connection guide](../../../README.md). Optional branches are unwired and fail the Flow when selected.
|
|
4
|
+
|
|
5
|
+
From `connectors/braintree/python`, run `uv run python -m examples.transaction_read.worker` with the project's `DEX_PROJECT_*` environment and a running `dexcli dev` service. Start Flow type `BraintreeTransactionReadPython` with a unique Flow ID and input `{"transactionId":"txn-1"}`. Replace the sample IDs with GraphQL transaction ID from your Braintree account.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Runnable Braintree transaction lookup Flow using getTransaction."""
|
|
4
|
+
|
|
5
|
+
import dex
|
|
6
|
+
from dex_connectors.sdk import QueryResult
|
|
7
|
+
|
|
8
|
+
from dex_connectors.braintree import (
|
|
9
|
+
Connection,
|
|
10
|
+
GetTransactionInput,
|
|
11
|
+
TransactionProfile,
|
|
12
|
+
new_get_transaction_step,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
FLOW_TYPE = "BraintreeTransactionReadPython"
|
|
16
|
+
CONNECTION_NAME = "braintree"
|
|
17
|
+
_CALL_STEP_TYPE = "CallBraintree"
|
|
18
|
+
_RESULT = dex.Attribute("braintree-transaction-read", TransactionProfile)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def map_to_operation_input(request: GetTransactionInput) -> GetTransactionInput:
|
|
22
|
+
"""Send the request unchanged."""
|
|
23
|
+
return request
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# dex:group group-id:braintree group-label:"Braintree"
|
|
27
|
+
# dex:explanation text:"Start the Braintree request."
|
|
28
|
+
class _StartRequest(dex.Step[GetTransactionInput]):
|
|
29
|
+
def get_step_type(self) -> str:
|
|
30
|
+
return "StartBraintreeRequest"
|
|
31
|
+
|
|
32
|
+
def execute(self, context: dex.Context, input: GetTransactionInput) -> dex.StepDecision:
|
|
33
|
+
return dex.go_to(dex.StepRef("CallBraintree"), input)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# dex:group group-id:braintree group-label:"Braintree"
|
|
37
|
+
# dex:explanation text:"Record the provider result and complete the Flow."
|
|
38
|
+
class _CompleteRequest(dex.Step[QueryResult[TransactionProfile]]):
|
|
39
|
+
def get_step_type(self) -> str:
|
|
40
|
+
return "CompleteBraintreeRequest"
|
|
41
|
+
|
|
42
|
+
def execute(self, context: dex.Context, input: QueryResult[TransactionProfile]) -> dex.StepDecision:
|
|
43
|
+
_RESULT.set(context, input.value)
|
|
44
|
+
return dex.graceful_complete(input.value)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TransactionReadFlow(dex.Flow[GetTransactionInput]):
|
|
48
|
+
"""Read transaction status through the static braintree connection."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, connection: Connection) -> None:
|
|
51
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
52
|
+
raise ValueError("transaction lookup requires the static braintree connection")
|
|
53
|
+
self._start = _StartRequest()
|
|
54
|
+
self._complete = _CompleteRequest()
|
|
55
|
+
self._call = new_get_transaction_step(
|
|
56
|
+
step_type=_CALL_STEP_TYPE,
|
|
57
|
+
step_input_type=GetTransactionInput,
|
|
58
|
+
annotations={
|
|
59
|
+
"groupId": "braintree",
|
|
60
|
+
"groupLabel": "Braintree",
|
|
61
|
+
"explanation": "Read transaction status from the connected Braintree workspace.",
|
|
62
|
+
},
|
|
63
|
+
connection=connection,
|
|
64
|
+
connection_name=CONNECTION_NAME,
|
|
65
|
+
map_to_operation_input=map_to_operation_input,
|
|
66
|
+
found=self._complete,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def get_flow_type(self) -> str:
|
|
70
|
+
"""Return the stable Flow identity used in Dex Web."""
|
|
71
|
+
return "BraintreeTransactionReadPython"
|
|
72
|
+
|
|
73
|
+
def get_steps(self) -> dex.StepList[GetTransactionInput]:
|
|
74
|
+
"""Register the start, provider read, and completion Steps."""
|
|
75
|
+
return dex.StepList.start_step(self._start).other_steps(self._call, self._complete)
|
|
76
|
+
|
|
77
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
78
|
+
"""Persist the provider result."""
|
|
79
|
+
return dex.PersistenceSchema.of(_RESULT)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Real Dex Worker and Client verification for the Braintree Python Flow."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import base64
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
from datetime import timedelta
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from uuid import uuid4
|
|
12
|
+
|
|
13
|
+
import dex
|
|
14
|
+
import httpx
|
|
15
|
+
import pytest
|
|
16
|
+
from dex_connectors.sdk import ConnectionRef, SecretString, StaticCredentialProvider
|
|
17
|
+
|
|
18
|
+
from dex_connectors.braintree import (
|
|
19
|
+
Client,
|
|
20
|
+
Config,
|
|
21
|
+
Credentials,
|
|
22
|
+
GetTransactionInput,
|
|
23
|
+
TransactionProfile,
|
|
24
|
+
new_connection,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from .flow import CONNECTION_NAME, TransactionReadFlow
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.mark.asyncio
|
|
31
|
+
async def test_transaction_read_retries_503(tmp_path: Path) -> None:
|
|
32
|
+
"""Run the checked-in Flow across real Dex retry and persistence boundaries."""
|
|
33
|
+
address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
|
|
34
|
+
requests: list[httpx.Request] = []
|
|
35
|
+
|
|
36
|
+
def answer(request: httpx.Request) -> httpx.Response:
|
|
37
|
+
requests.append(request)
|
|
38
|
+
assert request.url.path == "/graphql"
|
|
39
|
+
assert request.headers["Authorization"] == "Basic " + base64.b64encode(
|
|
40
|
+
b"sample-public-key:sample-private-key"
|
|
41
|
+
).decode("ascii")
|
|
42
|
+
assert request.method == "POST"
|
|
43
|
+
assert request.headers["Content-Type"] == "application/json"
|
|
44
|
+
assert request.headers["Braintree-Version"] == "2019-01-01"
|
|
45
|
+
assert request.content and json.loads(request.content)["variables"] == {
|
|
46
|
+
"id": "txn-1",
|
|
47
|
+
}
|
|
48
|
+
if len(requests) == 1:
|
|
49
|
+
return httpx.Response(503)
|
|
50
|
+
return httpx.Response(
|
|
51
|
+
200,
|
|
52
|
+
json={
|
|
53
|
+
"data": {"node": {"__typename": "Transaction", "id": "txn-1", "status": "SETTLED"}},
|
|
54
|
+
},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
reference = ConnectionRef("braintree", CONNECTION_NAME)
|
|
58
|
+
credentials = Credentials("sample-public-key", SecretString("sample-private-key"))
|
|
59
|
+
async with httpx.AsyncClient(transport=httpx.MockTransport(answer)) as http_client:
|
|
60
|
+
provider = Client(
|
|
61
|
+
Config(base_url="http://127.0.0.1:12345"),
|
|
62
|
+
StaticCredentialProvider({reference: credentials}),
|
|
63
|
+
http_client,
|
|
64
|
+
)
|
|
65
|
+
connection = new_connection(provider, reference)
|
|
66
|
+
flow = TransactionReadFlow(connection)
|
|
67
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
68
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(str(tmp_path / "blobs"), 1 << 24))
|
|
69
|
+
worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=address))
|
|
70
|
+
worker_task = asyncio.create_task(worker.start())
|
|
71
|
+
try:
|
|
72
|
+
await worker.wait_pull_registered(timeout=15)
|
|
73
|
+
async with dex.AsyncClient(registry, cache, dex.ClientOptions(server_address=address)) as client:
|
|
74
|
+
flow_id = f"braintree-python-{uuid4().hex}"
|
|
75
|
+
await client.start_flow(flow, flow_id, GetTransactionInput(transaction_id="txn-1"))
|
|
76
|
+
result = await asyncio.wait_for(client.wait_for_flow(flow_id, timedelta(seconds=25)), 30)
|
|
77
|
+
assert result.status == dex.FlowStatus.COMPLETED, result.error_message
|
|
78
|
+
assert result.single_output(TransactionProfile).status == "SETTLED"
|
|
79
|
+
assert result.single_output(TransactionProfile).id == "txn-1"
|
|
80
|
+
assert len(requests) == 2
|
|
81
|
+
finally:
|
|
82
|
+
await worker.stop()
|
|
83
|
+
await worker_task
|
|
84
|
+
cache.close()
|
|
85
|
+
await connection.aclose()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Worker entrypoint for the Braintree transaction lookup Flow."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import dex
|
|
11
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
12
|
+
|
|
13
|
+
from dex_connectors.braintree import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, TransactionReadFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run_worker() -> None:
|
|
19
|
+
"""Load the named Dex Web connection and serve Braintree reads."""
|
|
20
|
+
project = await load_from_environment()
|
|
21
|
+
connection = None
|
|
22
|
+
cache = None
|
|
23
|
+
try:
|
|
24
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
25
|
+
registry = dex.Registry([TransactionReadFlow(connection)], allow_async_handlers=True)
|
|
26
|
+
cache_directory = os.environ.get(
|
|
27
|
+
"DEX_BLOB_CACHE_DIR",
|
|
28
|
+
str(Path(tempfile.gettempdir()) / "dex-braintree-worker-inspection-blobs"),
|
|
29
|
+
)
|
|
30
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 30))
|
|
31
|
+
worker = dex.AsyncWorker(
|
|
32
|
+
registry,
|
|
33
|
+
cache,
|
|
34
|
+
dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
|
|
35
|
+
)
|
|
36
|
+
async with worker:
|
|
37
|
+
await worker.start()
|
|
38
|
+
finally:
|
|
39
|
+
if connection is not None:
|
|
40
|
+
await connection.aclose()
|
|
41
|
+
if cache is not None:
|
|
42
|
+
cache.close()
|
|
43
|
+
await project.close()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main() -> None:
|
|
47
|
+
"""Run until the Worker stops or the process receives an interrupt."""
|
|
48
|
+
asyncio.run(run_worker())
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dex-connector-braintree"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Braintree connector for Dex Flows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = ["dex-connectors-sdk==0.1.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
|
|
13
|
+
|
|
14
|
+
[dependency-groups]
|
|
15
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7", "pyyaml>=6", "types-PyYAML>=6"]
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build.targets.wheel]
|
|
18
|
+
packages = ["src/dex_connectors"]
|
|
19
|
+
|
|
20
|
+
[tool.pytest.ini_options]
|
|
21
|
+
testpaths = ["tests"]
|
|
22
|
+
pythonpath = [".", "src"]
|
|
23
|
+
asyncio_mode = "auto"
|
|
24
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
25
|
+
|
|
26
|
+
[tool.mypy]
|
|
27
|
+
python_version = "3.11"
|
|
28
|
+
strict = true
|
|
29
|
+
mypy_path = "src"
|
|
30
|
+
explicit_package_bases = true
|
|
31
|
+
|
|
32
|
+
[tool.ruff]
|
|
33
|
+
target-version = "py311"
|
|
34
|
+
line-length = 110
|
|
35
|
+
|
|
36
|
+
[tool.ruff.lint]
|
|
37
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Braintree transaction Queries for Dex Flows."""
|
|
4
|
+
|
|
5
|
+
from .client import Client, Config, Credentials, GetTransactionOperation
|
|
6
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
7
|
+
from .models import GetTransactionInput, TransactionProfile
|
|
8
|
+
from .steps import new_get_transaction_step
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"TransactionProfile",
|
|
12
|
+
"Client",
|
|
13
|
+
"Config",
|
|
14
|
+
"Connection",
|
|
15
|
+
"Credentials",
|
|
16
|
+
"GetTransactionInput",
|
|
17
|
+
"GetTransactionOperation",
|
|
18
|
+
"new_connection",
|
|
19
|
+
"new_connection_with_operations",
|
|
20
|
+
"new_get_transaction_step",
|
|
21
|
+
"new_project_connection",
|
|
22
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
base_url: str = "https://payments.sandbox.braintree-api.com"
|
|
14
|
+
api_version: str = "2019-01-01"
|
|
15
|
+
timeout_seconds: float = 15
|
|
16
|
+
max_response_bytes: int = 1048576
|
|
17
|
+
|
|
18
|
+
setattr(Config, '__module__', 'dex_connectors.braintree.client')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True, slots=True)
|
|
22
|
+
class Credentials:
|
|
23
|
+
|
|
24
|
+
public_key: str
|
|
25
|
+
private_key: SecretString
|
|
26
|
+
|
|
27
|
+
setattr(Credentials, '__module__', 'dex_connectors.braintree.client')
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from dex_connectors.sdk import ConnectionRef, Query, Call, SecretString
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
|
|
11
|
+
from ..client import Client, Config, Credentials
|
|
12
|
+
from .definitions import CONNECTOR_ID, GET_TRANSACTION_DEFINITION
|
|
13
|
+
from ..models import GetTransactionInput, TransactionProfile
|
|
14
|
+
|
|
15
|
+
class Connection:
|
|
16
|
+
|
|
17
|
+
__slots__ = ('_get_transaction', '_client', 'reference')
|
|
18
|
+
|
|
19
|
+
def __init__(self,
|
|
20
|
+
reference: ConnectionRef,
|
|
21
|
+
get_transaction: Query[GetTransactionInput, TransactionProfile],
|
|
22
|
+
client: Client | None = None,
|
|
23
|
+
) -> None:
|
|
24
|
+
reference.validate()
|
|
25
|
+
if reference.provider != CONNECTOR_ID or get_transaction is None:
|
|
26
|
+
raise ValueError("Braintree connection provider and operations are required")
|
|
27
|
+
if get_transaction.definition().operation != GET_TRANSACTION_DEFINITION.operation:
|
|
28
|
+
raise ValueError("Braintree connection operation identity differs")
|
|
29
|
+
self.reference = reference
|
|
30
|
+
self._get_transaction = get_transaction
|
|
31
|
+
self._client = client
|
|
32
|
+
|
|
33
|
+
def get_transaction(self) -> Query[GetTransactionInput, TransactionProfile]:
|
|
34
|
+
return self._get_transaction
|
|
35
|
+
|
|
36
|
+
async def aclose(self) -> None:
|
|
37
|
+
if self._client is not None:
|
|
38
|
+
await self._client.aclose()
|
|
39
|
+
|
|
40
|
+
def __repr__(self) -> str:
|
|
41
|
+
return "braintree.Connection([REDACTED])"
|
|
42
|
+
|
|
43
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
44
|
+
raise TypeError("Braintree connections cannot be serialized")
|
|
45
|
+
|
|
46
|
+
setattr(Connection, '__module__', 'dex_connectors.braintree.connection')
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
50
|
+
if client is None:
|
|
51
|
+
raise ValueError("Braintree client is required")
|
|
52
|
+
return Connection(reference, client.get_transaction(), client)
|
|
53
|
+
|
|
54
|
+
setattr(new_connection, '__module__', 'dex_connectors.braintree.connection')
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def new_connection_with_operations(
|
|
58
|
+
get_transaction: Query[GetTransactionInput, TransactionProfile],
|
|
59
|
+
reference: ConnectionRef,
|
|
60
|
+
) -> Connection:
|
|
61
|
+
return Connection(reference, get_transaction)
|
|
62
|
+
|
|
63
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.braintree.connection')
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class _ProjectCredentialSource:
|
|
67
|
+
|
|
68
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey) -> None:
|
|
69
|
+
self.project = project
|
|
70
|
+
self.key = key
|
|
71
|
+
|
|
72
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
73
|
+
material = await self.project.resolve_credential(self.key, str(call.id))
|
|
74
|
+
if not isinstance(material, dict):
|
|
75
|
+
raise ValueError("Braintree stored credential does not match the connector credential fields")
|
|
76
|
+
if set(material) - set(('publicKey', 'privateKey')):
|
|
77
|
+
raise ValueError("Braintree stored credential does not match the connector credential fields")
|
|
78
|
+
public_key = material.get("publicKey")
|
|
79
|
+
if public_key is not None and not (isinstance(public_key, str)):
|
|
80
|
+
raise ValueError("Braintree credential publicKey has an invalid type")
|
|
81
|
+
private_key = material.get("privateKey")
|
|
82
|
+
if private_key is not None and not (isinstance(private_key, str)):
|
|
83
|
+
raise ValueError("Braintree credential privateKey has an invalid type")
|
|
84
|
+
if not public_key:
|
|
85
|
+
raise ValueError("Braintree credential publicKey is required")
|
|
86
|
+
if not private_key:
|
|
87
|
+
raise ValueError("Braintree credential privateKey is required")
|
|
88
|
+
return Credentials(public_key, SecretString(private_key))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def new_project_connection(
|
|
92
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
93
|
+
) -> Connection:
|
|
94
|
+
if project is None:
|
|
95
|
+
raise ValueError("Braintree connection requires loaded project configuration")
|
|
96
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
97
|
+
reference.validate()
|
|
98
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
99
|
+
matching = [
|
|
100
|
+
entry
|
|
101
|
+
for entry in project.configuration.connections
|
|
102
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
103
|
+
]
|
|
104
|
+
if len(matching) != 1:
|
|
105
|
+
raise ValueError("Braintree project connection is missing or duplicated")
|
|
106
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
107
|
+
raise ValueError("Braintree project connection provider differs")
|
|
108
|
+
config = _decode_config(matching[0].configuration)
|
|
109
|
+
client = Client(config, _ProjectCredentialSource(project, key), http_client)
|
|
110
|
+
return new_connection(client, reference)
|
|
111
|
+
|
|
112
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.braintree.connection')
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
116
|
+
if set(value) - {"baseUrl", "apiVersion", "timeout", "maxResponseBytes"}:
|
|
117
|
+
raise ValueError("Braintree configuration has unknown fields")
|
|
118
|
+
config_arguments: dict[str, Any] = {}
|
|
119
|
+
if "baseUrl" in value:
|
|
120
|
+
base_url = value["baseUrl"]
|
|
121
|
+
if not (isinstance(base_url, str)):
|
|
122
|
+
raise ValueError("Braintree configuration baseUrl has an invalid type")
|
|
123
|
+
config_arguments['base_url'] = base_url
|
|
124
|
+
if "apiVersion" in value:
|
|
125
|
+
api_version = value["apiVersion"]
|
|
126
|
+
if not (isinstance(api_version, str)):
|
|
127
|
+
raise ValueError("Braintree configuration apiVersion has an invalid type")
|
|
128
|
+
config_arguments['api_version'] = api_version
|
|
129
|
+
if "timeout" in value:
|
|
130
|
+
timeout = value["timeout"]
|
|
131
|
+
if not (type(timeout) is int):
|
|
132
|
+
raise ValueError("Braintree configuration timeout has an invalid type")
|
|
133
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
134
|
+
if "maxResponseBytes" in value:
|
|
135
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
136
|
+
if not (type(max_response_bytes) is int):
|
|
137
|
+
raise ValueError("Braintree configuration maxResponseBytes has an invalid type")
|
|
138
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
139
|
+
return Config(**config_arguments)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import (
|
|
8
|
+
BranchDefinition,
|
|
9
|
+
MutationDefinition,
|
|
10
|
+
OperationRef,
|
|
11
|
+
QueryDefinition,
|
|
12
|
+
RetryPolicy,
|
|
13
|
+
StepDefaults,
|
|
14
|
+
default_connector_step_execute_retry_policy,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTOR_ID = "braintree"
|
|
18
|
+
PROVIDER = "braintree"
|
|
19
|
+
GET_TRANSACTION_OPERATION_ID = "getTransaction"
|
|
20
|
+
DEFECT = "defect"
|
|
21
|
+
FOUND = "found"
|
|
22
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
23
|
+
NOT_FOUND = "notFound"
|
|
24
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
25
|
+
|
|
26
|
+
GET_TRANSACTION_DEFINITION = QueryDefinition(
|
|
27
|
+
OperationRef(CONNECTOR_ID, GET_TRANSACTION_OPERATION_ID),
|
|
28
|
+
(
|
|
29
|
+
BranchDefinition(FOUND, "Braintree returned the transaction.", False),
|
|
30
|
+
BranchDefinition(NOT_FOUND, "The node is absent or is another object type.", True),
|
|
31
|
+
BranchDefinition(PROVIDER_REJECTED, "Braintree returned a definite GraphQL or HTTP rejection.", True),
|
|
32
|
+
BranchDefinition(INVALID_RESPONSE, "Braintree returned malformed or oversized JSON.", True),
|
|
33
|
+
BranchDefinition(DEFECT, "Local input or credentials are invalid.", True),
|
|
34
|
+
),
|
|
35
|
+
StepDefaults(
|
|
36
|
+
timedelta(seconds=30),
|
|
37
|
+
2,
|
|
38
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
39
|
+
),
|
|
40
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import ConnectionRef, Failure, FailureKind
|
|
8
|
+
from dex_connectors.sdk.connectormock import Case, Query
|
|
9
|
+
|
|
10
|
+
from ..connection import Connection, new_connection_with_operations
|
|
11
|
+
from ..models import GetTransactionInput, TransactionProfile
|
|
12
|
+
from .definitions import CONNECTOR_ID, DEFECT, FOUND, GET_TRANSACTION_DEFINITION, INVALID_RESPONSE, NOT_FOUND, PROVIDER_REJECTED
|
|
13
|
+
|
|
14
|
+
def get_transaction_found(value: TransactionProfile, failure: Failure | None = None) -> Case[TransactionProfile]:
|
|
15
|
+
return Case.branch_result(FOUND, value, failure)
|
|
16
|
+
|
|
17
|
+
setattr(get_transaction_found, '__module__', "dex_connectors.braintree.braintreemock")
|
|
18
|
+
|
|
19
|
+
def get_transaction_not_found(value: TransactionProfile, failure: Failure | None = None) -> Case[TransactionProfile]:
|
|
20
|
+
return Case.branch_result(NOT_FOUND, value, failure)
|
|
21
|
+
|
|
22
|
+
setattr(get_transaction_not_found, '__module__', "dex_connectors.braintree.braintreemock")
|
|
23
|
+
|
|
24
|
+
def get_transaction_provider_rejected(value: TransactionProfile, failure: Failure | None = None) -> Case[TransactionProfile]:
|
|
25
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
26
|
+
|
|
27
|
+
setattr(get_transaction_provider_rejected, '__module__', "dex_connectors.braintree.braintreemock")
|
|
28
|
+
|
|
29
|
+
def get_transaction_invalid_response(value: TransactionProfile, failure: Failure | None = None) -> Case[TransactionProfile]:
|
|
30
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
31
|
+
|
|
32
|
+
setattr(get_transaction_invalid_response, '__module__', "dex_connectors.braintree.braintreemock")
|
|
33
|
+
|
|
34
|
+
def get_transaction_defect(value: TransactionProfile, failure: Failure | None = None) -> Case[TransactionProfile]:
|
|
35
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
36
|
+
|
|
37
|
+
setattr(get_transaction_defect, '__module__', "dex_connectors.braintree.braintreemock")
|
|
38
|
+
|
|
39
|
+
def get_transaction_retry(failure: Failure, after_seconds: float = 0) -> Case[TransactionProfile]:
|
|
40
|
+
return Case.retry(failure, after_seconds)
|
|
41
|
+
|
|
42
|
+
setattr(get_transaction_retry, '__module__', "dex_connectors.braintree.braintreemock")
|
|
43
|
+
|
|
44
|
+
def get_transaction_found_default() -> Case[TransactionProfile]:
|
|
45
|
+
return Case.branch_result(FOUND, TransactionProfile(id='txn-1', status='SETTLED'))
|
|
46
|
+
|
|
47
|
+
setattr(get_transaction_found_default, '__module__', "dex_connectors.braintree.braintreemock")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class Mock:
|
|
51
|
+
|
|
52
|
+
def __init__(self, connection_name: str = "braintree") -> None:
|
|
53
|
+
self.get_transaction_script: Query[GetTransactionInput, TransactionProfile] = Query(GET_TRANSACTION_DEFINITION)
|
|
54
|
+
self.get_transaction_script.default(get_transaction_found_default())
|
|
55
|
+
self._connection = new_connection_with_operations(
|
|
56
|
+
get_transaction=self.get_transaction_script,
|
|
57
|
+
reference=ConnectionRef(CONNECTOR_ID, connection_name),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def connection(self) -> Connection:
|
|
61
|
+
return self._connection
|
|
62
|
+
|
|
63
|
+
setattr(Mock, '__module__', "dex_connectors.braintree.braintreemock")
|
|
64
|
+
|
|
65
|
+
__all__ = [
|
|
66
|
+
"Mock",
|
|
67
|
+
"get_transaction_found",
|
|
68
|
+
"get_transaction_not_found",
|
|
69
|
+
"get_transaction_provider_rejected",
|
|
70
|
+
"get_transaction_invalid_response",
|
|
71
|
+
"get_transaction_defect",
|
|
72
|
+
"get_transaction_retry",
|
|
73
|
+
"get_transaction_found_default",
|
|
74
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field as _dataclass_field
|
|
6
|
+
|
|
7
|
+
# GetTransactionInput selects one Braintree GraphQL node by ID.
|
|
8
|
+
@dataclass(frozen=True, slots=True)
|
|
9
|
+
class GetTransactionInput:
|
|
10
|
+
# TransactionID is the GraphQL transaction ID, not a legacy SDK ID.
|
|
11
|
+
transaction_id: str = _dataclass_field(default='', metadata={'dex_json_name': 'transactionId'})
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
setattr(GetTransactionInput, '__module__', 'dex_connectors.braintree.models')
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# TransactionProfile contains a transaction's ID and current payment status.
|
|
18
|
+
@dataclass(frozen=True, slots=True)
|
|
19
|
+
class TransactionProfile:
|
|
20
|
+
# ID is the Braintree GraphQL transaction ID.
|
|
21
|
+
id: str = ''
|
|
22
|
+
# Status is the Braintree PaymentStatus enum value.
|
|
23
|
+
status: str = ''
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
setattr(TransactionProfile, '__module__', 'dex_connectors.braintree.models')
|