npx skills add https://github.com/eyadsibai/ltk --skill stripe-payments适用于支付、订阅和 Webhook 的生产就绪型 Stripe 集成。
| 流程 | 使用场景 | PCI 合规负担 |
|---|---|---|
| 结账会话 | 托管页面,设置最快 | 最小 |
| 支付意向 | 自定义 UI,完全控制 | 需要 Stripe.js |
| 设置意向 | 保存卡片以备后用 | 最小 |
import stripe
stripe.api_key = "sk_test_..."
session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items=[{
'price_data': {
'currency': 'usd',
'product_data': {'name': 'Premium Plan'},
'unit_amount': 2000, # $20.00 in cents
'recurring': {'interval': 'month'},
},
'quantity': 1,
}],
mode='subscription',
success_url='https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
cancel_url='https://example.com/cancel',
)
# Redirect to session.url
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# Backend: Create payment intent
def create_payment_intent(amount, customer_id=None):
intent = stripe.PaymentIntent.create(
amount=amount, # In cents
currency='usd',
customer=customer_id,
automatic_payment_methods={'enabled': True},
)
return intent.client_secret
// Frontend: Confirm payment
const stripe = Stripe('pk_test_...');
const {error, paymentIntent} = await stripe.confirmCardPayment(
clientSecret,
{payment_method: {card: cardElement}}
);
@app.route('/webhook', methods=['POST'])
def webhook():
payload = request.data
sig = request.headers.get('Stripe-Signature')
try:
event = stripe.Webhook.construct_event(
payload, sig, 'whsec_...'
)
except stripe.error.SignatureVerificationError:
return 'Invalid signature', 400
if event['type'] == 'payment_intent.succeeded':
handle_payment_success(event['data']['object'])
elif event['type'] == 'customer.subscription.deleted':
handle_subscription_canceled(event['data']['object'])
return 'OK', 200
| 事件 | 处理时机 |
|---|---|
payment_intent.succeeded | 支付完成 |
payment_intent.payment_failed | 支付失败 |
customer.subscription.updated | 订阅变更 |
customer.subscription.deleted | 订阅取消 |
invoice.payment_succeeded | 订阅支付成功 |
# Create subscription
subscription = stripe.Subscription.create(
customer=customer_id,
items=[{'price': 'price_xxx'}],
payment_behavior='default_incomplete',
expand=['latest_invoice.payment_intent'],
)
# Customer portal for self-service
session = stripe.billing_portal.Session.create(
customer=customer_id,
return_url='https://example.com/account',
)
# Redirect to session.url
# Full refund
stripe.Refund.create(payment_intent='pi_xxx')
# Partial refund
stripe.Refund.create(
payment_intent='pi_xxx',
amount=500, # $5.00
reason='requested_by_customer'
)
| 卡号 | 结果 |
|---|---|
4242424242424242 | 成功 |
4000000000000002 | 被拒绝 |
4000002500003155 | 需要 3D 安全验证 |
4000000000009995 | 资金不足 |
每周安装量
92
代码仓库
GitHub 星标
1
首次出现
2026年1月28日
安全审计
已安装于
gemini-cli79
opencode79
codex77
github-copilot75
claude-code71
cursor71
Production-ready Stripe integration for payments, subscriptions, and webhooks.
| Flow | Use Case | PCI Burden |
|---|---|---|
| Checkout Session | Hosted page, fastest setup | Minimal |
| Payment Intents | Custom UI, full control | Requires Stripe.js |
| Setup Intents | Save card for later | Minimal |
import stripe
stripe.api_key = "sk_test_..."
session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items=[{
'price_data': {
'currency': 'usd',
'product_data': {'name': 'Premium Plan'},
'unit_amount': 2000, # $20.00 in cents
'recurring': {'interval': 'month'},
},
'quantity': 1,
}],
mode='subscription',
success_url='https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
cancel_url='https://example.com/cancel',
)
# Redirect to session.url
# Backend: Create payment intent
def create_payment_intent(amount, customer_id=None):
intent = stripe.PaymentIntent.create(
amount=amount, # In cents
currency='usd',
customer=customer_id,
automatic_payment_methods={'enabled': True},
)
return intent.client_secret
// Frontend: Confirm payment
const stripe = Stripe('pk_test_...');
const {error, paymentIntent} = await stripe.confirmCardPayment(
clientSecret,
{payment_method: {card: cardElement}}
);
@app.route('/webhook', methods=['POST'])
def webhook():
payload = request.data
sig = request.headers.get('Stripe-Signature')
try:
event = stripe.Webhook.construct_event(
payload, sig, 'whsec_...'
)
except stripe.error.SignatureVerificationError:
return 'Invalid signature', 400
if event['type'] == 'payment_intent.succeeded':
handle_payment_success(event['data']['object'])
elif event['type'] == 'customer.subscription.deleted':
handle_subscription_canceled(event['data']['object'])
return 'OK', 200
| Event | When to Handle |
|---|---|
payment_intent.succeeded | Payment completed |
payment_intent.payment_failed | Payment failed |
customer.subscription.updated | Subscription changed |
customer.subscription.deleted | Subscription canceled |
invoice.payment_succeeded | Subscription payment OK |
# Create subscription
subscription = stripe.Subscription.create(
customer=customer_id,
items=[{'price': 'price_xxx'}],
payment_behavior='default_incomplete',
expand=['latest_invoice.payment_intent'],
)
# Customer portal for self-service
session = stripe.billing_portal.Session.create(
customer=customer_id,
return_url='https://example.com/account',
)
# Redirect to session.url
# Full refund
stripe.Refund.create(payment_intent='pi_xxx')
# Partial refund
stripe.Refund.create(
payment_intent='pi_xxx',
amount=500, # $5.00
reason='requested_by_customer'
)
| Card Number | Result |
|---|---|
4242424242424242 | Success |
4000000000000002 | Declined |
4000002500003155 | 3D Secure required |
4000000000009995 | Insufficient funds |
Weekly Installs
92
Repository
GitHub Stars
1
First Seen
Jan 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
gemini-cli79
opencode79
codex77
github-copilot75
claude-code71
cursor71
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
166,500 周安装
Benchling Python SDK与REST API集成指南:生物信息学自动化与生命科学研发
178 周安装
Hypogenic:基于LLM的自动化科学假设生成与测试框架,加速AI科研发现
179 周安装
Arboreto:基因调控网络推断Python库,支持GRNBoost2/GENIE3算法与分布式计算
180 周安装
Clerk 身份验证模板 - Next.js 14/15 App Router 完整设置与路由保护
181 周安装
Next.js服务端与客户端组件选择指南:TypeScript最佳实践与性能优化
180 周安装
Fastify TypeScript 开发指南:构建高性能、类型安全的 Node.js API
181 周安装