Setup
On first use, read setup.md and confirm platform, PSP, and release target before making code changes.
When to Use
User needs Alipay in checkout, subscriptions, or cross-border wallet flows. Agent handles architecture decisions, signing strategy, gateway integration, rollout validation, and post-launch operations.
Architecture
Memory lives in ~/alipay/. See memory-template.md for setup and status fields.
CODEBLOCK0
Quick Reference
Use the smallest relevant file for the current task.
| Topic | File |
|---|
| Setup flow | INLINECODE3 |
| Memory template |
memory-template.md |
| Implementation plan |
implementation-playbook.md |
| Validation matrix |
validation-checklist.md |
| Failure recovery |
failure-handling.md |
| Release and operations |
launch-playbook.md |
| Recurring and subscription flows |
recurring-payments.md |
Requirements
- - Environment variable: INLINECODE10
- CLI tools for diagnostics:
curl, INLINECODE12 - Access to Alipay merchant console and target PSP account
Never ask users to paste private keys, full signed payloads, or PSP secrets into chat.
Data Storage
Local notes stay under ~/alipay/:
- - memory file for current state and integration decisions
- validation log file for test outcomes and evidence
- incidents file for failure signatures and mitigations
Core Rules
1. Confirm Business Goal Before Choosing Integration Path
Start by identifying the target outcome:
- - Higher mobile checkout conversion
- Faster repeat purchases
- Lower payment friction for domestic and cross-border users
- Fewer payment failures
Then choose one primary path:
- - Web or H5 checkout with Alipay gateway redirect flow
- In-app checkout with Alipay SDK handoff
- PSP-mediated integration path
Do not mix paths in one patch unless the user asks for a migration plan.
2. Require Merchant and Environment Prerequisites
Before implementation, confirm:
- - Alipay app id exists for the correct account
- Gateway keys and certificates match the environment
- Notify and return URLs are configured and reachable
- Test and production credentials are separated
If prerequisites are missing, pause coding and produce a concrete prerequisite checklist.
3. Enforce Server Truth for Amounts and Currency
Amounts and currency must match across:
- - Client payment request payload
- Server-side order totals
- Alipay authorization and capture calls
Never trust client totals for final charge amount.
4. Make Signing and Callback Verification Explicit
Treat signing and verification as required controls:
- - Sign outgoing requests with the approved key strategy
- Verify callback signatures before changing order state
- Reject unsigned or invalid callbacks deterministically
Never mark a payment successful before signature checks pass.
5. Keep Payment Payload Handling Minimal and Auditable
Treat Alipay payloads as sensitive:
- - Forward payload only to backend or PSP
- Persist metadata only (request id, status, amount, currency)
- Never store raw signed payloads in logs, notes, or screenshots
6. Build Idempotent and Recoverable Payment Steps
Require idempotency and reconciliation for all critical calls:
- - Authorization request
- Capture request
- Refund or close operations
Every retried request must reuse stable idempotency keys to prevent duplicates.
7. Separate Test and Production Release Gates
Do not recommend production rollout until all gates pass:
- - Test success, decline, cancellation, and timeout paths are covered
- Device and browser matrix is complete for supported audience
- Fallback card or alternative checkout works when Alipay is unavailable
- Failure observability and alerts are active
Common Traps
- - Shipping test gateway config to production -> live checkout failures
- Skipping callback signature verification -> fraudulent or duplicated state transitions
- Mismatching charset or signing parameters -> request rejection at gateway
- Trusting client totals -> mismatch between authorized and captured amounts
- Missing idempotency on retries -> duplicate charges and refund overhead
- Launching without fallback checkout -> conversion loss when wallet is unavailable
External Endpoints
| Endpoint | Data Sent | Purpose |
|---|
| https://openapi.alipay.com/gateway.do | Signed payment requests and metadata | Production Alipay gateway operations |
| https://openapi-sandbox.dl.alipaydev.com/gateway.do |
Signed payment requests and metadata | Sandbox validation and integration testing |
| https://global.alipay.com | Documentation and account console traffic | Merchant setup and operational reference |
No other data should be sent externally unless the selected PSP requires it.
Security & Privacy
Data that leaves your machine:
- - Alipay request payloads needed for wallet flow
- Payment metadata and signed requests sent to configured PSP or backend
Data that stays local:
- - Integration notes and rollout state under INLINECODE14
- Validation evidence and failure logs without raw signed payloads
This skill does NOT:
- - Store raw signed request payloads in memory files
- Skip mandatory merchant and callback verification requirements
- Enable production release without explicit readiness checks
Trust
Alipay integrations depend on Alipay infrastructure and the chosen PSP.
Only install and run this skill if you trust those services and your payment backend.
Related Skills
Install with
clawhub install <slug> if user confirms:
- -
payments - General payment design and checkout decision frameworks - INLINECODE17 - Billing models, reconciliation, and payment lifecycle decisions
- INLINECODE18 - Reliable backend API contracts and failure-safe integrations
- INLINECODE19 - Authentication and session hardening in transaction flows
- INLINECODE20 - Android checkout implementation and runtime troubleshooting patterns
Feedback
- - If useful: INLINECODE21
- Stay updated: INLINECODE22
设置
首次使用时,请先阅读 setup.md 并确认平台、PSP 和发布目标,然后再进行代码修改。
使用场景
用户在结账、订阅或跨境钱包流程中需要使用支付宝。代理负责架构决策、签名策略、网关集成、上线验证以及上线后运营。
架构
记忆文件存放在 ~/alipay/ 目录下。请参阅 memory-template.md 了解设置和状态字段。
~/alipay/
|-- memory.md # 项目快照、风险状态和上线状态
|-- implementations.md # 所选方案和平台说明
|-- validation-log.md # 测试证据和环境结果
-- incidents.md # 支付失败、根本原因和修复方案
快速参考
根据当前任务使用最小的相关文件。
memory-template.md |
| 实施方案 | implementation-playbook.md |
| 验证矩阵 | validation-checklist.md |
| 故障恢复 | failure-handling.md |
| 发布与运营 | launch-playbook.md |
| 定期与订阅流程 | recurring-payments.md |
要求
- - 环境变量:ALIPAYAPPID
- 诊断 CLI 工具:curl、jq
- 可访问支付宝商家控制台和目标 PSP 账户
切勿要求用户粘贴私钥、完整签名负载或 PSP 机密信息到聊天中。
数据存储
本地记录保存在 ~/alipay/ 目录下:
- - 记忆文件:记录当前状态和集成决策
- 验证日志文件:记录测试结果和证据
- 故障事件文件:记录失败特征和缓解措施
核心规则
1. 在选择集成路径前确认业务目标
首先确定目标结果:
- - 提高移动端结账转化率
- 加快重复购买速度
- 降低国内和跨境用户的支付摩擦
- 减少支付失败次数
然后选择一条主要路径:
- - 通过支付宝网关重定向流程进行 Web 或 H5 结账
- 通过支付宝 SDK 交接进行应用内结账
- PSP 中介集成路径
除非用户要求迁移计划,否则不要在一个补丁中混合使用多条路径。
2. 要求具备商家和环境先决条件
在实施之前,确认:
- - 支付宝应用 ID 对应正确的账户
- 网关密钥和证书与环境匹配
- 通知和返回 URL 已配置并可访问
- 测试和生产凭据已分离
如果缺少先决条件,暂停编码并生成具体的先决条件清单。
3. 强制服务器端对金额和货币的真实性
金额和货币必须在以下方面保持一致:
- - 客户端支付请求负载
- 服务器端订单总额
- 支付宝授权和收款调用
切勿信任客户端的最终收费金额。
4. 明确签名和回调验证
将签名和验证视为必需的控制措施:
- - 使用批准的密钥策略对发出的请求进行签名
- 在更改订单状态前验证回调签名
- 确定性地拒绝未签名或无效的回调
在签名检查通过之前,切勿将支付标记为成功。
5. 保持支付负载处理最小化且可审计
将支付宝负载视为敏感信息:
- - 仅将负载转发到后端或 PSP
- 仅持久化元数据(请求 ID、状态、金额、货币)
- 切勿在日志、记录或截图中存储原始签名负载
6. 构建幂等且可恢复的支付步骤
所有关键调用都需要幂等性和对账:
每次重试的请求必须使用稳定的幂等键以防止重复。
7. 分离测试和生产发布关卡
在所有关卡通过之前,不建议进行生产发布:
- - 覆盖测试成功、拒绝、取消和超时路径
- 针对目标受众完成设备和浏览器矩阵
- 当支付宝不可用时,备选卡或其他结账方式正常工作
- 故障可观测性和告警已激活
常见陷阱
- - 将测试网关配置部署到生产环境 -> 导致线上结账失败
- 跳过回调签名验证 -> 导致欺诈性或重复的状态转换
- 字符集或签名参数不匹配 -> 请求在网关被拒绝
- 信任客户端总额 -> 授权金额与收款金额不匹配
- 重试时缺少幂等性 -> 导致重复扣费和退款开销
- 未设置备选结账方式即上线 -> 钱包不可用时导致转化率损失
外部端点
| 端点 | 发送的数据 | 用途 |
|---|
| https://openapi.alipay.com/gateway.do | 签名的支付请求和元数据 | 生产环境支付宝网关操作 |
| https://openapi-sandbox.dl.alipaydev.com/gateway.do |
签名的支付请求和元数据 | 沙箱验证和集成测试 |
| https://global.alipay.com | 文档和账户控制台流量 | 商家设置和运营参考 |
除非所选 PSP 要求,否则不应向外部发送其他数据。
安全与隐私
离开您机器的数据:
- - 钱包流程所需的支付宝请求负载
- 发送到已配置 PSP 或后端的支付元数据和签名请求
保留在本地数据:
- - ~/alipay/ 目录下的集成记录和上线状态
- 不包含原始签名负载的验证证据和故障日志
本技能不会:
- - 在记忆文件中存储原始签名请求负载
- 跳过强制性的商家和回调验证要求
- 在未明确检查就绪状态的情况下启用生产发布
信任
支付宝集成依赖于支付宝基础设施和所选 PSP。
仅当您信任这些服务以及您的支付后端时,才安装和运行本技能。
相关技能
如果用户确认,使用 clawhub install 安装:
- - payments - 通用支付设计和结账决策框架
- billing - 计费模型、对账和支付生命周期决策
- api - 可靠的后端 API 契约和故障安全集成
- auth - 交易流程中的身份验证和会话加固
- android - Android 结账实现和运行时故障排查模式
反馈
- - 如果觉得有用:clawhub star alipay
- 保持更新:clawhub sync