spencerpauly/awesome-cursor-skills

adding-stripe

Integrate Stripe payments into a web application, including checkout sessions, webhooks, and customer portal.

查看源码

使用方法

  1. 复制安装命令,在自己的智能体环境安装前先检查源码包。
  2. 从原始文档核对所需工具、凭据和支持的宿主。
  3. 说明输入材料与期望交付物,并对照来源检查输出。
npx skills add https://github.com/spencerpauly/awesome-cursor-skills --skill adding-stripe

开始前需了解

  • 安装不包含模型订阅、API 额度或访问文件的权限。
  • 仓库星数和安装量反映活跃情况,不等于独立质量或安全测试。
仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

Add Stripe Payments

Use this skill when the user asks to add payments, billing, subscriptions, or Stripe integration.

Steps

  1. Install the SDK
bash
   npm install stripe @stripe/stripe-js
  1. Add environment variables
   STRIPE_SECRET_KEY=sk_test_...
   NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
   STRIPE_WEBHOOK_SECRET=whsec_...
  1. Create a Stripe client module — create lib/stripe.ts:
ts
   import Stripe from "stripe";

   export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
     apiVersion: "2024-12-18.acacia",
   });
  1. Create a checkout API route — create an endpoint that creates a Stripe Checkout session:
ts
   const session = await stripe.checkout.sessions.create({
     mode: "subscription", // or "payment" for one-time
     payment_method_types: ["card"],
     line_items: [{ price: priceId, quantity: 1 }],
     success_url: `${origin}/success?session_id={CHECKOUT_SESSION_ID}`,
     cancel_url: `${origin}/pricing`,
     customer_email: userEmail,
   });
   return redirect(session.url!);
  1. Create a webhook handler — create a POST endpoint at /api/webhooks/stripe:
  • Verify the webhook signature using stripe.webhooks.constructEvent.
  • Handle key events: checkout.session.completed, customer.subscription.updated, customer.subscription.deleted, invoice.payment_failed.
  • Update your database with the subscription status.
  1. Add customer portal (optional) — create an endpoint that redirects to stripe.billingPortal.sessions.create so users can manage their subscription.
  1. Add pricing page UI — create a pricing page with plan cards that call the checkout API route.

Notes

  • Always verify webhook signatures — never trust unverified payloads.
  • Use Stripe CLI (stripe listen --forward-to localhost:3000/api/webhooks/stripe) for local webhook testing.
  • Store the Stripe customer ID in your user database to avoid creating duplicate customers.
  • Use stripe.prices.list to fetch prices dynamically instead of hardcoding them.

按任务相关推荐

来自同一仓库

更多 Skills

全部 Skills