技能 stripe-integration
💳

stripe-integration

安全 🌐 网络访问⚙️ 外部命令

集成 Stripe 支付

也可从以下获取: wshobson

本技能提供全面的 Stripe 支付集成指导,包括实现结账、订阅、Webhook 和退款处理,并遵循 PCI 合规最佳实践。

支持: Claude Codex Code(CC)
🥉 73 青铜
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“stripe-integration”。 为 49 美元的产品创建结账会话

预期结果:

我可以帮助你创建 Stripe 结账会话。以下是 Python 代码:

```python
import stripe

stripe.api_key = 'sk_test_YOUR_KEY'

session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items=[{
'price_data': {
'currency': 'usd',
'product_data': {'name': 'Premium Widget'},
'unit_amount': 4900, # $49.00 in cents
},
'quantity': 1,
}],
mode='payment',
success_url='https://yoursite.com/success?session_id={CHECKOUT_SESSION_ID}',
cancel_url='https://yoursite.com/cancel',
)

# Redirect user to session.url
```

这将创建一个托管结账页面。用户将被重定向到 Stripe 的安全支付表单。

正在使用“stripe-integration”。 安全地处理支付成功 Webhook

预期结果:

以下是使用 Flask 并带签名验证的安全 Webhook 处理器:

```python
from flask import Flask, request
import stripe

app = Flask(__name__)
endpoint_secret = 'whsec_YOUR_SECRET'

@app.route('/webhook', methods=['POST'])
def webhook():
payload = request.data
sig_header = request.headers.get('Stripe-Signature')

try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret
)
except ValueError:
return 'Invalid payload', 400
except stripe.error.SignatureVerificationError:
return 'Invalid signature', 400

if event['type'] == 'payment_intent.succeeded':
payment_intent = event['data']['object']
# Process the payment - update database, send receipt, etc.

return 'Success', 200
```

安全审计

安全
v1 • 2/25/2026

All 47 static findings are false positives. The skill contains legitimate Stripe payment integration documentation with Python code examples. Detected patterns (backtick execution, hardcoded URLs, API key access) are benign documentation artifacts: backticks are markdown code fences, URLs are placeholder examples, and API key patterns are documented placeholders showing where users should insert their own keys.

1
已扫描文件
457
分析行数
5
发现项
1
审计总数
中风险问题 (3)
External Command Detection in Code Blocks
Static scanner detected Ruby/shell backtick execution patterns at 26 locations. Investigation reveals these are FALSE POSITIVES - the detections are backticks used for markdown code fencing in Python code examples (e.g., `import stripe`, `stripe.api_key = ...`). This is legitimate documentation formatting, not command execution.
Hardcoded URLs in Code Examples
Static scanner detected hardcoded URLs. Investigation reveals these are FALSE POSITIVES - placeholder example URLs like 'https://yourdomain.com/success' in code samples showing users where to configure their own callback URLs.
Environment Variable Access for API Keys
Static scanner detected API key access patterns at lines 81 and 394. Investigation reveals these are FALSE POSITIVES - these are documented placeholders 'sk_test_...' showing users where to insert their own test API keys, a standard documentation practice for Stripe integration guides.
审计者: claude

质量评分

38
架构
100
可维护性
87
内容
50
社区
90
安全
100
规范符合性

你能构建什么

电子商务结账实现

在 Web 应用中添加 Stripe 结账功能,通过托管结账页面接受一次性付款。

SaaS 订阅管理

为 SaaS 产品设置定期计费,包含客户门户访问和订阅生命周期管理。

Webhook 事件处理

通过签名验证和幂等处理安全地处理支付事件,适用于生产系统。

试试这些提示

基础结账设置
帮我设置一个基础的 Stripe 结账流程,用于 29 美元的一次性付款。展示如何创建结账会话并重定向用户。
订阅创建
为每月 19 美元的月度服务创建订阅结账流程。包含客户创建和订阅激活。
Webhook 处理器
用 Python 编写一个安全的 Webhook 处理器,验证 Stripe 签名并处理 payment_intent.succeeded 事件。
退款处理
展示如何实现部分退款并处理退款工作流程,包括原因代码。

最佳实践

  • 始终使用 stripe.Webhook.construct_event 验证 Webhook 签名,以防止伪造事件
  • 使用 Stripe 的托管结账页面以最大限度地减少 PCI 合规负担
  • 在处理前通过检查重复事件 ID 来幂等地处理 Webhook 事件
  • 仅存储支付方式 ID,绝不存储原始卡数据,以保持 PCI 合规
  • 开发期间使用测试模式密钥,并使用测试卡号验证所有支付流程

避免

  • 不要仅依赖客户端支付确认 - 始终通过 Webhook 验证
  • 不要在源代码中硬编码 API 密钥 - 使用环境变量或密钥管理
  • 不要重复处理相同的 Webhook 事件 - 实现幂等性检查
  • 不要在测试模式中使用生产 API 密钥,也不要在生产中使用测试卡

常见问题

结账会话(Checkout Sessions)和支付意向(Payment Intents)之间有什么区别?
结账会话(Checkout Sessions)使用 Stripe 的托管支付页面,实施工作量最小且符合 PCI 合规要求。支付意向(Payment Intents)让你完全控制在应用中构建自定义支付 UI。
我如何验证 Webhook 确实来自 Stripe?
使用 stripe.Webhook.construct_event() 和你的端点密钥来验证 Stripe-Signature 标头。这确保请求确实来自 Stripe。
我可以使用的测试卡号有哪些?
使用 4242424242424242 进行成功支付测试,使用 4000000000000002 测试被拒卡片,使用 4000002500003155 测试需要 3D Secure 的卡片。
我如何为欧洲客户处理强客户认证(SCA)?
当你使用结账会话(Checkout Sessions)或启用 automatic_payment_methods 时,Stripe 会自动处理 SCA。对于自定义流程,请使用带有新认证流程的 Stripe Elements。
我可以处理部分退款吗?
可以,在创建退款时提供以美分为单位的 amount 参数。如果不提供,Stripe 将处理全额退款。你可以进行多次部分退款,总额不超过原始支付金额。
我如何让客户访问管理他们的订阅?
通过调用 stripe.billing_portal.Session.create() 并传入客户 ID 来使用 Stripe 计费门户(Billing Portal)。这提供了一个 Stripe 托管页面,客户可以在其中更新支付方式、取消或暂停订阅。

开发者详情

文件结构

📄 SKILL.md