返回顶部
P

PayPalPayPal支付集成

Integrate PayPal payments with proper webhook verification, OAuth handling, and security validation for checkout flows and subscriptions.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
848
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

PayPal

使用场景

用户需要集成PayPal REST API实现支付、订阅或付款。代理负责处理结账流程、Webhook验证、OAuth令牌管理和争议处理工作流。

快速参考

主题文件
代码模式patterns.md
Webhook事件
webhooks.md |

核心规则

1. 环境URL不同

  • - 沙箱环境:api.sandbox.paypal.com
  • 生产环境:api.paypal.com
  • 生成代码前务必确认使用哪个环境
  • 凭证与环境绑定——切勿混用

2. OAuth令牌管理

javascript // 令牌约8小时过期——需处理刷新 const getToken = async () => { const res = await fetch(https://api.paypal.com/v1/oauth2/token, { method: POST, headers: { Authorization: Basic ${Buffer.from(${clientId}:${secret}).toString(base64)}, Content-Type: application/x-www-form-urlencoded }, body: granttype=clientcredentials }); return res.json(); // { accesstoken, expiresin } };

切勿硬编码令牌。需实现刷新逻辑。

3. Webhook验证是强制要求

PayPal Webhook必须通过API调用验证——而非简单HMAC: javascript // POST /v1/notifications/verify-webhook-signature const verification = await fetch(https://api.paypal.com/v1/notifications/verify-webhook-signature, { method: POST, headers: { Authorization: Bearer ${token}, Content-Type: application/json }, body: JSON.stringify({ auth_algo: headers[paypal-auth-algo], cert_url: headers[paypal-cert-url], transmission_id: headers[paypal-transmission-id], transmission_sig: headers[paypal-transmission-sig], transmission_time: headers[paypal-transmission-time], webhookid: WEBHOOKID, webhook_event: body }) }); // verification_status === SUCCESS

4. CAPTURE与AUTHORIZE——需先确认
意图行为
CAPTURE批准后立即扣款
AUTHORIZE
预授权资金,后续扣款(最长29天) |

集成后更改意图会破坏整个流程。

5. 服务端验证——绝不信任客户端

javascript // 客户端批准后,在服务端验证再执行 const order = await fetch(https://api.paypal.com/v2/checkout/orders/${orderId}, { headers: { Authorization: Bearer ${token} } }).then(r => r.json());

// 验证以下所有项:
if (order.status !== APPROVED) throw new Error(未批准);
if (order.purchase_units[0].amount.value !== expectedAmount) throw new Error(金额不匹配);
if (order.purchaseunits[0].amount.currencycode !== expectedCurrency) throw new Error(币种不匹配);
if (order.purchaseunits[0].payee.merchantid !== YOURMERCHANTID) throw new Error(商户错误);

6. Webhook幂等性

PayPal可能多次发送相同Webhook: javascript const processed = await db.webhooks.findOne({ eventId: body.id }); if (processed) return res.status(200).send(已处理); await db.webhooks.insert({ eventId: body.id, processedAt: new Date() }); // 现在处理事件

7. 货币小数规则

部分货币无小数位:
货币小数位示例
USD, EUR210.50
JPY, TWD
0 | 1050(非1050.00) |

为JPY发送10.50会导致API错误。

常见陷阱

  • - IPN与Webhooks — IPN已过时。新集成请使用Webhooks。切勿混用。
  • 订单状态 — CREATED → APPROVED → COMPLETED(或VOIDED)。处理所有状态,不仅限于正常路径。
  • 小数混淆 — PayPal使用字符串表示金额(10.50),而非浮点数。部分货币禁止小数。
  • 沙箱速率限制 — 低于生产环境。不要假设生产环境会以相同方式失败。
  • 付款与支付 — 付款API是独立的。不要混淆发送资金(付款)与接收资金(订单)。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 paypal-1776101241 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 paypal-1776101241 技能

通过命令行安装

skillhub install paypal-1776101241

下载

⬇ 下载 PayPal v1.0.0(免费)

文件大小: 5.4 KB | 发布时间: 2026-4-14 13:13

v1.0.0 最新 2026-4-14 13:13
Initial release

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部