Metadata-Version: 2.4
Name: langchain-paypack
Version: 0.7.3
Summary: LangChain tool for PayPack: AI Agent autonomous payments (HTTP 402, x402, AP2)
Home-page: https://github.com/rhcjw/paypack
Author: ronghua
Author-email: 2283794147@qq.com
License: Apache-2.0
Project-URL: Source, https://github.com/rhcjw/paypack
Project-URL: Tracker, https://github.com/rhcjw/paypack/issues
Project-URL: Gitee Mirror, https://gitee.com/rhcjw_com/paypack
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Intended Audience :: Developers
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: langchain-core<0.3.0,>=0.1.0
Requires-Dist: web3<7.0.0,>=6.0.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

> ⚠️ **This package is legacy (local-signer mode).** For Cloud mode: **[paypack-langchain](https://pypi.org/project/paypack-langchain/) · PyPI** — `pip install paypack-langchain`
>
> 此包为旧版（本地签名模式）。Cloud 版请使用 `paypack-langchain`。

# langchain-paypack: 让 AI Agent 拥有支付能力

**专为 AI Agent 设计的通用支付中间件。一行代码接入支付宝、微信支付及加密货币网络，打破生态壁垒，让 AI 自主完成跨平台交易。**

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
[![Python](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/)
[![LangChain](https://img.shields.io/badge/LangChain-Integration-green.svg)](https://python.langchain.com/)
[![PyPI](https://img.shields.io/pypi/v/langchain-paypack.svg)](https://pypi.org/project/langchain-paypack/)
[![Gitee](https://img.shields.io/badge/Gitee-Mirror-red.svg)](https://gitee.com/rhcjw_com/paypack)

---

## 为什么是 PayPack？| Why PayPack?

**PayPack is the ONLY payment middleware that supports x402/AP2 crypto payments AND Alipay/WeChat fiat payments.**
**PayPack 是唯一同时支持 x402/AP2 链上支付和支付宝/微信法币支付的 AI 支付中间件。**

| Tool | Payment Method | Supports China Users? |
| 工具 | 支付方式 | 支持中国用户？ |
|------|---------|---------------------|
| **Ampersend** | x402 + USDC | ❌ No Alipay/WeChat |
| **GOAT** | Crypto | ❌ No Alipay/WeChat |
| **Stripe Agent Toolkit** | Stripe (credit card) | ❌ Foreign cards only |
| **Nevermined** | x402 protocol | ❌ No Alipay/WeChat |
| **Privy** | Wallet infra | ❌ No Alipay/WeChat |
| **PayPack** ✅ | x402/AP2 + USDC/ETH + **Alipay** + **WeChat Pay** | ✅ Open-source & free |
| **PayPack Cloud** ☁️ | **Managed payment API — Alipay + WeChat Pay** | ✅ Live at [rhcjw.com/pay](https://rhcjw.com/pay) |

While everyone asks "how does AI pay with USDC?", PayPack asks "how does AI pay with Alipay and WeChat?".
当所有人在琢磨"怎么让 AI 用 USDC 付钱"时，PayPack 在想"怎么让 AI 用支付宝和微信付钱"。

1.3 billion people in China use Alipay and WeChat — not USDC. **Only PayPack serves this market.**
国内 13 亿人用支付宝和微信，不用 USDC。**这个市场，只有 PayPack 在做。**

---

## Quick Start | 快速开始

### On-Chain Payment (ETH / USDC) | 链上支付

```python
from paypack import AgentPay

pay = AgentPay(
    wallet_config={"private_key": "your-key"},
    network="base-sepolia",
    spend_limit_daily=10.0,
)

# AI auto-handles HTTP 402 payment requests | AI 自动处理 HTTP 402 支付要求
import requests
response = requests.get("https://api.data-provider.com/premium")
if response.status_code == 402:
    content = pay.auto_handle_402(response)

# Or send payment directly | 或直接发送支付
receipt = pay.send(to="0xRecipientAddress", amount=0.001, currency="USDC")
print(receipt["tx_hash"])
```

### Alipay (CNY) | 支付宝支付（人民币）🏦

```python
from paypack.signer.alipay import AlipaySigner
from paypack import AgentPay

# Two lines to integrate Alipay | 两行代码接入支付宝
signer = AlipaySigner(app_id="your APPID", private_key_path="key.pem",
                       alipay_public_key_path="alipay_public_key.pem", sandbox=True)
pay = AgentPay(signer=signer, network="alipay")

# AI pays in yuan | AI 直接付人民币
receipt = pay.send(to="user_alipay_id", amount=0.01, currency="CNY",
                   subject="AI Data Subscription | AI 数据订阅费")
```

```python
# Web payment — generates cashier URL, user scans QR to pay | 电脑网站支付 — 生成收银台链接，用户扫码即付
pay_url = signer.page_pay(
    out_trade_no="ORDER_20260709_001",
    total_amount=9.90,
    subject="AI Agent API Monthly Fee | AI Agent API 调用月费",
    body="Auto-generated by PayPack | PayPack 自动生成的支付订单"
)
# User opens pay_url to complete payment | 用户打开 pay_url 即可扫码支付
```

### WeChat Pay (CNY) | 微信支付（人民币）💚

```python
# paypack_wechat is a commercial module, requires License Key
# paypack_wechat 为商业模块，需要 License Key
# Source includes a template: paypack_wechat_run.example.py | 开源代码包里包含示例模板
from paypack_wechat import WechatSigner
from paypack import AgentPay

signer = WechatSigner(
    mchid="Merchant ID | 商户号",
    serial_no="Certificate S/N | 证书序列号",
    private_key_path="apiclient_key.pem",
    api_v3_key="APIv3 Key | APIv3密钥",
    license_key="PAYPACK-WECHAT-v1-...",
    app_id="Mini Program AppID | 小程序AppID",
    notify_url="https://your-domain.com/wechat/notify",
)
pay = AgentPay(signer=signer, network="wechat")

# AI initiates WeChat Pay → frontend calls wx.requestPayment()
# AI 发起微信支付 → 前端调起 wx.requestPayment()
result = pay.send(
    to="User OpenID | 用户openid",
    amount=9.90,
    currency="CNY",
    subject="AI Monthly Subscription | AI 服务月费",
    app_id="Mini Program AppID | 小程序AppID",
)
# result["prepay_params"] passes directly to frontend | 直接传给前端调起支付
```

### PayPack Cloud | 云托管服务 ☁️

不想自己管理密钥和商户号？直接用 PayPack Cloud API：

```bash
# 注册获取 API Key
curl -X POST https://rhcjw.com/pay/v1/register \
  -H "Content-Type: application/json" \
  -d '{"name": "myapp", "email": "user@example.com"}'

# 创建支付宝支付
curl -X POST https://rhcjw.com/pay/v1/pay \
  -H "Authorization: Bearer ppk_xxx" \
  -d '{"amount": 0.01, "subject": "AI 服务", "channel": "alipay"}'

# 创建微信支付
curl -X POST https://rhcjw.com/pay/v1/pay \
  -H "Authorization: Bearer ppk_xxx" \
  -d '{"amount": 0.01, "subject": "AI 服务", "channel": "wechat"}'
```

### LangChain Integration | LangChain 集成

```python
from langchain_paypack import PayPackTool

tool = PayPackTool(
    private_key="0x...",
    wallet_address="0x...",
    network="base-sepolia",
    spend_limit_daily=10.0,
)

# AI Agent calls directly | AI Agent 直接调用
result = tool._run(to="0x...", amount=0.001, currency="USDC")
```

> 💡 Compare: integrating Alipay yourself means hundreds of pages of docs, hundreds of lines of code, sandbox/RSA2 signing/verify/callbacks. PayPack: two lines.
> 💡 对比：自己对接支付宝要读几百页文档、写几百行代码、处理沙箱/RSA2签名/验签/回调。PayPack 两行搞定。

### Dify Plugin | Dify 插件

```bash
# In Dify: Plugins → Install from GitHub | 在 Dify 中：插件 → 从 GitHub 安装
# Enter: https://github.com/rhcjw/paypack
```

Or download [paypack-0.1.2.difypkg](https://github.com/rhcjw/paypack/releases/tag/v0.1.2) and upload locally. | 或下载直接上传。

> See [QUICKSTART.md](./QUICKSTART.md) — 5-minute tutorial covering all three channels. | 详见 QUICKSTART.md — 5 分钟三路教程。

---

## Current Status | 当前状态

| Channel | Sandbox/Test | Production | Fully Auto? |
| 通道 | 沙箱/测试 | 生产 | 全自动？ |
|---------|-------------|------------|-------------|
| **ETH / USDC** (Base/Ethereum/Polygon/Arbitrum) | ✅ Verified | ✅ Live | ✅ Yes |
| **Alipay CNY** | ✅ Sandbox OK | ✅ **Production Verified** (¥0.10 paid + refunded) | ⚠️ User scans QR |
| **WeChat Pay CNY** | ✅ Backend OK | ✅ **Production Verified** (¥0.05 paid) | ⚠️ User scans QR |
| **PayPack Cloud** ☁️ | — | ✅ **Live** at [rhcjw.com/pay](https://rhcjw.com/pay) | ✅ API Key auth |

---

## Architecture | 架构

```text
       AI Agent Application
                │
                ▼
         PayPack SDK  ◄── You are here 你在这里
                │
        ┌───────┼───────┐
        │       │       │
  Protocol   Payment   Security
   Parser    Router    Fuse
  (x402/    (USDC/    (Limits/
   AP2)     CNY)       Audit)
        │       │       │
        └───────┼───────┘
                │
                ▼
    Settlement Networks
  (Base / Alipay / WeChat / More...)
```

PayPack doesn't invent new protocols. It wraps scattered capabilities into a single `agent.pay()`.
PayPack 不发明新协议，而是把零散的能力封装成一个 `agent.pay()`。

---

## Features | 功能

- **Multi-Protocol | 多协议**: x402 + AP2 auto-detect and route | 自动检测和路由
- **3-Channel | 三通道**: USDC/ETH on-chain + Alipay CNY + WeChat Pay CNY
- **Cloud API | 云托管**: No key management needed, pay-as-you-go | 无需管理密钥，按次计费
- **Signer Abstraction | 签名器抽象**: LocalSigner (dev) / AWSKMSSigner (prod, key never leaves HSM)
- **Nano-Payment | 纳米支付**: ERC-4337 batch settlement, saves gas | 批量结算省 Gas
- **Safety Fuse | 安全熔断**: Daily spend limit, balance check, auditable receipts | 日限额、余额检查、可审计收据
- **RPC Failover | RPC 故障转移**: Multi-node auto-switch (v0.5) | 多节点自动切换
- **Tx Retry | 交易重试**: RBF + exponential backoff (v0.5) | RBF + 指数退避
- **Limit Persistence | 限额持久化**: Redis / SQLite / Memory (v0.5)
- **LangChain Native | LangChain 原生**: `PayPackTool` plug-and-play | 即插即用
- **Dify Plugin | Dify 插件**: [v0.1.2](https://github.com/rhcjw/paypack/releases/tag/v0.1.2) — pay/query/refund tools

---

## Supported Networks | 支持网络

| Network | Chain ID | Currency | 币种 |
|---------|----------|----------|------|
| Base Sepolia (testnet) | 84532 | ETH, USDC |
| Base Mainnet | 8453 | ETH, USDC |
| Ethereum Mainnet | 1 | ETH, USDC |
| Polygon Mainnet | 137 | POL, USDC |
| Arbitrum Mainnet | 42161 | ETH, USDC |
| **Alipay Sandbox | 支付宝沙箱** | — | **CNY** |
| **Alipay Production ✅ | 支付宝生产** | — | **CNY** (¥0.10 verified) |
| **WeChat Pay ✅ | 微信支付** | — | **CNY** (¥0.05 verified) |
| **PayPack Cloud ☁️** | — | **CNY** | Live |

---

## Installation | 安装

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

Or from Gitee (faster in China) | 或从 Gitee 安装（国内更快）：

```bash
pip install https://gitee.com/rhcjw_com/paypack/raw/master/dist/langchain_paypack-0.5.0-py3-none-any.whl
```

---

## Verified Transactions | 已验证交易

| Currency | Amount | Transaction | 交易凭证 |
|----------|--------|-------------|---------|
| ETH | 0.0001 ETH | `d5f7ec94342c26a132289a9898ffd4885010089d1ddba19951117618a3992127` |
| USDC | 0.001 USDC | `c4c24c4c1c8fd2ae738ed91cd87596ad2c672337b5ebf6d42a392adf61760e27` |
| CNY (Alipay) | 0.63 yuan | Sandbox TX: `2026070922001406640510096995` |
| CNY (Alipay) | **¥0.10** | **Production** ✅ `2026071122001479581453918172` (paid + refunded) |
| CNY (WeChat) | **¥0.05** | **Production** ✅ Native QR scan & pay |

---

## Milestones | 里程碑

| Version | Goal | 目标 | Status |
|---------|------|------|--------|
| v0.1 | Base testnet x402 payment loop (ETH + USDC) | ✅ |
| v0.2 | AP2 protocol support | ✅ |
| v0.3 | LangChain plugin published | ✅ |
| v0.4 | Signer abstraction + ERC-4337 batch settlement | ✅ |
| v0.5 | RPC failover + retry + limit persistence | ✅ |
| 🔌 Dify Plugin | Pay/Query/Refund tools | ✅ [v0.1.2](https://github.com/rhcjw/paypack/releases/tag/v0.1.2) |
| v0.6 | Alipay production launch | ✅ (¥0.10 paid + refunded on 2026-07-11) |
| v0.7 | WeChat Pay production launch | ✅ (¥0.05 paid on 2026-07-12) |
| v1.0 | PayPack Cloud managed service | ✅ **Live** at [rhcjw.com/pay](https://rhcjw.com/pay) |

---

## Why Now? | 为什么是现在？

- Stablecoin annual volume hit **$33 trillion** (2025) — 20x PayPal | 稳定币年交易量突破 $33 万亿
- AI Agent count projected at **22 billion** (McKinsey) | AI Agent 数量预计达 220 亿
- x402 protocol already processes tens of millions of tx on Solana | x402 协议已在 Solana 上处理数千万笔交易
- LangChain/LlamaIndex payment plugin market is **completely empty** | 支付插件市场完全空白
- Alipay "AI Pay" initiative launching 2026 — PayPack is the first to bridge it with x402 | 支付宝"AI 付"计划 2026 年启动

---

## Target Users: Chinese AI Developers | 目标用户：国内 AI 开发者

PayPack isn't just for LangChain. Hundreds of thousands of developers use these platforms — **none of them have payment tools**.
PayPack 不只是 LangChain 生态的工具。国内数十万开发者在用这些平台——**它们全都没有支付工具**。

| Platform | Users | 用户量 | Has Payment? | 有支付工具吗？ |
|----------|-------|--------|-------------|--------------|
| **Dify** | 100K+ | 数十万 | ✅ [PayPack Plugin](https://github.com/rhcjw/paypack/releases/tag/v0.1.2) |
| **Coze (ByteDance)** | 1M+ | 数百万 | ❌ None |
| **Baidu Qianfan** | 100K+ | 数十万 | ❌ None |
| **Tongyi Bailian** | 100K+ | 数十万 | ❌ None |

These developers are PayPack's real users. | 这些平台的开发者，才是 PayPack 真正的用户。

---

## Links | 链接

| Channel | URL | 渠道 |
|---------|-----|------|
| GitHub | https://github.com/rhcjw/paypack |
| Gitee (China Mirror) | https://gitee.com/rhcjw_com/paypack | Gitee（国内镜像） |
| PyPI | https://pypi.org/project/langchain-paypack/ |
| PayPack Cloud | https://rhcjw.com/pay | 云服务 |
| Dify Plugin | [paypack-0.1.2.difypkg](https://github.com/rhcjw/paypack/releases/tag/v0.1.2) | Dify 插件 |
| Quick Start | [QUICKSTART.md](./QUICKSTART.md) | 快速入门 |

---

## Contributing | 贡献

Star the repo, open an issue, or mention PayPack in Dify/Coze communities — every bit helps.
Star ⭐、提 Issue、或者在 Dify/Coze 社区里提到 PayPack，都是贡献。

## License | 许可证

Apache License 2.0. See [LICENSE](LICENSE).
