PayPack · by Xiamen Shizhun Technology

Quickstart — add payments to an AI agent with PayPack

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.

Requirements

ItemVersion
Python≥ 3.10
langchain-core≥ 0.1.0, < 0.3.0 (installed automatically)
web3≥ 6.0.0, < 7.0.0 (installed automatically)
Current package version0.7.9
LicenseApache-2.0

Step 1 — Install

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

Step 2 — Choose a rail

RailCurrencyUse when
Alipay (fiat)CNYYour users pay with Alipay
WeChat Pay (fiat)CNYYour users pay inside WeChat / mini programs
x402 / AP2 (on-chain)USDC / ETHThe merchant API itself answers HTTP 402

Step 3a — Pay with Alipay (CNY)

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)

Web checkout (QR code)

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.

Step 3b — Pay with WeChat Pay (CNY)

Note: 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).

Step 3c — Pay on-chain with x402 (USDC / ETH)

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"])

Step 4 — Use it as a LangChain tool

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.

Step 5 (optional) — Use the hosted Cloud API instead

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"}'

Supported networks

NetworkChain IDCurrencies
Base Sepolia (testnet)84532ETH, USDC
Base Mainnet8453ETH, USDC
Ethereum Mainnet1ETH, USDC
Polygon Mainnet137POL, USDC
Arbitrum Mainnet42161ETH, USDC
Alipay (sandbox / production)—CNY
WeChat Pay—CNY

Verification status

ChannelSandboxProduction
ETH / USDC (Base, Ethereum, Polygon, Arbitrum)VerifiedLive
Alipay (CNY)Sandbox OKProduction verified (¥0.10 paid and refunded)
WeChat Pay (CNY)Backend OKProduction verified (¥0.05 paid)

Safety features you get by default

Summary

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