Install langchain-paypack and give an agent the ability to pay. PayPack exposes one payment call and hides the differences between on-chain (x402 / AP2) and fiat (Alipay, WeChat Pay) rails behind it.
| Item | Version |
|---|---|
| Python | ≥ 3.10 |
langchain-core | ≥ 0.1.0, < 0.3.0 (installed automatically) |
web3 | ≥ 6.0.0, < 7.0.0 (installed automatically) |
| Current package version | 0.7.9 |
| License | Apache-2.0 |
pip install langchain-paypack
If you are in mainland China, the Gitee mirror is usually faster:
pip install https://gitee.com/rhcjw_com/paypack/raw/master/dist/langchain_paypack-0.5.0-py3-none-any.whl
| Rail | Currency | Use when |
|---|---|---|
| Alipay (fiat) | CNY | Your users pay with Alipay |
| WeChat Pay (fiat) | CNY | Your users pay inside WeChat / mini programs |
| x402 / AP2 (on-chain) | USDC / ETH | The merchant API itself answers HTTP 402 |
from paypack import AgentPay
from paypack.signer.alipay import AlipaySigner
signer = AlipaySigner(
app_id="your-app-id",
private_key_path="key.pem",
alipay_public_key_path="alipay_public_key.pem",
sandbox=True, # set False for production
)
pay = AgentPay(signer=signer, network="alipay")
receipt = pay.send(
to="user_alipay_id",
amount=0.01,
currency="CNY",
subject="AI data subscription",
)
print(receipt)
pay_url = signer.page_pay(
out_trade_no="ORDER_20261020_001",
total_amount=9.90,
subject="AI Agent API monthly fee",
body="Generated by PayPack",
)
# Open pay_url in a browser; the user scans the QR to pay.
paypack_wechat is a commercial module and requires a license key. The open-source package ships a template: paypack_wechat_run.example.py.
from paypack_wechat import WechatSigner
from paypack import AgentPay
signer = WechatSigner(
mchid="merchant-id",
serial_no="certificate-serial",
private_key_path="apiclient_key.pem",
api_v3_key="api-v3-key",
license_key="PAYPACK-WECHAT-v1-...",
app_id="mini-program-appid",
notify_url="https://your-domain.com/wechat/notify",
)
pay = AgentPay(signer=signer, network="wechat")
result = pay.send(
to="user-openid",
amount=9.90,
currency="CNY",
subject="AI monthly subscription",
app_id="mini-program-appid",
)
# result["prepay_params"] is passed to the frontend (wx.requestPayment).
from paypack import AgentPay
import requests
pay = AgentPay(
wallet_config={"private_key": "0x..."},
network="base-sepolia",
spend_limit_daily=10.0, # safety fuse
)
# The merchant API answers 402 with a payment requirement
response = requests.get("https://api.example.com/premium")
if response.status_code == 402:
content = pay.auto_handle_402(response)
# Or send directly
receipt = pay.send(to="0xRecipientAddress", amount=0.001, currency="USDC")
print(receipt["tx_hash"])
from langchain_paypack import PayPackTool
tool = PayPackTool(
private_key="0x...",
wallet_address="0x...",
network="base-sepolia",
spend_limit_daily=10.0,
)
result = tool._run(to="0x...", amount=0.001, currency="USDC")
Register the tool on your agent and the model can call it like any other tool.
If you do not want to manage merchant keys, PayPack Cloud exposes a plain HTTP API:
# Register and get an API key
curl -X POST https://rhcjw.com/pay/v1/register \
-H "Content-Type: application/json" \
-d '{"name":"myapp","email":"user@example.com"}'
# Create a payment
curl -X POST https://rhcjw.com/pay/v1/pay \
-H "Authorization: Bearer ppk_xxx" \
-H "Content-Type: application/json" \
-d '{"amount":0.01,"subject":"AI service","channel":"alipay"}'
| Network | Chain ID | Currencies |
|---|---|---|
| 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 / production) | — | CNY |
| WeChat Pay | — | CNY |
| Channel | Sandbox | Production |
|---|---|---|
| ETH / USDC (Base, Ethereum, Polygon, Arbitrum) | Verified | Live |
| Alipay (CNY) | Sandbox OK | Production verified (¥0.10 paid and refunded) |
| WeChat Pay (CNY) | Backend OK | Production verified (¥0.05 paid) |
spend_limit_daily caps what the agent can spend in 24 hours.pip install langchain-paypack (Python ≥ 3.10, current version 0.7.9).AgentPay, AlipaySigner, WechatSigner, PayPackTool) and a hosted HTTP Cloud API.
PayPack is a developer tool for payment integration. It does not provide investment services, does not promise returns, and does not hold user funds.
Operated by Xiamen Shizhun Technology Co., Ltd. (Unified Social Credit Code: 91350211MA34XHGG5T) · Website: rhcjw.com · ICP filing: 闽ICP备2024041817号-2