Metadata-Version: 2.4
Name: paypack-langchain
Version: 0.1.8
Summary: One line of code. Three currencies. Alipay · WeChat Pay · USDC · ETH. Auto-routed by currency — one PayPackTool, three settlement networks. Featured use case: Zhihui Trading Terminal (production quant trading platform).
Project-URL: Homepage, https://github.com/yourname/paypack
Author: PayPack
License: MIT
Keywords: agent-pay,agent收款,ai支付,alipay,ap2,base,dify,langchain,paypack,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

# paypack-langchain

> One line of code. Three currencies. Alipay · WeChat Pay · USDC · ETH.

```bash
pip install paypack-langchain
```

```python
from paypack_langchain import PayPackTool

tool = PayPackTool(api_key="ppk_...", base_url="https://rhcjw.com/pay")
result = tool.run(amount=0.01, subject="AI data query")
# → Order created, ¥0.01, scan to pay
```

---

## 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"}'
# → {"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"  # PayPack Cloud
)
result = tool.run(amount=0.01, subject="AI data query")
print(result)
```

**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"))
# → {"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 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, call pay_for_data first."
)
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** | PayPack Cloud | Alipay | `currency="CNY"` |
| **CNY** | PayPack Cloud | WeChat Pay | `currency="CNY"` |
| **USDC** | On-chain (local sign) | Base / Ethereum / Polygon / Arbitrum | `currency="USDC", to="0x..."` |
| **ETH** | On-chain (local sign) | Base / Ethereum / Polygon / Arbitrum | `currency="ETH", to="0x..."` |

Auto-routed by `currency` parameter — one tool, three currencies.

---

## Featured Use Case: 志辉交易系统 (Zhihui Trading Terminal)

[志辉交易系统](https://rhcjw.com) is a live quantitative trading platform that uses PayPack as its native payment layer:

- **AI strategy agents** autonomously pay for market data API calls
- **Contest participants** subscribe to backtesting engine time via WeChat/Alipay
- **Risk management alerts** trigger on-chain USDC settlements

This is not a toy demo — it's a production trading system processing real CNY and USDC payments every day.

> 👉 See it in action: [https://rhcjw.com/pay](https://rhcjw.com/pay)

---

## API Reference

### PayPackTool (Create Payment)

| 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 `PRIVATE_KEY` env var |
| `network` | string | optional | Default `base-sepolia`. Options: `base-mainnet`, `base-sepolia`, `ethereum-mainnet`, `ethereum-sepolia`, `polygon-mainnet`, `arbitrum-mainnet` |
| `broadcast` | bool | no | `True` = broadcast to chain, `False` = dry-run sign only |
| `amount` | float | **yes** | Amount (CNY in yuan, USDC/ETH in token units) |
| `subject` | string | **yes** | Description shown on payment page |
| `currency` | string | no | `CNY` (default) / `USDC` / `ETH` |
| `to` | string | for USDC/ETH | Recipient wallet address `0x...` |
| `callback_url` | string | no | Webhook for payment result notification |

### PayPackQueryTool (Check Payment)

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| `api_key` | string | yes | API Key |
| `base_url` | string | yes | `https://rhcjw.com/pay` |
| `order_id` | string | yes | Order ID from `PayPackTool` response |

---

## Links

- **Live demo**: [https://rhcjw.com/pay](https://rhcjw.com/pay)
- **GitHub**: [https://github.com/rhcjw/paypack](https://github.com/rhcjw/paypack)
- **Issues**: [https://github.com/rhcjw/paypack/issues](https://github.com/rhcjw/paypack/issues)

---

*Legacy users: the old `langchain-paypack` package is deprecated. Migrate to `paypack-langchain` for the latest features.*
