Metadata-Version: 2.4
Name: langchain-paypack
Version: 0.7.5
Summary: 让 AI Agent 自己收钱：一行代码集成支付宝/微信/USDC/ETH 支付。支持 LangChain Agent、x402 协议、AP2 协议。
Project-URL: Homepage, https://github.com/rhcjw/paypack
Author: 荣华
License: Apache-2.0
Keywords: agent-pay,agent收款,ai支付,alipay,ap2,base,dify,langchain,usdc,wechat,x402
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27.0
Requires-Dist: langchain-core>=0.3.0
Requires-Dist: paypack>=0.7.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: web3<8.0.0,>=6.0.0
Description-Content-Type: text/markdown

# langchain-paypack / paypack-langchain

> AI Agent Payment — One line of code. Alipay · WeChat Pay · USDC · ETH.

---

## 📦 安装 / Installation

```bash
pip install langchain-paypack
# or
pip install paypack-langchain
```

要求 Python 3.10+ | Requires Python 3.10+

---

## 中文文档

### 🚀 三步接入

**第一步：获取 API Key**

```bash
curl -X POST https://rhcjw.com/pay/v1/register \
  -H "Content-Type: application/json" \
  -d '{"name": "你的项目名"}'
```

返回：
```json
{"api_key": "ppk_你的API_KEY"}
```

**第二步：创建一笔支付**

```python
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，扫码支付
```

**第三步：查询支付结果**

```python
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 中使用

```python
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**

```bash
curl -X POST https://rhcjw.com/pay/v1/register \
  -H "Content-Type: application/json" \
  -d '{"name": "my_project"}'
```

Returns:
```json
{"api_key": "ppk_your_api_key"}
```

**Step 2: Create a payment**

```python
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**

```python
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

```python
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
