1
---
2
name: paypal-integration
3
description: Integrate PayPal payment processing with support for express checkout, subscriptions, and refund management. Use when implementing PayPal payments, processing online transactions, or building e-commerce checkout flows.
4
---
5
6
# PayPal Integration
7
8
Master PayPal payment integration including Express Checkout, IPN handling, recurring billing, and refund workflows.
9
10
## When to Use This Skill
11
12
- Integrating PayPal as a payment option
13
- Implementing express checkout flows
14
- Setting up recurring billing with PayPal
15
- Processing refunds and payment disputes
16
- Handling PayPal webhooks (IPN)
17
- Supporting international payments
18
- Implementing PayPal subscriptions
19
20
## Core Concepts
21
22
### 1. Payment Products
23
24
**PayPal Checkout**
25
26
- One-time payments
27
- Express checkout experience
28
- Guest and PayPal account payments
29
30
**PayPal Subscriptions**
31
32
- Recurring billing
33
- Subscription plans
34
- Automatic renewals
35
36
**PayPal Payouts**
37
38
- Send money to multiple recipients
39
- Marketplace and platform payments
40
41
### 2. Integration Methods
42
43
**Client-Side (JavaScript SDK)**
44
45
- Smart Payment Buttons
46
- Hosted payment flow
47
- Minimal backend code
48
49
**Server-Side (REST API)**
50
51
- Full control over payment flow
52
- Custom checkout UI
53
- Advanced features
54
55
### 3. IPN (Instant Payment Notification)
56
57
- Webhook-like payment notifications
58
- Asynchronous payment updates
59
- Verification required
60
61
## Quick Start
62
63
```javascript
64
// Frontend - PayPal Smart Buttons
65
<div id="paypal-button-container"></div>
66
67
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID¤cy=USD"></script>
68
<script>
69
paypal.Buttons({
70
createOrder: function(data, actions) {
71
return actions.order.create({
72
purchase_units: [{
73
amount: {
74
value: '25.00'
75
}
76
}]
77
});
78
},
79
onApprove: function(data, actions) {
80
return actions.order.capture().then(function(details) {
81
// Payment successful
82
console.log('Transaction completed by ' + details.payer.name.given_name);
83
84
// Send to backend for verification
85
fetch('/api/paypal/capture', {
86
method: 'POST',
87
headers: {'Content-Type': 'application/json'},
88
body: JSON.stringify({orderID: data.orderID})
89
});
90
});
91
}
92
}).render('#paypal-button-container');
93
</script>
94
```
95
96
```python
97
# Backend - Verify and capture order
98
from paypalrestsdk import Payment
99
import paypalrestsdk
100
101
paypalrestsdk.configure({
102
"mode": "sandbox", # or "live"
103
"client_id": "YOUR_CLIENT_ID",
104
"client_secret": "YOUR_CLIENT_SECRET"
105
})
106
107
def capture_paypal_order(order_id):
108
"""Capture a PayPal order."""
109
payment = Payment.find(order_id)
110
111
if payment.execute({"payer_id": payment.payer.payer_info.payer_id}):
112
# Payment successful
113
return {
114
'status': 'success',
115
'transaction_id': payment.id,
116
'amount': payment.transactions[0].amount.total
117
}
118
else:
119
# Payment failed
120
return {
121
'status': 'failed',
122
'error': payment.error
123
}
124
```
125
126
## Detailed patterns and worked examples
127
128
Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
129
130
## Testing
131
132
```python
133
# Use sandbox credentials
134
SANDBOX_CLIENT_ID = "..."
135
SANDBOX_SECRET = "..."
136
137
# Test accounts
138
# Create test buyer and seller accounts at developer.paypal.com
139
140
def test_payment_flow():
141
"""Test complete payment flow."""
142
client = PayPalClient(SANDBOX_CLIENT_ID, SANDBOX_SECRET, mode='sandbox')
143
144
# Create order
145
order = client.create_order(10.00)
146
assert 'id' in order
147
148
# Get approval URL
149
approval_url = next((link['href'] for link in order['links'] if link['rel'] == 'approve'), None)
150
assert approval_url is not None
151
152
# After approval (manual step with test account)
153
# Capture order
154
# captured = client.capture_order(order['id'])
155
# assert captured['status'] == 'COMPLETED'
156
```
157