paypack-langchain 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: paypack-langchain
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: langchain-paypack: x402 (Coinbase) + AP2 (Google) dual-protocol client for LangChain Agents. One agent.pay() for USDC/ETH (Base/Ethereum/Polygon/Arbitrum) + Alipay/WeChat CNY. Dify Tool Plugin available.
|
|
5
|
+
Project-URL: Homepage, https://github.com/yourname/paypack
|
|
6
|
+
Author: PayPack
|
|
7
|
+
License: MIT
|
|
8
|
+
Keywords: agent-pay,alipay,ap2,base,dify,langchain,usdc,wechat,x402
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: httpx>=0.27.0
|
|
11
|
+
Requires-Dist: langchain-core>=0.3.0
|
|
12
|
+
Requires-Dist: pydantic>=2.0.0
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# langchain-paypack: x402 + AP2 dual-protocol for LangChain Agents
|
|
16
|
+
|
|
17
|
+
x402 (Coinbase) + AP2 (Google) 双协议支付。一行代码给 LangChain Agent 加上 USDC/ETH + 支付宝/微信支付能力。Dify Tool Plugin 可用。
|
|
18
|
+
|
|
19
|
+
## 安装
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install paypack-langchain
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 快速开始
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from paypack_langchain import PayPackTool
|
|
29
|
+
|
|
30
|
+
# 用你的 API Key 初始化
|
|
31
|
+
tool = PayPackTool(
|
|
32
|
+
api_key="ppk_你的API_KEY",
|
|
33
|
+
base_url="https://你的域名.com", # PayPack Cloud 服务地址
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# 在 Agent 里直接使用
|
|
37
|
+
result = tool.run(amount=0.01, subject="AI 数据查询")
|
|
38
|
+
print(result)
|
|
39
|
+
# 输出:
|
|
40
|
+
# 支付订单已创建
|
|
41
|
+
# 订单号: PP20260710120000ABC12345
|
|
42
|
+
# 金额: ¥0.01
|
|
43
|
+
# 状态: pending
|
|
44
|
+
# 支付链接: https://openapi.alipay.com/...
|
|
45
|
+
# 二维码: https://...
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 在 LangChain Agent 中使用
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from langchain.agents import create_react_agent, AgentExecutor
|
|
52
|
+
from langchain_openai import ChatOpenAI
|
|
53
|
+
from paypack_langchain import PayPackTool, PayPackQueryTool
|
|
54
|
+
|
|
55
|
+
llm = ChatOpenAI(model="deepseek-v4-flash")
|
|
56
|
+
tools = [
|
|
57
|
+
PayPackTool(api_key="ppk_xxx", base_url="https://你的域名.com"),
|
|
58
|
+
PayPackQueryTool(api_key="ppk_xxx", base_url="https://你的域名.com"),
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
agent = create_react_agent(llm, tools, ...)
|
|
62
|
+
agent_executor = AgentExecutor(agent=agent, tools=tools)
|
|
63
|
+
|
|
64
|
+
# Agent 现在可以自动发起支付和查询订单了
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 获取 API Key
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
curl -X POST https://你的域名.com/v1/register \
|
|
71
|
+
-H "Content-Type: application/json" \
|
|
72
|
+
-d '{"name": "my_agent"}'
|
|
73
|
+
# 返回: {"api_key": "ppk_xxx..."}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 发布
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
cd plugins/langchain
|
|
80
|
+
pip install build
|
|
81
|
+
python -m build
|
|
82
|
+
pip install twine
|
|
83
|
+
python -m twine upload dist/*
|
|
84
|
+
```
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# langchain-paypack: x402 + AP2 dual-protocol for LangChain Agents
|
|
2
|
+
|
|
3
|
+
x402 (Coinbase) + AP2 (Google) 双协议支付。一行代码给 LangChain Agent 加上 USDC/ETH + 支付宝/微信支付能力。Dify Tool Plugin 可用。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install paypack-langchain
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from paypack_langchain import PayPackTool
|
|
15
|
+
|
|
16
|
+
# 用你的 API Key 初始化
|
|
17
|
+
tool = PayPackTool(
|
|
18
|
+
api_key="ppk_你的API_KEY",
|
|
19
|
+
base_url="https://你的域名.com", # PayPack Cloud 服务地址
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
# 在 Agent 里直接使用
|
|
23
|
+
result = tool.run(amount=0.01, subject="AI 数据查询")
|
|
24
|
+
print(result)
|
|
25
|
+
# 输出:
|
|
26
|
+
# 支付订单已创建
|
|
27
|
+
# 订单号: PP20260710120000ABC12345
|
|
28
|
+
# 金额: ¥0.01
|
|
29
|
+
# 状态: pending
|
|
30
|
+
# 支付链接: https://openapi.alipay.com/...
|
|
31
|
+
# 二维码: https://...
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 在 LangChain Agent 中使用
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from langchain.agents import create_react_agent, AgentExecutor
|
|
38
|
+
from langchain_openai import ChatOpenAI
|
|
39
|
+
from paypack_langchain import PayPackTool, PayPackQueryTool
|
|
40
|
+
|
|
41
|
+
llm = ChatOpenAI(model="deepseek-v4-flash")
|
|
42
|
+
tools = [
|
|
43
|
+
PayPackTool(api_key="ppk_xxx", base_url="https://你的域名.com"),
|
|
44
|
+
PayPackQueryTool(api_key="ppk_xxx", base_url="https://你的域名.com"),
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
agent = create_react_agent(llm, tools, ...)
|
|
48
|
+
agent_executor = AgentExecutor(agent=agent, tools=tools)
|
|
49
|
+
|
|
50
|
+
# Agent 现在可以自动发起支付和查询订单了
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 获取 API Key
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
curl -X POST https://你的域名.com/v1/register \
|
|
57
|
+
-H "Content-Type: application/json" \
|
|
58
|
+
-d '{"name": "my_agent"}'
|
|
59
|
+
# 返回: {"api_key": "ppk_xxx..."}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 发布
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
cd plugins/langchain
|
|
66
|
+
pip install build
|
|
67
|
+
python -m build
|
|
68
|
+
pip install twine
|
|
69
|
+
python -m twine upload dist/*
|
|
70
|
+
```
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PayPack LangChain Tool
|
|
3
|
+
一行代码给 AI Agent 加上支付能力。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
from paypack_langchain import PayPackTool
|
|
7
|
+
|
|
8
|
+
tool = PayPackTool(api_key="ppk_xxx")
|
|
9
|
+
result = tool.run(amount=0.01, subject="AI 数据查询")
|
|
10
|
+
"""
|
|
11
|
+
from typing import Optional, Type
|
|
12
|
+
|
|
13
|
+
from langchain_core.tools import BaseTool
|
|
14
|
+
from pydantic import BaseModel, Field
|
|
15
|
+
import httpx
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class PayPackInput(BaseModel):
|
|
19
|
+
"""支付请求参数"""
|
|
20
|
+
amount: float = Field(..., gt=0, description="支付金额(元),如 0.01")
|
|
21
|
+
subject: str = Field(..., min_length=1, max_length=256, description="商品描述,如 'AI 数据查询'")
|
|
22
|
+
callback_url: Optional[str] = Field(None, description="支付结果回调地址(可选)")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class PayPackQueryInput(BaseModel):
|
|
26
|
+
"""查询请求参数"""
|
|
27
|
+
order_id: str = Field(..., description="订单号,支付接口返回的 order_id")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class PayPackTool(BaseTool):
|
|
31
|
+
"""
|
|
32
|
+
PayPack 支付工具 —— AI Agent 专用支付接口。
|
|
33
|
+
|
|
34
|
+
调用后返回支付链接或二维码,用户完成支付后 Agent 继续执行。
|
|
35
|
+
|
|
36
|
+
使用前先注册获取 API Key:
|
|
37
|
+
curl -X POST https://your-domain.com/v1/register \\
|
|
38
|
+
-H "Content-Type: application/json" \\
|
|
39
|
+
-d '{"name": "my_agent"}'
|
|
40
|
+
"""
|
|
41
|
+
name: str = "paypack_pay"
|
|
42
|
+
description: str = (
|
|
43
|
+
"发起一笔支付并返回支付链接。适用于需要向用户收费后才能提供内容的场景。"
|
|
44
|
+
"输入金额(元)和商品描述,返回一个支付二维码/链接。"
|
|
45
|
+
)
|
|
46
|
+
args_schema: Type[BaseModel] = PayPackInput
|
|
47
|
+
|
|
48
|
+
api_key: str = Field(..., description="PayPack Cloud API Key,格式: ppk_xxx")
|
|
49
|
+
base_url: str = Field(default="https://your-domain.com", description="PayPack Cloud 服务地址")
|
|
50
|
+
|
|
51
|
+
def _run(self, amount: float, subject: str, callback_url: Optional[str] = None) -> str:
|
|
52
|
+
"""同步调用支付接口"""
|
|
53
|
+
import json
|
|
54
|
+
payload = {
|
|
55
|
+
"amount": amount,
|
|
56
|
+
"currency": "CNY",
|
|
57
|
+
"subject": subject,
|
|
58
|
+
}
|
|
59
|
+
if callback_url:
|
|
60
|
+
payload["callback_url"] = callback_url
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
resp = httpx.post(
|
|
64
|
+
f"{self.base_url}/v1/pay",
|
|
65
|
+
json=payload,
|
|
66
|
+
headers={"X-API-Key": self.api_key, "Content-Type": "application/json"},
|
|
67
|
+
timeout=15,
|
|
68
|
+
)
|
|
69
|
+
resp.raise_for_status()
|
|
70
|
+
data = resp.json()
|
|
71
|
+
|
|
72
|
+
lines = [
|
|
73
|
+
f"支付订单已创建",
|
|
74
|
+
f"订单号: {data.get('order_id', '')}",
|
|
75
|
+
f"金额: ¥{amount:.2f}",
|
|
76
|
+
f"状态: {data.get('status', 'pending')}",
|
|
77
|
+
]
|
|
78
|
+
if data.get("pay_url"):
|
|
79
|
+
lines.append(f"支付链接: {data['pay_url']}")
|
|
80
|
+
if data.get("qr_code"):
|
|
81
|
+
lines.append(f"二维码: {data['qr_code']}")
|
|
82
|
+
|
|
83
|
+
return "\n".join(lines)
|
|
84
|
+
|
|
85
|
+
except httpx.HTTPStatusError as e:
|
|
86
|
+
if e.response.status_code == 402:
|
|
87
|
+
return f"余额不足,请先充值。详情: {e.response.text}"
|
|
88
|
+
return f"支付失败 ({e.response.status_code}): {e.response.text}"
|
|
89
|
+
except Exception as e:
|
|
90
|
+
return f"支付异常: {str(e)}"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class PayPackQueryTool(BaseTool):
|
|
94
|
+
"""
|
|
95
|
+
查询 PayPack 订单状态。
|
|
96
|
+
"""
|
|
97
|
+
name: str = "paypack_query"
|
|
98
|
+
description: str = "查询一笔支付订单的当前状态(成功/待支付/已退款)。"
|
|
99
|
+
args_schema: Type[BaseModel] = PayPackQueryInput
|
|
100
|
+
|
|
101
|
+
api_key: str = Field(..., description="PayPack Cloud API Key")
|
|
102
|
+
base_url: str = Field(default="https://your-domain.com", description="PayPack Cloud 服务地址")
|
|
103
|
+
|
|
104
|
+
def _run(self, order_id: str) -> str:
|
|
105
|
+
try:
|
|
106
|
+
resp = httpx.get(
|
|
107
|
+
f"{self.base_url}/v1/query",
|
|
108
|
+
params={"order_id": order_id},
|
|
109
|
+
headers={"X-API-Key": self.api_key},
|
|
110
|
+
timeout=10,
|
|
111
|
+
)
|
|
112
|
+
resp.raise_for_status()
|
|
113
|
+
data = resp.json()
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
f"订单: {data.get('order_id')}\n"
|
|
117
|
+
f"状态: {data.get('status')}\n"
|
|
118
|
+
f"金额: ¥{data.get('amount', 0):.2f}\n"
|
|
119
|
+
f"创建时间: {data.get('created_at', '')}\n"
|
|
120
|
+
f"支付时间: {data.get('paid_at', '未支付')}"
|
|
121
|
+
)
|
|
122
|
+
except Exception as e:
|
|
123
|
+
return f"查询失败: {str(e)}"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# 便捷函数:一行代码发起支付
|
|
127
|
+
def pay(api_key: str, amount: float, subject: str, base_url: str = "https://your-domain.com") -> str:
|
|
128
|
+
"""一行代码发起支付"""
|
|
129
|
+
tool = PayPackTool(api_key=api_key, base_url=base_url)
|
|
130
|
+
return tool.run(amount=amount, subject=subject)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "paypack-langchain"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "langchain-paypack: x402 (Coinbase) + AP2 (Google) dual-protocol client for LangChain Agents. One agent.pay() for USDC/ETH (Base/Ethereum/Polygon/Arbitrum) + Alipay/WeChat CNY. Dify Tool Plugin available."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"langchain-core>=0.3.0",
|
|
14
|
+
"httpx>=0.27.0",
|
|
15
|
+
"pydantic>=2.0.0",
|
|
16
|
+
]
|
|
17
|
+
keywords = ["langchain", "x402", "ap2", "agent-pay", "dify", "alipay", "wechat", "usdc", "base"]
|
|
18
|
+
|
|
19
|
+
[[project.authors]]
|
|
20
|
+
name = "PayPack"
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/yourname/paypack"
|