langchain-paypack: x402 (Coinbase) + AP2 (Google) dual-protocol Agent payments. One agent.pay() for USDC/ETH on-chain (Base/Ethereum/Polygon/Arbitrum) + Alipay/WeChat CNY via Cloud. Auto-routes by currency. Dify Tool Plugin available.
Project description
langchain-paypack: x402 + AP2 dual-protocol for LangChain Agents
🌐 Dual-channel · Neutral — the only Agent payment middleware supporting Alipay + WeChat Pay.
x402 (Coinbase) + AP2 (Google) dual-protocol. One agent.pay() for USDC/ETH across Base/Ethereum/Polygon/Arbitrum, plus Alipay/WeChat CNY. Dify Tool Plugin also available.
Installation
pip install paypack-langchain
Requires Python 3.10+.
Quick Start
1. Get your API Key
curl -X POST https://rhcjw.com/pay/v1/register \
-H "Content-Type: application/json" \
-d '{"name": "my_agent", "email": "your@email.com"}'
Returns:
{"api_key": "ppk_your_api_key_here"}
Save this key — you'll use it in every call.
2. Create a payment in 3 lines
from paypack_langchain import PayPackTool
tool = PayPackTool(
api_key="ppk_your_api_key_here",
base_url="https://rhcjw.com/pay",
)
result = tool.run(amount=0.01, subject="AI data query")
print(result)
Output:
支付订单已创建
订单号: PP20260710120000ABC12345
金额: ¥0.01
状态: pending
支付链接: https://openapi.alipay.com/...
二维码: https://...
3. Verify it worked
Check order status:
from paypack_langchain import PayPackQueryTool
query = PayPackQueryTool(
api_key="ppk_your_api_key_here",
base_url="https://rhcjw.com/pay",
)
print(query.run(order_id="PP20260710120000ABC12345"))
Use in a LangChain Agent
from langchain.agents import create_react_agent, AgentExecutor
from langchain_openai import ChatOpenAI
from paypack_langchain import PayPackTool, PayPackQueryTool
llm = ChatOpenAI(model="gpt-4")
tools = [
PayPackTool(api_key="ppk_xxx", base_url="https://rhcjw.com/pay"),
PayPackQueryTool(api_key="ppk_xxx", base_url="https://rhcjw.com/pay"),
]
agent = create_react_agent(llm, tools, ...)
agent_executor = AgentExecutor(agent=agent, tools=tools)
# Agent now handles payments and order queries automatically
When your Agent calls a metered API and receives an HTTP 402 response, it can use PayPackTool to settle the payment and retry the request — fully autonomous.
Supported Currencies & Routing
| Currency | Route | Networks | Status |
|---|---|---|---|
| CNY | PayPack Cloud API | Alipay / WeChat Pay | ✅ Production (¥0.10 / ¥0.05 verified) |
| USDC | On-chain (local signer) | Base / Ethereum / Polygon / Arbitrum | ✅ Live |
| ETH | On-chain (local signer) | Base / Ethereum / Polygon / Arbitrum | ✅ Live |
Auto-routed by currency parameter — one tool, three currencies.
API Reference
PayPackTool
| Parameter | Type | Required | Description |
|---|---|---|---|
api_key |
string | for CNY | PayPack Cloud API key (ppk_...) |
base_url |
string | for CNY | PayPack Cloud endpoint: https://rhcjw.com/pay |
private_key |
string | for USDC/ETH | Wallet private key (0x...) or set PRIVATE_KEY env |
network |
string | for USDC/ETH | Blockchain: base-sepolia (default), base-mainnet, ethereum-mainnet, polygon-mainnet, arbitrum-mainnet |
broadcast |
bool | ❌ | True to broadcast to chain, False (default) to dry-run sign only |
amount |
float | ✅ | Payment amount (e.g. 0.01 for ¥0.01 or 0.01 USDC) |
subject |
string | ✅ | Description shown on payment page |
currency |
string | ❌ | CNY (default, via Cloud), USDC or ETH (on-chain) |
to |
string | for USDC/ETH | Recipient wallet address (0x...), required for on-chain |
callback_url |
string | ❌ | Webhook URL for payment notification (Cloud mode) |
PayPackQueryTool
| Parameter | Type | Required | Description |
|---|---|---|---|
api_key |
string | ✅ | Your PayPack Cloud API key |
base_url |
string | ✅ | PayPack Cloud endpoint |
order_id |
string | ✅ | Order ID from PayPackTool response |
Links
- Cloud API: https://rhcjw.com/pay
- PyPI: https://pypi.org/project/paypack-langchain/
- GitHub: https://github.com/rhcjw/paypack
- Dify Plugin: PR #2693 (in review)
- Issues: https://github.com/rhcjw/paypack/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file paypack_langchain-0.1.5.tar.gz.
File metadata
- Download URL: paypack_langchain-0.1.5.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53e15da09fef714852bcea7f336411c91864bb4881d8c6277bc441e23f36b29a
|
|
| MD5 |
232cf83a5598ea3514291facf4c1a552
|
|
| BLAKE2b-256 |
41162ee115a85491c02a7695287520c01937a45a1eb1dfa53c86f8d0c7a24120
|
File details
Details for the file paypack_langchain-0.1.5-py3-none-any.whl.
File metadata
- Download URL: paypack_langchain-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3051f61648392bd88fd16bb617796cf274b43146c86ca9f6da93d53fb1c113e5
|
|
| MD5 |
a846e91801d3f02f092bd5cc2e826948
|
|
| BLAKE2b-256 |
0f7fca0b9ae7a03117eeec7ce81994d85d45ff99a383ddd3962a291cdadd0e70
|