paypal-integration について
開発者向けの PayPal 決済統合ガイドです。Checkout、サブスクリプション、Payouts、IPN 通知、返金を扱い、JavaScript SDK と REST API による実装やサンドボックステストを説明します。
主な機能
- 01PayPal Checkout の統合
- 02サブスクリプションと定期課金
- 03複数宛先への Payouts
- 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 統合
Express Checkout、IPN 処理、定期請求、返金ワークフローを含む PayPal 決済統合をマスターしましょう。
このスキルを使用する場面
- PayPal を支払いオプションとして統合する場合
- エクスプレスチェックアウトフローを実装する場合
- PayPal で定期請求を設定する場合
- 返金と支払いに関する紛争を処理する場合
- PayPal Webhook(IPN)を処理する場合
- 国際決済をサポートする場合
- PayPal サブスクリプションを実装する場合
中核となる概念
1. 決済プロダクト
PayPal チェックアウト
- 単発の支払い
- エクスプレスチェックアウト体験
- ゲストおよび PayPal アカウントでの支払い
PayPal サブスクリプション
- 定期請求
- サブスクリプションプラン
- 自動更新
PayPal ペイアウト
- 複数の受取人への送金
- マーケットプレイスおよびプラットフォームの支払い
2. 統合方法
クライアントサイド(JavaScript SDK)
- スマートペイメントボタン
- ホスト型の支払いフロー
- 最小限のバックエンドコード
サーバーサイド(REST API)
- 支払いフローの完全な制御
- カスタムチェックアウト UI
- 高度な機能
3. IPN(Instant Payment Notification)
- 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 対応