让 AI Agent 自己收钱:一行代码集成支付宝/微信/USDC/ETH 支付。支持 LangChain Agent、x402 协议、AP2 协议。
Project description
langchain-paypack / paypack-langchain
AI Agent Payment — One line of code. Alipay · WeChat Pay · USDC · ETH.
📦 安装 / Installation
pip install langchain-paypack
# or
pip install paypack-langchain
要求 Python 3.10+ | Requires Python 3.10+
中文文档
🚀 三步接入
第一步:获取 API Key
curl -X POST https://rhcjw.com/pay/v1/register \
-H "Content-Type: application/json" \
-d '{"name": "你的项目名"}'
返回:
{"api_key": "ppk_你的API_KEY"}
第二步:创建一笔支付
from paypack_langchain import PayPackTool
tool = PayPackTool(
api_key="ppk_你的API_KEY",
base_url="https://rhcjw.com/pay"
)
result = tool.run(amount=0.01, subject="AI 数据查询")
print(result)
# 输出:订单已创建,金额 ¥0.01,扫码支付
第三步:查询支付结果
from paypack_langchain import PayPackQueryTool
query = PayPackQueryTool(api_key="ppk_你的API_KEY", base_url="https://rhcjw.com/pay")
print(query.run(order_id="PP2026071400ABC123"))
# 输出:{"status": "success", "amount": 0.01}
🧠 在 LangChain Agent 中使用
from langchain.agents import create_react_agent, AgentExecutor
from langchain_openai import ChatOpenAI
from langchain_core.tools import Tool
from paypack_langchain import PayPackTool
pay_tool = PayPackTool(api_key="ppk_你的API_KEY", base_url="https://rhcjw.com/pay")
tools = [
Tool(
name="pay_for_data",
func=lambda q: pay_tool.run(amount=0.01, subject=q),
description="用户需要付费数据时调用,返回支付二维码"
)
]
llm = ChatOpenAI(model="gpt-4")
agent = create_react_agent(llm, tools, prompt="你是一个数据查询助手。付费数据先调用 pay_for_data 生成支付。")
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
result = executor.invoke({"input": "查最新市场数据"})
print(result)
💰 支持的币种
| 币种 | 路由 | 网络 | 示例 |
|---|---|---|---|
| CNY | Cloud API | 支付宝 / 微信支付 | currency="CNY" |
| USDC | 链上签名 | Base / Ethereum / Polygon / Arbitrum | currency="USDC", to="0x..." |
| ETH | 链上签名 | Base / Ethereum / Polygon / Arbitrum | currency="ETH", to="0x..." |
📖 API 参考
PayPackTool(创建支付)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
api_key |
string | CNY 必填 | API Key (ppk_...) |
base_url |
string | CNY 必填 | https://rhcjw.com/pay |
private_key |
string | USDC/ETH 必填 | 钱包私钥或环境变量 PRIVATE_KEY |
network |
string | 可选 | 默认 base-sepolia |
broadcast |
bool | 否 | True=上链,False=仅签名 |
amount |
float | 是 | 金额(CNY=元,USDC/ETH=币数量) |
subject |
string | 是 | 商品描述 |
currency |
string | 否 | CNY(默认) / USDC / ETH |
to |
string | USDC/ETH 必填 | 收款地址 0x... |
callback_url |
string | 否 | 回调地址 |
PayPackQueryTool(查询支付)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
api_key |
string | 是 | API Key |
base_url |
string | 是 | https://rhcjw.com/pay |
order_id |
string | 是 | 订单号 |
🔗 链接
- 在线体验: https://rhcjw.com/pay
- GitHub: https://github.com/rhcjw/paypack
- 问题反馈: https://github.com/rhcjw/paypack/issues
English Documentation
🚀 Quick Start
Step 1: Get API Key
curl -X POST https://rhcjw.com/pay/v1/register \
-H "Content-Type: application/json" \
-d '{"name": "my_project"}'
Returns:
{"api_key": "ppk_your_api_key"}
Step 2: Create a payment
from paypack_langchain import PayPackTool
tool = PayPackTool(
api_key="ppk_your_api_key",
base_url="https://rhcjw.com/pay"
)
result = tool.run(amount=0.01, subject="AI data query")
print(result)
# Output: Order created, ¥0.01, scan to pay
Step 3: Check payment status
from paypack_langchain import PayPackQueryTool
query = PayPackQueryTool(api_key="ppk_your_api_key", base_url="https://rhcjw.com/pay")
print(query.run(order_id="PP2026071400ABC123"))
# Output: {"status": "success", "amount": 0.01}
🧠 Use with LangChain Agent
from langchain.agents import create_react_agent, AgentExecutor
from langchain_openai import ChatOpenAI
from langchain_core.tools import Tool
from paypack_langchain import PayPackTool
pay_tool = PayPackTool(api_key="ppk_your_api_key", base_url="https://rhcjw.com/pay")
tools = [
Tool(
name="pay_for_data",
func=lambda q: pay_tool.run(amount=0.01, subject=q),
description="Call this when user needs paid data. Returns payment QR code."
)
]
llm = ChatOpenAI(model="gpt-4")
agent = create_react_agent(llm, tools, prompt="You are a data assistant. For paid data, first call pay_for_data.")
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
result = executor.invoke({"input": "Get latest market data"})
print(result)
💰 Supported Currencies
| Currency | Route | Networks | Example |
|---|---|---|---|
| CNY | Cloud API | Alipay / WeChat Pay | currency="CNY" |
| USDC | On-chain | Base / Ethereum / Polygon / Arbitrum | currency="USDC", to="0x..." |
| ETH | On-chain | Base / Ethereum / Polygon / Arbitrum | currency="ETH", to="0x..." |
📖 API Reference
PayPackTool
| Param | Type | Required | Description |
|---|---|---|---|
api_key |
string | for CNY | API Key (ppk_...) |
base_url |
string | for CNY | https://rhcjw.com/pay |
private_key |
string | for USDC/ETH | Wallet private key or env PRIVATE_KEY |
network |
string | optional | Default base-sepolia |
broadcast |
bool | no | True=broadcast, False=dry-run |
amount |
float | yes | Amount in CNY/USDC/ETH |
subject |
string | yes | Description |
currency |
string | no | CNY(default) / USDC / ETH |
to |
string | for USDC/ETH | Recipient 0x... |
callback_url |
string | no | Webhook URL |
PayPackQueryTool
| Param | Type | Required | Description |
|---|---|---|---|
api_key |
string | yes | API Key |
base_url |
string | yes | https://rhcjw.com/pay |
order_id |
string | yes | Order ID |
🔗 Links
- Try it live: https://rhcjw.com/pay
- GitHub: https://github.com/rhcjw/paypack
- 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 langchain_paypack-0.7.5.tar.gz.
File metadata
- Download URL: langchain_paypack-0.7.5.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa9371e3af15b51077e0122cf6c2e45bd5ec762753953ab01e203fc09caa1805
|
|
| MD5 |
d1c8a752ff6e395fa6c420d4eb21af1b
|
|
| BLAKE2b-256 |
ad69758e95a764b93fc822b60d015d030ad25a294c067bff6d2f5849919a7a11
|
File details
Details for the file langchain_paypack-0.7.5-py3-none-any.whl.
File metadata
- Download URL: langchain_paypack-0.7.5-py3-none-any.whl
- Upload date:
- Size: 6.0 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 |
5a6ae486e48b4a0ba43c0178318c193aedb90fc72d52ed540d19575da271f7fb
|
|
| MD5 |
896d1bc4e631f7a9ffbe7380bc76bafb
|
|
| BLAKE2b-256 |
f8e26a9e1e1e745e243f873b4b2fffa17fbf7cf2ffd1a5588b18cf8996905ee6
|