paymos-langchain 1.0.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.
@@ -0,0 +1,71 @@
1
+ name: Publish
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ tags: ["v*"]
7
+ pull_request:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ concurrency:
13
+ group: publish-${{ github.ref }}
14
+ cancel-in-progress: false
15
+
16
+ jobs:
17
+ build:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
21
+ with:
22
+ persist-credentials: false
23
+ - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
24
+ with:
25
+ python-version: "3.13"
26
+ - name: Verify immutable release version
27
+ if: startsWith(github.ref, 'refs/tags/v')
28
+ run: python -c "import os,tomllib,pathlib; actual=tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['version']; expected=os.environ['GITHUB_REF_NAME'][1:]; assert actual == expected, f'tag {expected} != package {actual}'"
29
+ - name: Install base package and dev tools
30
+ run: python -m pip install --disable-pip-version-check ".[dev]"
31
+ - name: Lint and type-check
32
+ run: |
33
+ python -m ruff format --check .
34
+ python -m ruff check .
35
+ python -m mypy src/paymos_langchain
36
+ - name: Run unit tests (base install without langchain-core)
37
+ run: python -m unittest discover -s tests -v
38
+ - name: Run unit tests with [langchain] extra
39
+ run: |
40
+ python -m venv /tmp/paymos-langchain-extra
41
+ /tmp/paymos-langchain-extra/bin/python -m pip install --disable-pip-version-check ".[langchain]"
42
+ /tmp/paymos-langchain-extra/bin/python -m unittest discover -s tests -v
43
+ - name: Build wheel and sdist
44
+ run: python -m build
45
+ - name: Test built wheel in isolation (base + langchain extra)
46
+ run: |
47
+ python -m venv /tmp/paymos-wheel-base
48
+ /tmp/paymos-wheel-base/bin/python -m pip install --disable-pip-version-check dist/*.whl
49
+ cd /tmp
50
+ /tmp/paymos-wheel-base/bin/python -c "import paymos_langchain as pl; assert pl.VERSION; assert len(pl.ALL_TOOL_NAMES) == 25"
51
+ python -m venv /tmp/paymos-wheel-langchain
52
+ /tmp/paymos-wheel-langchain/bin/python -m pip install --disable-pip-version-check "$GITHUB_WORKSPACE"/dist/*.whl "langchain-core>=0.3.0" "pydantic>=2.0.0"
53
+ /tmp/paymos-wheel-langchain/bin/python -c "from langchain_core.tools import BaseToolkit; from paymos import Paymos; from paymos_langchain import PaymosToolkit; assert issubclass(PaymosToolkit, BaseToolkit); tk = PaymosToolkit(payment_client=Paymos('pk_live_1', 'sk_live_1'), payout_client=Paymos('rk_live_1', 'sk_live_1')); assert len(tk.get_tools()) == 15"
54
+ - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
55
+ with:
56
+ name: python-package
57
+ path: dist/
58
+ if-no-files-found: error
59
+
60
+ pypi:
61
+ needs: build
62
+ if: startsWith(github.ref, 'refs/tags/v')
63
+ runs-on: ubuntu-latest
64
+ permissions:
65
+ id-token: write
66
+ steps:
67
+ - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
68
+ with:
69
+ name: python-package
70
+ path: dist/
71
+ - uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # release/v1
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [1.0.0] - 2026-12-05
6
+
7
+ - Initial release of `paymos-langchain` built on top of `paymos-sdk`.
8
+ - Add `PaymosAgentTools` with key-scoped separation between Payment (`pk_*`) and Payout (`rk_*`) clients and automatic single-client prefix classification.
9
+ - Add least-privilege `PaymosToolPermissions` gating withdrawals, refunds, cancellations, and channel moderation behind explicit opt-in flags.
10
+ - Add per-scope sandbox simulation auto-detection (`pk_test_*` enables payment simulators only; `rk_test_*` enables withdrawal simulation only).
11
+ - Add strict runtime argument validation for all 25 Paymos Merchant API operations and secret redaction (`sanitize_error_message`) for API secrets, `sk_*`, `rk_*`, `whsec_*`, `HMAC-SHA256`, and `Bearer` tokens.
12
+ - Add OpenAI Chat Completions (`to_openai_tools`) and Responses API (`to_openai_responses_tools`) schema exporters.
13
+ - Add `PaymosToolkit` compatible with `langchain-core` (`BaseToolkit` and `StructuredTool`) as well as custom `tool_builder` adapters.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Paymos Labs
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,216 @@
1
+ Metadata-Version: 2.4
2
+ Name: paymos-langchain
3
+ Version: 1.0.0
4
+ Summary: Official Paymos AI agent tools and LangChain toolkit for stablecoin payments, channels, refunds, and payouts
5
+ Project-URL: Homepage, https://paymos.io
6
+ Project-URL: Documentation, https://paymos.io/docs
7
+ Project-URL: Repository, https://github.com/Paymos-labs/paymos-langchain
8
+ Project-URL: Issues, https://github.com/Paymos-labs/paymos-langchain/issues
9
+ Author-email: Paymos Labs <support@paymos.io>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai-agents,crewai,langchain,openai-agents,payments,paymos,stablecoins,usdc,usdt
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: paymos-sdk>=1.0.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: build>=1.2.2; extra == 'dev'
25
+ Requires-Dist: mypy>=1.14.0; extra == 'dev'
26
+ Requires-Dist: ruff>=0.9.0; extra == 'dev'
27
+ Provides-Extra: langchain
28
+ Requires-Dist: langchain-core>=0.3.0; extra == 'langchain'
29
+ Requires-Dist: pydantic>=2.0.0; extra == 'langchain'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # paymos-langchain
33
+
34
+ Official Python AI agent tools and LangChain toolkit for the [Paymos](https://paymos.io) Merchant API, built on top of [`paymos-sdk`](https://github.com/Paymos-labs/python-sdk).
35
+
36
+ Give LangChain, LangGraph, OpenAI Agents, CrewAI, or custom Python tool loops safe, key-scoped access to Paymos invoices, static per-customer payment channels, deposit feeds, server-calculated refunds, balances, and payouts.
37
+
38
+ ## Why Paymos for AI Agents
39
+
40
+ - **Key-scope isolation (`pk_*` vs `rk_*`):** Paymos separates Payment API keys (`pk_live_*` / `pk_test_*`) from Payout API keys (`rk_live_*` / `rk_test_*`). `paymos-langchain` enforces the same boundary locally before any HTTP request is signed.
41
+ - **Least-privilege by default:** Money-moving and destructive actions (`create_withdrawal`, `cancel_withdrawal`, `create_refund`, `cancel_invoice`, `block_payment_channel`, `unblock_payment_channel`) are disabled unless explicitly opted in through `PaymosToolPermissions`.
42
+ - **Per-scope sandbox auto-detection:** Test keys (`pk_test_*` and `rk_test_*`) automatically unlock only the matching sandbox simulation tools. Live keys (`pk_live_*` and `rk_live_*`) expose zero simulation tools by default.
43
+ - **Secret redaction in tool errors:** `PaymosAgentTools` catches SDK errors and redacts configured `api_secret` values as well as `sk_*`, `rk_*`, `whsec_*`, `HMAC-SHA256`, and `Bearer` credentials before returning error text to an LLM.
44
+ - **Transparent Paymos economics:** Accept **USDT, USDC, USD1, DAI** (stablecoins) and **XAUT** (gold-backed asset) across **13 deposit networks** and **11 payout networks** (NEAR and Sui are deposit-only). Standard incoming processing fee is **1.0%** (configurable `0–100%` pass-through to the payer; **0.3%** Enterprise rate on request), with **0% Paymos withdrawal commission** (subsidized network fee only) and automated AML screening in Production. Withdrawal address whitelisting is **off by default** (opt-in by the merchant Owner; live API payouts use a Payout key IP allowlist while the whitelist is off).
45
+
46
+ ## Installation
47
+
48
+ Framework-agnostic install (OpenAI function calling, OpenAI Agents SDK, CrewAI, custom runtimes — zero LangChain dependency required):
49
+
50
+ ```bash
51
+ pip install paymos-langchain
52
+ ```
53
+
54
+ With LangChain `BaseToolkit` and `StructuredTool` support:
55
+
56
+ ```bash
57
+ pip install "paymos-langchain[langchain]"
58
+ ```
59
+
60
+ Requires Python 3.10+ and `paymos-sdk>=1.0.0`.
61
+
62
+ ## Quickstart
63
+
64
+ ### 1. LangChain (`PaymosToolkit`)
65
+
66
+ ```python
67
+ import os
68
+ from paymos import Paymos
69
+ from paymos_langchain import PaymosToolkit, PaymosToolPermissions
70
+
71
+ payment_client = Paymos(
72
+ api_key=os.environ["PAYMOS_PAYMENT_API_KEY"], # pk_live_... or pk_test_...
73
+ api_secret=os.environ["PAYMOS_PAYMENT_API_SECRET"],
74
+ )
75
+ payout_client = Paymos(
76
+ api_key=os.environ["PAYMOS_PAYOUT_API_KEY"], # rk_live_... or rk_test_...
77
+ api_secret=os.environ["PAYMOS_PAYOUT_API_SECRET"],
78
+ )
79
+
80
+ toolkit = PaymosToolkit(
81
+ payment_client=payment_client,
82
+ payout_client=payout_client,
83
+ permissions=PaymosToolPermissions(
84
+ allow_refunds=False,
85
+ allow_withdrawals=False,
86
+ allow_cancellations=False,
87
+ allow_channel_moderation=False,
88
+ ),
89
+ )
90
+
91
+ tools = toolkit.get_tools() # 15 safe default StructuredTool instances
92
+ ```
93
+
94
+ ### 2. Single-Key Setup (Payment-Only or Payout-Only)
95
+
96
+ Pass a single `client=` to automatically classify it by `client.api_key` prefix (`pk_*` -> Payment scope, `rk_*` -> Payout scope):
97
+
98
+ ```python
99
+ from paymos import Paymos
100
+ from paymos_langchain import PaymosAgentTools
101
+
102
+ payment_only = PaymosAgentTools(
103
+ client=Paymos("pk_live_...", "sk_live_..."),
104
+ )
105
+ # Exposes 12 safe Payment + shared tools (excludes balances and withdrawals)
106
+
107
+ payout_only = PaymosAgentTools(
108
+ client=Paymos("rk_live_...", "sk_live_..."),
109
+ )
110
+ # Exposes 4 safe Payout + shared tools:
111
+ # ["get_server_time", "get_balances", "get_withdrawal", "list_withdrawals"]
112
+ ```
113
+
114
+ If you use a custom non-prefixed key in tests, pass `key_scope="payment"` or `key_scope="payout"`.
115
+
116
+ ### 3. OpenAI Function Calling / Agents SDK
117
+
118
+ ```python
119
+ import json
120
+ from paymos import Paymos
121
+ from paymos_langchain import PaymosAgentTools
122
+
123
+ agent_tools = PaymosAgentTools(
124
+ payment_client=Paymos("pk_test_...", "sk_test_..."),
125
+ )
126
+
127
+ # OpenAI Chat Completions format:
128
+ chat_tools = agent_tools.to_openai_tools()
129
+
130
+ # OpenAI Responses API / Agents SDK flat format:
131
+ responses_tools = agent_tools.to_openai_responses_tools()
132
+
133
+ # Dispatch a model tool call (accepts dict or raw JSON string):
134
+ result = agent_tools.execute_tool(
135
+ "create_invoice",
136
+ {
137
+ "project_id": "prj_...",
138
+ "amount": "25.00",
139
+ "currency": "USD",
140
+ "external_order_id": "order_1001",
141
+ },
142
+ )
143
+ print(json.dumps(result))
144
+ ```
145
+
146
+ ### 4. Custom Adapter Seam (`tool_builder`)
147
+
148
+ `PaymosToolkit.get_tools(tool_builder=...)` lets you plug into CrewAI, AutoGen, or your own tool class without installing `langchain-core`:
149
+
150
+ ```python
151
+ custom_tools = toolkit.get_tools(
152
+ tool_builder=lambda spec, fn: {
153
+ "name": spec.name,
154
+ "description": spec.description,
155
+ "parameters": spec.parameters,
156
+ "run": fn,
157
+ }
158
+ )
159
+ ```
160
+
161
+ ## Security Model & Permissions
162
+
163
+ | `PaymosToolPermissions` flag | Default | Tools unlocked (when matching client is configured) |
164
+ |---|---|---|
165
+ | `allow_withdrawals` | `False` | `create_withdrawal`, `cancel_withdrawal` (requires `payout_client`) |
166
+ | `allow_refunds` | `False` | `create_refund` (requires `payment_client`) |
167
+ | `allow_cancellations` | `False` | `cancel_invoice` (requires `payment_client`) |
168
+ | `allow_channel_moderation` | `False` | `block_payment_channel`, `unblock_payment_channel` (requires `payment_client`) |
169
+ | `enable_sandbox_tools` | `None` (auto) | `pk_test_*` unlocks 3 payment simulators; `rk_test_*` unlocks `simulate_withdrawal_completion`; `pk_live_*`/`rk_live_*` unlock 0 |
170
+
171
+ ### Exceptions
172
+
173
+ - `ToolPermissionError` — raised with **0 network calls** when a tool is disabled by permissions, disabled in production, or outside the configured API key scope.
174
+ - `ToolValidationError` — raised with **0 network calls** when arguments fail schema validation (missing required fields, invalid enums, blank or `>500`-char `reason`, empty `stage=""`, or invalid RFC 3339 timestamps on `list_refunds`).
175
+ - `PaymosToolError` — base exception wrapping runtime SDK failures with `sanitize_error_message` replacing secrets with `[REDACTED]`.
176
+
177
+ ## Complete 25-Tool Reference
178
+
179
+ | Tool | Key Scope | Gate | Description |
180
+ |---|---|---|---|
181
+ | `get_server_time` | `shared` | `default` | Get Paymos API server Unix timestamp |
182
+ | `create_invoice` | `payment` | `default` | Create an invoice with optional `products[]` line items |
183
+ | `get_invoice` | `payment` | `default` | Retrieve an invoice by `invoice_id` |
184
+ | `list_invoices` | `payment` | `default` | List invoices with cursor pagination and filters |
185
+ | `confirm_invoice_payment` | `payment` | `default` | Lock currency and network on an invoice for Host-to-Host checkout |
186
+ | `cancel_invoice` | `payment` | `allow_cancellations` | Cancel an invoice with a 1–500 character reason |
187
+ | `create_payment_channel` | `payment` | `default` | Idempotently create or fetch a customer's static payment channel |
188
+ | `get_payment_channel` | `payment` | `default` | Retrieve a payment channel and its provisioned network addresses |
189
+ | `list_payment_channels` | `payment` | `default` | List payment channels with cursor pagination and filters |
190
+ | `block_payment_channel` | `payment` | `allow_channel_moderation` | Block a payment channel from accepting deposits |
191
+ | `unblock_payment_channel` | `payment` | `allow_channel_moderation` | Unblock a payment channel |
192
+ | `get_payment_channel_deposit` | `payment` | `default` | Retrieve a single payment channel deposit by `deposit_id` |
193
+ | `read_payment_channel_deposits` | `payment` | `default` | Read one page of the confirmed deposit feed with `next_cursor` |
194
+ | `create_refund` | `payment` | `allow_refunds` | Create a server-calculated `full` or `overpayment` invoice refund |
195
+ | `get_refund` | `payment` | `default` | Retrieve a refund by `refund_id` |
196
+ | `list_refunds` | `payment` | `default` | List refunds with optional RFC 3339 `created_from` / `created_to` |
197
+ | `get_balances` | `payout` | `default` | Retrieve available merchant balances per asset |
198
+ | `create_withdrawal` | `payout` | `allow_withdrawals` | Create an idempotent single-recipient payout |
199
+ | `get_withdrawal` | `payout` | `default` | Retrieve a withdrawal by `withdrawal_id` |
200
+ | `list_withdrawals` | `payout` | `default` | List withdrawals with cursor pagination and filters |
201
+ | `cancel_withdrawal` | `payout` | `allow_withdrawals` | Cancel a withdrawal with a 1–500 character reason |
202
+ | `simulate_invoice_payment` | `payment` | `sandbox` | Sandbox: simulate invoice outcome (`paid`, `overpaid`, `underpay`, `cancel`, `paid_late`) |
203
+ | `simulate_payment_channel_deposit` | `payment` | `sandbox` | Sandbox: simulate channel deposit (omit `stage` for default `confirmed`) |
204
+ | `simulate_refund` | `payment` | `sandbox` | Sandbox: simulate terminal refund status (`completed`, `failed`, `cancelled`) |
205
+ | `simulate_withdrawal_completion` | `payout` | `sandbox` | Sandbox: simulate withdrawal completion |
206
+
207
+ ## Documentation & Support
208
+
209
+ - Paymos Documentation: https://paymos.io/docs
210
+ - Python SDK: https://github.com/Paymos-labs/python-sdk
211
+ - Repository & Issues: https://github.com/Paymos-labs/paymos-langchain
212
+ - Support: support@paymos.io
213
+
214
+ ## License
215
+
216
+ MIT License — Copyright (c) 2026 Paymos Labs.
@@ -0,0 +1,185 @@
1
+ # paymos-langchain
2
+
3
+ Official Python AI agent tools and LangChain toolkit for the [Paymos](https://paymos.io) Merchant API, built on top of [`paymos-sdk`](https://github.com/Paymos-labs/python-sdk).
4
+
5
+ Give LangChain, LangGraph, OpenAI Agents, CrewAI, or custom Python tool loops safe, key-scoped access to Paymos invoices, static per-customer payment channels, deposit feeds, server-calculated refunds, balances, and payouts.
6
+
7
+ ## Why Paymos for AI Agents
8
+
9
+ - **Key-scope isolation (`pk_*` vs `rk_*`):** Paymos separates Payment API keys (`pk_live_*` / `pk_test_*`) from Payout API keys (`rk_live_*` / `rk_test_*`). `paymos-langchain` enforces the same boundary locally before any HTTP request is signed.
10
+ - **Least-privilege by default:** Money-moving and destructive actions (`create_withdrawal`, `cancel_withdrawal`, `create_refund`, `cancel_invoice`, `block_payment_channel`, `unblock_payment_channel`) are disabled unless explicitly opted in through `PaymosToolPermissions`.
11
+ - **Per-scope sandbox auto-detection:** Test keys (`pk_test_*` and `rk_test_*`) automatically unlock only the matching sandbox simulation tools. Live keys (`pk_live_*` and `rk_live_*`) expose zero simulation tools by default.
12
+ - **Secret redaction in tool errors:** `PaymosAgentTools` catches SDK errors and redacts configured `api_secret` values as well as `sk_*`, `rk_*`, `whsec_*`, `HMAC-SHA256`, and `Bearer` credentials before returning error text to an LLM.
13
+ - **Transparent Paymos economics:** Accept **USDT, USDC, USD1, DAI** (stablecoins) and **XAUT** (gold-backed asset) across **13 deposit networks** and **11 payout networks** (NEAR and Sui are deposit-only). Standard incoming processing fee is **1.0%** (configurable `0–100%` pass-through to the payer; **0.3%** Enterprise rate on request), with **0% Paymos withdrawal commission** (subsidized network fee only) and automated AML screening in Production. Withdrawal address whitelisting is **off by default** (opt-in by the merchant Owner; live API payouts use a Payout key IP allowlist while the whitelist is off).
14
+
15
+ ## Installation
16
+
17
+ Framework-agnostic install (OpenAI function calling, OpenAI Agents SDK, CrewAI, custom runtimes — zero LangChain dependency required):
18
+
19
+ ```bash
20
+ pip install paymos-langchain
21
+ ```
22
+
23
+ With LangChain `BaseToolkit` and `StructuredTool` support:
24
+
25
+ ```bash
26
+ pip install "paymos-langchain[langchain]"
27
+ ```
28
+
29
+ Requires Python 3.10+ and `paymos-sdk>=1.0.0`.
30
+
31
+ ## Quickstart
32
+
33
+ ### 1. LangChain (`PaymosToolkit`)
34
+
35
+ ```python
36
+ import os
37
+ from paymos import Paymos
38
+ from paymos_langchain import PaymosToolkit, PaymosToolPermissions
39
+
40
+ payment_client = Paymos(
41
+ api_key=os.environ["PAYMOS_PAYMENT_API_KEY"], # pk_live_... or pk_test_...
42
+ api_secret=os.environ["PAYMOS_PAYMENT_API_SECRET"],
43
+ )
44
+ payout_client = Paymos(
45
+ api_key=os.environ["PAYMOS_PAYOUT_API_KEY"], # rk_live_... or rk_test_...
46
+ api_secret=os.environ["PAYMOS_PAYOUT_API_SECRET"],
47
+ )
48
+
49
+ toolkit = PaymosToolkit(
50
+ payment_client=payment_client,
51
+ payout_client=payout_client,
52
+ permissions=PaymosToolPermissions(
53
+ allow_refunds=False,
54
+ allow_withdrawals=False,
55
+ allow_cancellations=False,
56
+ allow_channel_moderation=False,
57
+ ),
58
+ )
59
+
60
+ tools = toolkit.get_tools() # 15 safe default StructuredTool instances
61
+ ```
62
+
63
+ ### 2. Single-Key Setup (Payment-Only or Payout-Only)
64
+
65
+ Pass a single `client=` to automatically classify it by `client.api_key` prefix (`pk_*` -> Payment scope, `rk_*` -> Payout scope):
66
+
67
+ ```python
68
+ from paymos import Paymos
69
+ from paymos_langchain import PaymosAgentTools
70
+
71
+ payment_only = PaymosAgentTools(
72
+ client=Paymos("pk_live_...", "sk_live_..."),
73
+ )
74
+ # Exposes 12 safe Payment + shared tools (excludes balances and withdrawals)
75
+
76
+ payout_only = PaymosAgentTools(
77
+ client=Paymos("rk_live_...", "sk_live_..."),
78
+ )
79
+ # Exposes 4 safe Payout + shared tools:
80
+ # ["get_server_time", "get_balances", "get_withdrawal", "list_withdrawals"]
81
+ ```
82
+
83
+ If you use a custom non-prefixed key in tests, pass `key_scope="payment"` or `key_scope="payout"`.
84
+
85
+ ### 3. OpenAI Function Calling / Agents SDK
86
+
87
+ ```python
88
+ import json
89
+ from paymos import Paymos
90
+ from paymos_langchain import PaymosAgentTools
91
+
92
+ agent_tools = PaymosAgentTools(
93
+ payment_client=Paymos("pk_test_...", "sk_test_..."),
94
+ )
95
+
96
+ # OpenAI Chat Completions format:
97
+ chat_tools = agent_tools.to_openai_tools()
98
+
99
+ # OpenAI Responses API / Agents SDK flat format:
100
+ responses_tools = agent_tools.to_openai_responses_tools()
101
+
102
+ # Dispatch a model tool call (accepts dict or raw JSON string):
103
+ result = agent_tools.execute_tool(
104
+ "create_invoice",
105
+ {
106
+ "project_id": "prj_...",
107
+ "amount": "25.00",
108
+ "currency": "USD",
109
+ "external_order_id": "order_1001",
110
+ },
111
+ )
112
+ print(json.dumps(result))
113
+ ```
114
+
115
+ ### 4. Custom Adapter Seam (`tool_builder`)
116
+
117
+ `PaymosToolkit.get_tools(tool_builder=...)` lets you plug into CrewAI, AutoGen, or your own tool class without installing `langchain-core`:
118
+
119
+ ```python
120
+ custom_tools = toolkit.get_tools(
121
+ tool_builder=lambda spec, fn: {
122
+ "name": spec.name,
123
+ "description": spec.description,
124
+ "parameters": spec.parameters,
125
+ "run": fn,
126
+ }
127
+ )
128
+ ```
129
+
130
+ ## Security Model & Permissions
131
+
132
+ | `PaymosToolPermissions` flag | Default | Tools unlocked (when matching client is configured) |
133
+ |---|---|---|
134
+ | `allow_withdrawals` | `False` | `create_withdrawal`, `cancel_withdrawal` (requires `payout_client`) |
135
+ | `allow_refunds` | `False` | `create_refund` (requires `payment_client`) |
136
+ | `allow_cancellations` | `False` | `cancel_invoice` (requires `payment_client`) |
137
+ | `allow_channel_moderation` | `False` | `block_payment_channel`, `unblock_payment_channel` (requires `payment_client`) |
138
+ | `enable_sandbox_tools` | `None` (auto) | `pk_test_*` unlocks 3 payment simulators; `rk_test_*` unlocks `simulate_withdrawal_completion`; `pk_live_*`/`rk_live_*` unlock 0 |
139
+
140
+ ### Exceptions
141
+
142
+ - `ToolPermissionError` — raised with **0 network calls** when a tool is disabled by permissions, disabled in production, or outside the configured API key scope.
143
+ - `ToolValidationError` — raised with **0 network calls** when arguments fail schema validation (missing required fields, invalid enums, blank or `>500`-char `reason`, empty `stage=""`, or invalid RFC 3339 timestamps on `list_refunds`).
144
+ - `PaymosToolError` — base exception wrapping runtime SDK failures with `sanitize_error_message` replacing secrets with `[REDACTED]`.
145
+
146
+ ## Complete 25-Tool Reference
147
+
148
+ | Tool | Key Scope | Gate | Description |
149
+ |---|---|---|---|
150
+ | `get_server_time` | `shared` | `default` | Get Paymos API server Unix timestamp |
151
+ | `create_invoice` | `payment` | `default` | Create an invoice with optional `products[]` line items |
152
+ | `get_invoice` | `payment` | `default` | Retrieve an invoice by `invoice_id` |
153
+ | `list_invoices` | `payment` | `default` | List invoices with cursor pagination and filters |
154
+ | `confirm_invoice_payment` | `payment` | `default` | Lock currency and network on an invoice for Host-to-Host checkout |
155
+ | `cancel_invoice` | `payment` | `allow_cancellations` | Cancel an invoice with a 1–500 character reason |
156
+ | `create_payment_channel` | `payment` | `default` | Idempotently create or fetch a customer's static payment channel |
157
+ | `get_payment_channel` | `payment` | `default` | Retrieve a payment channel and its provisioned network addresses |
158
+ | `list_payment_channels` | `payment` | `default` | List payment channels with cursor pagination and filters |
159
+ | `block_payment_channel` | `payment` | `allow_channel_moderation` | Block a payment channel from accepting deposits |
160
+ | `unblock_payment_channel` | `payment` | `allow_channel_moderation` | Unblock a payment channel |
161
+ | `get_payment_channel_deposit` | `payment` | `default` | Retrieve a single payment channel deposit by `deposit_id` |
162
+ | `read_payment_channel_deposits` | `payment` | `default` | Read one page of the confirmed deposit feed with `next_cursor` |
163
+ | `create_refund` | `payment` | `allow_refunds` | Create a server-calculated `full` or `overpayment` invoice refund |
164
+ | `get_refund` | `payment` | `default` | Retrieve a refund by `refund_id` |
165
+ | `list_refunds` | `payment` | `default` | List refunds with optional RFC 3339 `created_from` / `created_to` |
166
+ | `get_balances` | `payout` | `default` | Retrieve available merchant balances per asset |
167
+ | `create_withdrawal` | `payout` | `allow_withdrawals` | Create an idempotent single-recipient payout |
168
+ | `get_withdrawal` | `payout` | `default` | Retrieve a withdrawal by `withdrawal_id` |
169
+ | `list_withdrawals` | `payout` | `default` | List withdrawals with cursor pagination and filters |
170
+ | `cancel_withdrawal` | `payout` | `allow_withdrawals` | Cancel a withdrawal with a 1–500 character reason |
171
+ | `simulate_invoice_payment` | `payment` | `sandbox` | Sandbox: simulate invoice outcome (`paid`, `overpaid`, `underpay`, `cancel`, `paid_late`) |
172
+ | `simulate_payment_channel_deposit` | `payment` | `sandbox` | Sandbox: simulate channel deposit (omit `stage` for default `confirmed`) |
173
+ | `simulate_refund` | `payment` | `sandbox` | Sandbox: simulate terminal refund status (`completed`, `failed`, `cancelled`) |
174
+ | `simulate_withdrawal_completion` | `payout` | `sandbox` | Sandbox: simulate withdrawal completion |
175
+
176
+ ## Documentation & Support
177
+
178
+ - Paymos Documentation: https://paymos.io/docs
179
+ - Python SDK: https://github.com/Paymos-labs/python-sdk
180
+ - Repository & Issues: https://github.com/Paymos-labs/paymos-langchain
181
+ - Support: support@paymos.io
182
+
183
+ ## License
184
+
185
+ MIT License — Copyright (c) 2026 Paymos Labs.
@@ -0,0 +1,71 @@
1
+ [build-system]
2
+ requires = ["hatchling==1.31.0"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "paymos-langchain"
7
+ version = "1.0.0"
8
+ description = "Official Paymos AI agent tools and LangChain toolkit for stablecoin payments, channels, refunds, and payouts"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = ["paymos-sdk>=1.0.0"]
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ authors = [{ name = "Paymos Labs", email = "support@paymos.io" }]
15
+ keywords = [
16
+ "paymos",
17
+ "langchain",
18
+ "ai-agents",
19
+ "openai-agents",
20
+ "crewai",
21
+ "payments",
22
+ "stablecoins",
23
+ "usdt",
24
+ "usdc",
25
+ ]
26
+ classifiers = [
27
+ "Development Status :: 5 - Production/Stable",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.10",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Programming Language :: Python :: 3.13",
34
+ "Typing :: Typed",
35
+ ]
36
+
37
+ [project.optional-dependencies]
38
+ langchain = [
39
+ "langchain-core>=0.3.0",
40
+ "pydantic>=2.0.0",
41
+ ]
42
+ dev = [
43
+ "build>=1.2.2",
44
+ "mypy>=1.14.0",
45
+ "ruff>=0.9.0",
46
+ ]
47
+
48
+ [project.urls]
49
+ Homepage = "https://paymos.io"
50
+ Documentation = "https://paymos.io/docs"
51
+ Repository = "https://github.com/Paymos-labs/paymos-langchain"
52
+ Issues = "https://github.com/Paymos-labs/paymos-langchain/issues"
53
+
54
+ [tool.hatch.build.targets.wheel]
55
+ packages = ["src/paymos_langchain"]
56
+
57
+ [tool.mypy]
58
+ python_version = "3.10"
59
+ strict = true
60
+ packages = ["paymos_langchain"]
61
+
62
+ [[tool.mypy.overrides]]
63
+ module = ["langchain_core.*", "pydantic.*"]
64
+ ignore_missing_imports = true
65
+
66
+ [tool.ruff]
67
+ line-length = 120
68
+ target-version = "py310"
69
+
70
+ [tool.ruff.lint]
71
+ select = ["E4", "E7", "E9", "F", "I", "UP", "B"]
@@ -0,0 +1,46 @@
1
+ from __future__ import annotations
2
+
3
+ from .errors import (
4
+ REDACTED,
5
+ PaymosToolError,
6
+ ToolPermissionError,
7
+ ToolValidationError,
8
+ sanitize_error_message,
9
+ )
10
+ from .schemas import ALL_TOOL_NAMES, TOOL_SCHEMAS, get_tool_schema, validate_arguments
11
+ from .toolkit import PaymosToolkit, ToolBuilder
12
+ from .tools import (
13
+ KeyScope,
14
+ PaymosAgentTools,
15
+ PaymosClientLike,
16
+ PaymosToolPermissions,
17
+ PaymosToolSpec,
18
+ ToolGate,
19
+ ToolScope,
20
+ )
21
+
22
+ __version__ = "1.0.0"
23
+ VERSION = __version__
24
+
25
+ __all__ = [
26
+ "ALL_TOOL_NAMES",
27
+ "KeyScope",
28
+ "PaymosAgentTools",
29
+ "PaymosClientLike",
30
+ "PaymosToolError",
31
+ "PaymosToolPermissions",
32
+ "PaymosToolSpec",
33
+ "PaymosToolkit",
34
+ "REDACTED",
35
+ "TOOL_SCHEMAS",
36
+ "ToolBuilder",
37
+ "ToolGate",
38
+ "ToolPermissionError",
39
+ "ToolScope",
40
+ "ToolValidationError",
41
+ "VERSION",
42
+ "__version__",
43
+ "get_tool_schema",
44
+ "sanitize_error_message",
45
+ "validate_arguments",
46
+ ]