Skip to main content

让 AI Agent 自己收钱:一行代码集成支付宝/微信/USDC/ETH 支付。支持 LangChain Agent、x402 协议、AP2 协议。Auto-routes by currency.

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 订单号

🔗 链接


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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paypack_langchain-0.1.7.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paypack_langchain-0.1.7-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file paypack_langchain-0.1.7.tar.gz.

File metadata

  • Download URL: paypack_langchain-0.1.7.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

Hashes for paypack_langchain-0.1.7.tar.gz
Algorithm Hash digest
SHA256 3b2601f7fdb1cbe28df5d91710a5576e61ed529ef382d223d599c654585bd1d5
MD5 cfbd1f27247a4c0ddb5a496d83cebd4b
BLAKE2b-256 8c1b8e768a3699bbb66013ce607134f1f09b76a490caefd8475f73aade3c0077

See more details on using hashes here.

File details

Details for the file paypack_langchain-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for paypack_langchain-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c2a982eca73bb472a16aac8b824af482458e9a90cf3a963cc3b2e57ee2a66e5d
MD5 9f66578b311c697b70e90885395e4054
BLAKE2b-256 d0ba0b109a244573f4db38ea457d98f0976b49d314e997a06f0185ce7dd77b98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page