跳到正文
Skillpedia
API 与服务器(后端)33k · #8802

stripe-integration

它能做什么

这项技能指导你的智能体把 Stripe 支付添加到应用或网站中。它涵盖结账、订阅和 Webhook,并提供避免订单丢失和密钥泄露的步骤。

适用场景

  • ✓当你想为网站或应用添加结账、订阅或计费功能时。
  • ✓当你需要设置 Stripe Webhook,以便可靠地确认订单时。
  • ✓当你想对现有支付代码进行第二次检查,查找错误或安全漏洞的时候。

技能链接

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/development/stripe-integration/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/development/stripe-integration/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请为我的网上商店设置 Stripe Checkout,并确保通过 Webhook 确认付款。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会遵循 Stripe 的最新指南,为你的情况选择合适的支付方式,并应用幂等性和受限 API 密钥等检查。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Stripe Integration

Guidance for building payment code that does not lose orders, double-charge or leak keys. It follows Stripe's own recommendations as of October 2026. When a detail matters (a parameter, an event name, an API version), check docs.stripe.com or the Stripe MCP server's search_stripe_documentation tool before relying on memory.

Versions

  • Latest API version: 2026-09-30.endive. Pin it explicitly on the client so an account default change never alters response shapes under you.
  • Latest server SDKs: Node.js 23, Python 16, Ruby 20, PHP 22, Java 34, Go 87, .NET 53. Create a client instance; the global key pattern (stripe.api_key = …, Stripe.setApiKey) is deprecated in every SDK.
  • To move an existing integration to a newer version, read Upgrading your API version first.
// lib/stripe.ts
import Stripe from 'stripe';

export const stripe = new Stripe(process.env.STRIPE_API_KEY!, {
  apiVersion: '2026-09-30.endive',
});

Choose the API

Building Use
One-time payment, simple product Payment Links (no code) or Checkout Sessions
One-time payment in your web app Checkout Sessions (hosted or embedded)
Custom payment form Checkout Sessions with ui_mode: 'custom' + Payment Element
Save a card for later Setup Intents
Charge off-session (no customer present) Payment Intents with a saved payment method
Subscriptions, seats, trials Billing APIs + Checkout mode: 'subscription' + Customer Portal
New usage-based billing Metronome (Stripe's usage platform), not raw Billing Meters
Marketplace or platform Connect, Accounts v2 (/v2/core/accounts), Stripe-hosted onboarding

Never use the Charges API, Sources API, Tokens API, Card Element or the plan object. They are deprecated or legacy; use the rows above and Prices.

Rules

Fulfill from webhooks, never from the success page

A customer can pay and close the tab before the success page loads. Grant access, send email and write orders only in the webhook handler.

  • Handle checkout.session.completed and checkout.session.async_payment_succeeded. Fulfill only when session.payment_status !== 'unpaid'. Delayed methods (bank debits) send completed while still unpaid.
  • Handle checkout.session.async_payment_failed for those failures.
  • Subscriptions need customer.subscription.created|updated|deleted, invoice.paid and invoice.payment_failed. Renewals, dunning and cancellations only reach you this way.
  • Webhooks are required before launch, not a follow-up.

Verify every webhook signature on the raw body

Signature verification needs the exact bytes Stripe sent. Body-parsing middleware breaks it.

// Next.js App Router: app/api/stripe/webhook/route.ts
import Stripe from 'stripe';
import { stripe } from '@/lib/stripe';

export async function POST(req: Request) {
  const body = await req.text(); // raw body, do not use req.json()
  const signature = req.headers.get('stripe-signature');
  if (!signature) return new Response('missing signature', { status: 400 });

  let event: Stripe.Event;
  try {
    event = stripe.webhooks.constructEvent(
      body,
      signature,
      process.env.STRIPE_WEBHOOK_SECRET!,
    );
  } catch {
    return new Response('invalid signature', { status: 400 });
  }

  switch (event.type) {
    case 'checkout.session.completed':
    case 'checkout.session.async_payment_succeeded': {
      // Re-fetch instead of trusting the payload snapshot.
      const session = await stripe.checkout.sessions.retrieve(event.data.object.id);
      // fulfillOrder must be idempotent: the same event can arrive twice.
      if (session.payment_status !== 'unpaid') await fulfillOrder(session.id);
      break;
    }
    case 'checkout.session.async_payment_failed':
      await markPaymentFailed(event.data.object.id);
      break;
  }
  return new Response(null, { status: 200 });
}
  • On Cloudflare Workers, Deno or Bun use await stripe.webhooks.constructEventAsync(...).
  • In Express, mount express.raw({ type: 'application/json' }) on the webhook route only, before any global express.json().
  • In live mode Stripe retries for up to three days and can deliver an event more than once or out of order. Make fulfillOrder idempotent (store processed event or session IDs with a unique constraint) and decide by the object's current state, not by event order
常见问题

它也涵盖退款吗?

涵盖。描述中包括退款,以及结账、订阅、客户门户和 Stripe Tax。

它如何处理密钥?

这项技能警告不要暴露密钥,并建议使用受限 API 密钥。

建议是最新的吗?

这项技能声明它遵循截至 2026 年 10 月的 Stripe 指南,并告诉智能体在细节重要时查阅 Stripe 文档。

详情

作者的原始描述

Build or review a Stripe integration with current Stripe guidance: Checkout Sessions, Payment Element, Setup Intents, subscriptions and the Customer Portal, webhook-driven fulfillment, idempotency, restricted API keys and Stripe Tax. Use when: stripe, payments, checkout, subscription, billing, webhook, refund, payment intent.

repo: davila7/claude-code-templates

热度

GitHub 星标
33k
排名
#8802
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能