specweave 0.3.13 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +17 -1
- package/README.md +1 -1
- package/bin/install-all.sh +9 -2
- package/bin/install-hooks.sh +57 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +55 -0
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/core/agent-model-manager.d.ts +52 -0
- package/dist/core/agent-model-manager.d.ts.map +1 -0
- package/dist/core/agent-model-manager.js +120 -0
- package/dist/core/agent-model-manager.js.map +1 -0
- package/dist/core/cost-tracker.d.ts +108 -0
- package/dist/core/cost-tracker.d.ts.map +1 -0
- package/dist/core/cost-tracker.js +281 -0
- package/dist/core/cost-tracker.js.map +1 -0
- package/dist/core/model-selector.d.ts +57 -0
- package/dist/core/model-selector.d.ts.map +1 -0
- package/dist/core/model-selector.js +115 -0
- package/dist/core/model-selector.js.map +1 -0
- package/dist/core/phase-detector.d.ts +62 -0
- package/dist/core/phase-detector.d.ts.map +1 -0
- package/dist/core/phase-detector.js +229 -0
- package/dist/core/phase-detector.js.map +1 -0
- package/dist/types/cost-tracking.d.ts +43 -0
- package/dist/types/cost-tracking.d.ts.map +1 -0
- package/dist/types/cost-tracking.js +8 -0
- package/dist/types/cost-tracking.js.map +1 -0
- package/dist/types/model-selection.d.ts +53 -0
- package/dist/types/model-selection.d.ts.map +1 -0
- package/dist/types/model-selection.js +12 -0
- package/dist/types/model-selection.js.map +1 -0
- package/dist/utils/cost-reporter.d.ts +58 -0
- package/dist/utils/cost-reporter.d.ts.map +1 -0
- package/dist/utils/cost-reporter.js +224 -0
- package/dist/utils/cost-reporter.js.map +1 -0
- package/dist/utils/pricing-constants.d.ts +70 -0
- package/dist/utils/pricing-constants.d.ts.map +1 -0
- package/dist/utils/pricing-constants.js +71 -0
- package/dist/utils/pricing-constants.js.map +1 -0
- package/package.json +1 -1
- package/src/agents/architect/AGENT.md +3 -0
- package/src/agents/code-reviewer.md +156 -0
- package/src/agents/data-scientist/AGENT.md +181 -0
- package/src/agents/database-optimizer/AGENT.md +147 -0
- package/src/agents/devops/AGENT.md +3 -0
- package/src/agents/diagrams-architect/AGENT.md +3 -0
- package/src/agents/docs-writer/AGENT.md +3 -0
- package/src/agents/kubernetes-architect/AGENT.md +142 -0
- package/src/agents/ml-engineer/AGENT.md +150 -0
- package/src/agents/mlops-engineer/AGENT.md +201 -0
- package/src/agents/network-engineer/AGENT.md +149 -0
- package/src/agents/observability-engineer/AGENT.md +213 -0
- package/src/agents/payment-integration/AGENT.md +35 -0
- package/src/agents/performance/AGENT.md +3 -0
- package/src/agents/performance-engineer/AGENT.md +153 -0
- package/src/agents/pm/AGENT.md +3 -0
- package/src/agents/qa-lead/AGENT.md +3 -0
- package/src/agents/security/AGENT.md +3 -0
- package/src/agents/sre/AGENT.md +3 -0
- package/src/agents/tdd-orchestrator/AGENT.md +169 -0
- package/src/agents/tech-lead/AGENT.md +3 -0
- package/src/commands/specweave.costs.md +261 -0
- package/src/commands/specweave.ml-pipeline.md +292 -0
- package/src/commands/specweave.monitor-setup.md +501 -0
- package/src/commands/specweave.slo-implement.md +1055 -0
- package/src/commands/specweave.sync-github.md +1 -1
- package/src/commands/specweave.tdd-cycle.md +199 -0
- package/src/commands/specweave.tdd-green.md +842 -0
- package/src/commands/specweave.tdd-red.md +135 -0
- package/src/commands/specweave.tdd-refactor.md +165 -0
- package/src/skills/SKILLS-INDEX.md +18 -10
- package/src/skills/billing-automation/SKILL.md +559 -0
- package/src/skills/distributed-tracing/SKILL.md +438 -0
- package/src/skills/e2e-playwright/README.md +1 -1
- package/src/skills/e2e-playwright/package.json +1 -1
- package/src/skills/gitops-workflow/SKILL.md +285 -0
- package/src/skills/gitops-workflow/references/argocd-setup.md +134 -0
- package/src/skills/gitops-workflow/references/sync-policies.md +131 -0
- package/src/skills/grafana-dashboards/SKILL.md +369 -0
- package/src/skills/helm-chart-scaffolding/SKILL.md +544 -0
- package/src/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
- package/src/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
- package/src/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
- package/src/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
- package/src/skills/k8s-manifest-generator/SKILL.md +511 -0
- package/src/skills/k8s-manifest-generator/assets/configmap-template.yaml +296 -0
- package/src/skills/k8s-manifest-generator/assets/deployment-template.yaml +203 -0
- package/src/skills/k8s-manifest-generator/assets/service-template.yaml +171 -0
- package/src/skills/k8s-manifest-generator/references/deployment-spec.md +753 -0
- package/src/skills/k8s-manifest-generator/references/service-spec.md +724 -0
- package/src/skills/k8s-security-policies/SKILL.md +334 -0
- package/src/skills/k8s-security-policies/assets/network-policy-template.yaml +177 -0
- package/src/skills/k8s-security-policies/references/rbac-patterns.md +187 -0
- package/src/skills/ml-pipeline-workflow/SKILL.md +245 -0
- package/src/skills/paypal-integration/SKILL.md +467 -0
- package/src/skills/pci-compliance/SKILL.md +466 -0
- package/src/skills/prometheus-configuration/SKILL.md +392 -0
- package/src/skills/slo-implementation/SKILL.md +329 -0
- package/src/skills/stripe-integration/SKILL.md +442 -0
- package/src/skills/tdd-workflow/SKILL.md +378 -0
- package/src/templates/README.md.template +1 -1
- package/src/skills/bmad-method-expert/SKILL.md +0 -626
- package/src/skills/bmad-method-expert/scripts/analyze-project.js +0 -318
- package/src/skills/bmad-method-expert/scripts/check-setup.js +0 -208
- package/src/skills/bmad-method-expert/scripts/generate-template.js +0 -1149
- package/src/skills/bmad-method-expert/scripts/validate-documents.js +0 -340
- package/src/skills/context-optimizer/SKILL.md +0 -588
- package/src/skills/figma-designer/SKILL.md +0 -149
- package/src/skills/figma-implementer/SKILL.md +0 -148
- package/src/skills/figma-mcp-connector/SKILL.md +0 -136
- package/src/skills/figma-to-code/SKILL.md +0 -128
- package/src/skills/spec-kit-expert/SKILL.md +0 -1010
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: stripe-integration
|
|
3
|
+
description: Implement Stripe payment processing for robust, PCI-compliant payment flows including checkout, subscriptions, and webhooks. Use when integrating Stripe payments, building subscription systems, or implementing secure checkout flows.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Stripe Integration
|
|
7
|
+
|
|
8
|
+
Master Stripe payment processing integration for robust, PCI-compliant payment flows including checkout, subscriptions, webhooks, and refunds.
|
|
9
|
+
|
|
10
|
+
## When to Use This Skill
|
|
11
|
+
|
|
12
|
+
- Implementing payment processing in web/mobile applications
|
|
13
|
+
- Setting up subscription billing systems
|
|
14
|
+
- Handling one-time payments and recurring charges
|
|
15
|
+
- Processing refunds and disputes
|
|
16
|
+
- Managing customer payment methods
|
|
17
|
+
- Implementing SCA (Strong Customer Authentication) for European payments
|
|
18
|
+
- Building marketplace payment flows with Stripe Connect
|
|
19
|
+
|
|
20
|
+
## Core Concepts
|
|
21
|
+
|
|
22
|
+
### 1. Payment Flows
|
|
23
|
+
**Checkout Session (Hosted)**
|
|
24
|
+
- Stripe-hosted payment page
|
|
25
|
+
- Minimal PCI compliance burden
|
|
26
|
+
- Fastest implementation
|
|
27
|
+
- Supports one-time and recurring payments
|
|
28
|
+
|
|
29
|
+
**Payment Intents (Custom UI)**
|
|
30
|
+
- Full control over payment UI
|
|
31
|
+
- Requires Stripe.js for PCI compliance
|
|
32
|
+
- More complex implementation
|
|
33
|
+
- Better customization options
|
|
34
|
+
|
|
35
|
+
**Setup Intents (Save Payment Methods)**
|
|
36
|
+
- Collect payment method without charging
|
|
37
|
+
- Used for subscriptions and future payments
|
|
38
|
+
- Requires customer confirmation
|
|
39
|
+
|
|
40
|
+
### 2. Webhooks
|
|
41
|
+
**Critical Events:**
|
|
42
|
+
- `payment_intent.succeeded`: Payment completed
|
|
43
|
+
- `payment_intent.payment_failed`: Payment failed
|
|
44
|
+
- `customer.subscription.updated`: Subscription changed
|
|
45
|
+
- `customer.subscription.deleted`: Subscription canceled
|
|
46
|
+
- `charge.refunded`: Refund processed
|
|
47
|
+
- `invoice.payment_succeeded`: Subscription payment successful
|
|
48
|
+
|
|
49
|
+
### 3. Subscriptions
|
|
50
|
+
**Components:**
|
|
51
|
+
- **Product**: What you're selling
|
|
52
|
+
- **Price**: How much and how often
|
|
53
|
+
- **Subscription**: Customer's recurring payment
|
|
54
|
+
- **Invoice**: Generated for each billing cycle
|
|
55
|
+
|
|
56
|
+
### 4. Customer Management
|
|
57
|
+
- Create and manage customer records
|
|
58
|
+
- Store multiple payment methods
|
|
59
|
+
- Track customer metadata
|
|
60
|
+
- Manage billing details
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import stripe
|
|
66
|
+
|
|
67
|
+
stripe.api_key = "sk_test_..."
|
|
68
|
+
|
|
69
|
+
# Create a checkout session
|
|
70
|
+
session = stripe.checkout.Session.create(
|
|
71
|
+
payment_method_types=['card'],
|
|
72
|
+
line_items=[{
|
|
73
|
+
'price_data': {
|
|
74
|
+
'currency': 'usd',
|
|
75
|
+
'product_data': {
|
|
76
|
+
'name': 'Premium Subscription',
|
|
77
|
+
},
|
|
78
|
+
'unit_amount': 2000, # $20.00
|
|
79
|
+
'recurring': {
|
|
80
|
+
'interval': 'month',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
'quantity': 1,
|
|
84
|
+
}],
|
|
85
|
+
mode='subscription',
|
|
86
|
+
success_url='https://yourdomain.com/success?session_id={CHECKOUT_SESSION_ID}',
|
|
87
|
+
cancel_url='https://yourdomain.com/cancel',
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Redirect user to session.url
|
|
91
|
+
print(session.url)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Payment Implementation Patterns
|
|
95
|
+
|
|
96
|
+
### Pattern 1: One-Time Payment (Hosted Checkout)
|
|
97
|
+
```python
|
|
98
|
+
def create_checkout_session(amount, currency='usd'):
|
|
99
|
+
"""Create a one-time payment checkout session."""
|
|
100
|
+
try:
|
|
101
|
+
session = stripe.checkout.Session.create(
|
|
102
|
+
payment_method_types=['card'],
|
|
103
|
+
line_items=[{
|
|
104
|
+
'price_data': {
|
|
105
|
+
'currency': currency,
|
|
106
|
+
'product_data': {
|
|
107
|
+
'name': 'Purchase',
|
|
108
|
+
'images': ['https://example.com/product.jpg'],
|
|
109
|
+
},
|
|
110
|
+
'unit_amount': amount, # Amount in cents
|
|
111
|
+
},
|
|
112
|
+
'quantity': 1,
|
|
113
|
+
}],
|
|
114
|
+
mode='payment',
|
|
115
|
+
success_url='https://yourdomain.com/success?session_id={CHECKOUT_SESSION_ID}',
|
|
116
|
+
cancel_url='https://yourdomain.com/cancel',
|
|
117
|
+
metadata={
|
|
118
|
+
'order_id': 'order_123',
|
|
119
|
+
'user_id': 'user_456'
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
return session
|
|
123
|
+
except stripe.error.StripeError as e:
|
|
124
|
+
# Handle error
|
|
125
|
+
print(f"Stripe error: {e.user_message}")
|
|
126
|
+
raise
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Pattern 2: Custom Payment Intent Flow
|
|
130
|
+
```python
|
|
131
|
+
def create_payment_intent(amount, currency='usd', customer_id=None):
|
|
132
|
+
"""Create a payment intent for custom checkout UI."""
|
|
133
|
+
intent = stripe.PaymentIntent.create(
|
|
134
|
+
amount=amount,
|
|
135
|
+
currency=currency,
|
|
136
|
+
customer=customer_id,
|
|
137
|
+
automatic_payment_methods={
|
|
138
|
+
'enabled': True,
|
|
139
|
+
},
|
|
140
|
+
metadata={
|
|
141
|
+
'integration_check': 'accept_a_payment'
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
return intent.client_secret # Send to frontend
|
|
145
|
+
|
|
146
|
+
# Frontend (JavaScript)
|
|
147
|
+
"""
|
|
148
|
+
const stripe = Stripe('pk_test_...');
|
|
149
|
+
const elements = stripe.elements();
|
|
150
|
+
const cardElement = elements.create('card');
|
|
151
|
+
cardElement.mount('#card-element');
|
|
152
|
+
|
|
153
|
+
const {error, paymentIntent} = await stripe.confirmCardPayment(
|
|
154
|
+
clientSecret,
|
|
155
|
+
{
|
|
156
|
+
payment_method: {
|
|
157
|
+
card: cardElement,
|
|
158
|
+
billing_details: {
|
|
159
|
+
name: 'Customer Name'
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
if (error) {
|
|
166
|
+
// Handle error
|
|
167
|
+
} else if (paymentIntent.status === 'succeeded') {
|
|
168
|
+
// Payment successful
|
|
169
|
+
}
|
|
170
|
+
"""
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Pattern 3: Subscription Creation
|
|
174
|
+
```python
|
|
175
|
+
def create_subscription(customer_id, price_id):
|
|
176
|
+
"""Create a subscription for a customer."""
|
|
177
|
+
try:
|
|
178
|
+
subscription = stripe.Subscription.create(
|
|
179
|
+
customer=customer_id,
|
|
180
|
+
items=[{'price': price_id}],
|
|
181
|
+
payment_behavior='default_incomplete',
|
|
182
|
+
payment_settings={'save_default_payment_method': 'on_subscription'},
|
|
183
|
+
expand=['latest_invoice.payment_intent'],
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
'subscription_id': subscription.id,
|
|
188
|
+
'client_secret': subscription.latest_invoice.payment_intent.client_secret
|
|
189
|
+
}
|
|
190
|
+
except stripe.error.StripeError as e:
|
|
191
|
+
print(f"Subscription creation failed: {e}")
|
|
192
|
+
raise
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Pattern 4: Customer Portal
|
|
196
|
+
```python
|
|
197
|
+
def create_customer_portal_session(customer_id):
|
|
198
|
+
"""Create a portal session for customers to manage subscriptions."""
|
|
199
|
+
session = stripe.billing_portal.Session.create(
|
|
200
|
+
customer=customer_id,
|
|
201
|
+
return_url='https://yourdomain.com/account',
|
|
202
|
+
)
|
|
203
|
+
return session.url # Redirect customer here
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Webhook Handling
|
|
207
|
+
|
|
208
|
+
### Secure Webhook Endpoint
|
|
209
|
+
```python
|
|
210
|
+
from flask import Flask, request
|
|
211
|
+
import stripe
|
|
212
|
+
|
|
213
|
+
app = Flask(__name__)
|
|
214
|
+
|
|
215
|
+
endpoint_secret = 'whsec_...'
|
|
216
|
+
|
|
217
|
+
@app.route('/webhook', methods=['POST'])
|
|
218
|
+
def webhook():
|
|
219
|
+
payload = request.data
|
|
220
|
+
sig_header = request.headers.get('Stripe-Signature')
|
|
221
|
+
|
|
222
|
+
try:
|
|
223
|
+
event = stripe.Webhook.construct_event(
|
|
224
|
+
payload, sig_header, endpoint_secret
|
|
225
|
+
)
|
|
226
|
+
except ValueError:
|
|
227
|
+
# Invalid payload
|
|
228
|
+
return 'Invalid payload', 400
|
|
229
|
+
except stripe.error.SignatureVerificationError:
|
|
230
|
+
# Invalid signature
|
|
231
|
+
return 'Invalid signature', 400
|
|
232
|
+
|
|
233
|
+
# Handle the event
|
|
234
|
+
if event['type'] == 'payment_intent.succeeded':
|
|
235
|
+
payment_intent = event['data']['object']
|
|
236
|
+
handle_successful_payment(payment_intent)
|
|
237
|
+
elif event['type'] == 'payment_intent.payment_failed':
|
|
238
|
+
payment_intent = event['data']['object']
|
|
239
|
+
handle_failed_payment(payment_intent)
|
|
240
|
+
elif event['type'] == 'customer.subscription.deleted':
|
|
241
|
+
subscription = event['data']['object']
|
|
242
|
+
handle_subscription_canceled(subscription)
|
|
243
|
+
|
|
244
|
+
return 'Success', 200
|
|
245
|
+
|
|
246
|
+
def handle_successful_payment(payment_intent):
|
|
247
|
+
"""Process successful payment."""
|
|
248
|
+
customer_id = payment_intent.get('customer')
|
|
249
|
+
amount = payment_intent['amount']
|
|
250
|
+
metadata = payment_intent.get('metadata', {})
|
|
251
|
+
|
|
252
|
+
# Update your database
|
|
253
|
+
# Send confirmation email
|
|
254
|
+
# Fulfill order
|
|
255
|
+
print(f"Payment succeeded: {payment_intent['id']}")
|
|
256
|
+
|
|
257
|
+
def handle_failed_payment(payment_intent):
|
|
258
|
+
"""Handle failed payment."""
|
|
259
|
+
error = payment_intent.get('last_payment_error', {})
|
|
260
|
+
print(f"Payment failed: {error.get('message')}")
|
|
261
|
+
# Notify customer
|
|
262
|
+
# Update order status
|
|
263
|
+
|
|
264
|
+
def handle_subscription_canceled(subscription):
|
|
265
|
+
"""Handle subscription cancellation."""
|
|
266
|
+
customer_id = subscription['customer']
|
|
267
|
+
# Update user access
|
|
268
|
+
# Send cancellation email
|
|
269
|
+
print(f"Subscription canceled: {subscription['id']}")
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Webhook Best Practices
|
|
273
|
+
```python
|
|
274
|
+
import hashlib
|
|
275
|
+
import hmac
|
|
276
|
+
|
|
277
|
+
def verify_webhook_signature(payload, signature, secret):
|
|
278
|
+
"""Manually verify webhook signature."""
|
|
279
|
+
expected_sig = hmac.new(
|
|
280
|
+
secret.encode('utf-8'),
|
|
281
|
+
payload,
|
|
282
|
+
hashlib.sha256
|
|
283
|
+
).hexdigest()
|
|
284
|
+
|
|
285
|
+
return hmac.compare_digest(signature, expected_sig)
|
|
286
|
+
|
|
287
|
+
def handle_webhook_idempotently(event_id, handler):
|
|
288
|
+
"""Ensure webhook is processed exactly once."""
|
|
289
|
+
# Check if event already processed
|
|
290
|
+
if is_event_processed(event_id):
|
|
291
|
+
return
|
|
292
|
+
|
|
293
|
+
# Process event
|
|
294
|
+
try:
|
|
295
|
+
handler()
|
|
296
|
+
mark_event_processed(event_id)
|
|
297
|
+
except Exception as e:
|
|
298
|
+
log_error(e)
|
|
299
|
+
# Stripe will retry failed webhooks
|
|
300
|
+
raise
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Customer Management
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
def create_customer(email, name, payment_method_id=None):
|
|
307
|
+
"""Create a Stripe customer."""
|
|
308
|
+
customer = stripe.Customer.create(
|
|
309
|
+
email=email,
|
|
310
|
+
name=name,
|
|
311
|
+
payment_method=payment_method_id,
|
|
312
|
+
invoice_settings={
|
|
313
|
+
'default_payment_method': payment_method_id
|
|
314
|
+
} if payment_method_id else None,
|
|
315
|
+
metadata={
|
|
316
|
+
'user_id': '12345'
|
|
317
|
+
}
|
|
318
|
+
)
|
|
319
|
+
return customer
|
|
320
|
+
|
|
321
|
+
def attach_payment_method(customer_id, payment_method_id):
|
|
322
|
+
"""Attach a payment method to a customer."""
|
|
323
|
+
stripe.PaymentMethod.attach(
|
|
324
|
+
payment_method_id,
|
|
325
|
+
customer=customer_id
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
# Set as default
|
|
329
|
+
stripe.Customer.modify(
|
|
330
|
+
customer_id,
|
|
331
|
+
invoice_settings={
|
|
332
|
+
'default_payment_method': payment_method_id
|
|
333
|
+
}
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
def list_customer_payment_methods(customer_id):
|
|
337
|
+
"""List all payment methods for a customer."""
|
|
338
|
+
payment_methods = stripe.PaymentMethod.list(
|
|
339
|
+
customer=customer_id,
|
|
340
|
+
type='card'
|
|
341
|
+
)
|
|
342
|
+
return payment_methods.data
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Refund Handling
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
def create_refund(payment_intent_id, amount=None, reason=None):
|
|
349
|
+
"""Create a refund."""
|
|
350
|
+
refund_params = {
|
|
351
|
+
'payment_intent': payment_intent_id
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if amount:
|
|
355
|
+
refund_params['amount'] = amount # Partial refund
|
|
356
|
+
|
|
357
|
+
if reason:
|
|
358
|
+
refund_params['reason'] = reason # 'duplicate', 'fraudulent', 'requested_by_customer'
|
|
359
|
+
|
|
360
|
+
refund = stripe.Refund.create(**refund_params)
|
|
361
|
+
return refund
|
|
362
|
+
|
|
363
|
+
def handle_dispute(charge_id, evidence):
|
|
364
|
+
"""Update dispute with evidence."""
|
|
365
|
+
stripe.Dispute.modify(
|
|
366
|
+
charge_id,
|
|
367
|
+
evidence={
|
|
368
|
+
'customer_name': evidence.get('customer_name'),
|
|
369
|
+
'customer_email_address': evidence.get('customer_email'),
|
|
370
|
+
'shipping_documentation': evidence.get('shipping_proof'),
|
|
371
|
+
'customer_communication': evidence.get('communication'),
|
|
372
|
+
}
|
|
373
|
+
)
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## Testing
|
|
377
|
+
|
|
378
|
+
```python
|
|
379
|
+
# Use test mode keys
|
|
380
|
+
stripe.api_key = "sk_test_..."
|
|
381
|
+
|
|
382
|
+
# Test card numbers
|
|
383
|
+
TEST_CARDS = {
|
|
384
|
+
'success': '4242424242424242',
|
|
385
|
+
'declined': '4000000000000002',
|
|
386
|
+
'3d_secure': '4000002500003155',
|
|
387
|
+
'insufficient_funds': '4000000000009995'
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
def test_payment_flow():
|
|
391
|
+
"""Test complete payment flow."""
|
|
392
|
+
# Create test customer
|
|
393
|
+
customer = stripe.Customer.create(
|
|
394
|
+
email="test@example.com"
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
# Create payment intent
|
|
398
|
+
intent = stripe.PaymentIntent.create(
|
|
399
|
+
amount=1000,
|
|
400
|
+
currency='usd',
|
|
401
|
+
customer=customer.id,
|
|
402
|
+
payment_method_types=['card']
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
# Confirm with test card
|
|
406
|
+
confirmed = stripe.PaymentIntent.confirm(
|
|
407
|
+
intent.id,
|
|
408
|
+
payment_method='pm_card_visa' # Test payment method
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
assert confirmed.status == 'succeeded'
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
## Resources
|
|
415
|
+
|
|
416
|
+
- **references/checkout-flows.md**: Detailed checkout implementation
|
|
417
|
+
- **references/webhook-handling.md**: Webhook security and processing
|
|
418
|
+
- **references/subscription-management.md**: Subscription lifecycle
|
|
419
|
+
- **references/customer-management.md**: Customer and payment method handling
|
|
420
|
+
- **references/invoice-generation.md**: Invoicing and billing
|
|
421
|
+
- **assets/stripe-client.py**: Production-ready Stripe client wrapper
|
|
422
|
+
- **assets/webhook-handler.py**: Complete webhook processor
|
|
423
|
+
- **assets/checkout-config.json**: Checkout configuration templates
|
|
424
|
+
|
|
425
|
+
## Best Practices
|
|
426
|
+
|
|
427
|
+
1. **Always Use Webhooks**: Don't rely solely on client-side confirmation
|
|
428
|
+
2. **Idempotency**: Handle webhook events idempotently
|
|
429
|
+
3. **Error Handling**: Gracefully handle all Stripe errors
|
|
430
|
+
4. **Test Mode**: Thoroughly test with test keys before production
|
|
431
|
+
5. **Metadata**: Use metadata to link Stripe objects to your database
|
|
432
|
+
6. **Monitoring**: Track payment success rates and errors
|
|
433
|
+
7. **PCI Compliance**: Never handle raw card data on your server
|
|
434
|
+
8. **SCA Ready**: Implement 3D Secure for European payments
|
|
435
|
+
|
|
436
|
+
## Common Pitfalls
|
|
437
|
+
|
|
438
|
+
- **Not Verifying Webhooks**: Always verify webhook signatures
|
|
439
|
+
- **Missing Webhook Events**: Handle all relevant webhook events
|
|
440
|
+
- **Hardcoded Amounts**: Use cents/smallest currency unit
|
|
441
|
+
- **No Retry Logic**: Implement retries for API calls
|
|
442
|
+
- **Ignoring Test Mode**: Test all edge cases with test cards
|