关于 paypal-integration
为开发者提供 PayPal 支付集成指南,涵盖 Checkout、订阅、Payouts、IPN 通知和退款等流程。内容包括客户端 JavaScript SDK 与服务端 REST API 的集成方式及沙盒测试。
主要功能
- 01PayPal Checkout 集成
- 02订阅与定期扣款
- 03Payouts 多收款方付款
- 04IPN 通知处理
- 05沙盒支付测试
适用场景
- 01为应用添加 PayPal 支付
- 02实现订阅和自动续费
- 03处理退款及支付争议
- 04测试支付流程
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ wshobson/ agents --skill paypal-integration安装后在 Claude Code 中输入/paypal-integration确认已加载。
附带文件references/details.md
详细介绍
PayPal 集成
掌握 PayPal 支付集成,包括 Express Checkout、IPN 处理、循环扣款和退款工作流。
何时使用此技能
- 将 PayPal 集成为支付选项
- 实现快速结账流程
- 使用 PayPal 设置循环扣款
- 处理退款和支付争议
- 处理 PayPal webhook(IPN)
- 支持国际支付
- 实现 PayPal 订阅
核心概念
1. 支付产品
PayPal Checkout
- 一次性支付
- 快速结账体验
- 访客和 PayPal 账户支付
PayPal Subscriptions
- 循环扣款
- 订阅计划
- 自动续费
PayPal Payouts
- 向多个收款人汇款
- 市场和平台支付
2. 集成方式
客户端(JavaScript SDK)
- 智能支付按钮
- 托管支付流程
- 最少量的后端代码
服务端(REST API)
- 完全掌控支付流程
- 自定义结账 UI
- 高级功能
3. IPN(即时付款通知)
- 类似 webhook 的支付通知
- 异步支付更新
- 需要验证
快速开始
// Frontend - PayPal Smart Buttons
<div id="paypal-button-container"></div>
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID¤cy=USD"></script>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '25.00'
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Payment successful
console.log('Transaction completed by ' + details.payer.name.given_name);
// Send to backend for verification
fetch('/api/paypal/capture', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({orderID: data.orderID})
});
});
}
}).render('#paypal-button-container');
</script>
# Backend - Verify and capture order
from paypalrestsdk import Payment
import paypalrestsdk
paypalrestsdk.configure({
"mode": "sandbox", # or "live"
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET"
})
def capture_paypal_order(order_id):
"""Capture a PayPal order."""
payment = Payment.find(order_id)
if payment.execute({"payer_id": payment.payer.payer_info.payer_id}):
# Payment successful
return {
'status': 'success',
'transaction_id': payment.id,
'amount': payment.transactions[0].amount.total
}
else:
# Payment failed
return {
'status': 'failed',
'error': payment.error
}
详细模式与完整示例
详细的模式文档位于 references/details.md。当上述导航层级不够用时,请阅读该文件。
测试
# Use sandbox credentials
SANDBOX_CLIENT_ID = "..."
SANDBOX_SECRET = "..."
# Test accounts
# Create test buyer and seller accounts at developer.paypal.com
def test_payment_flow():
"""Test complete payment flow."""
client = PayPalClient(SANDBOX_CLIENT_ID, SANDBOX_SECRET, mode='sandbox')
# Create order
order = client.create_order(10.00)
assert 'id' in order
# Get approval URL
approval_url = next((link['href'] for link in order['links'] if link['rel'] == 'approve'), None)
assert approval_url is not None
# After approval (manual step with test account)
# Capture order
# captured = client.capture_order(order['id'])
# assert captured['status'] == 'COMPLETED'
评论
支持 Markdown