Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Stripe Payments: Checkout, Subscriptions & Webhooks

    1

    Implement secure Stripe Checkout, subscriptions, and webhook handlers with signature verification and idempotency.

    Free

    Security scanned
    Stripe Payments: Checkout, Subscriptions & Webhooks

    Stripe Payments: Checkout, Subscriptions & Webhooks

    Example session with this skill installed

    Add a Stripe subscription checkout to my Next.js app. I need a Pro plan at $20/month, trial period of 14 days, and a webhook to handle the fulfillment.

    • Read your context and instructions
    • Compiled the stripe payments

    I have implemented the Stripe subscription flow using Next.js API routes and the Stripe SDK. This includes a checkout session creator with a 14-day trial and a secure webhook handler to manage user entitlements.

    Stripe Subscription Integration

    // app/api/stripe/checkout/route.ts
    import { stripe } from "@/lib/stripe";
    import { NextResponse } from "next/server";
    
    export async function POST(req: Request) {
      const { userId, email } = await req.json();
    
      const session = await stripe.checkout.sessions.create({
        customer_email: email,
        line_items: [{ price: process.env.STRIPE_PRO_PRICE_ID, quantity: 1 }],
        mode: "subscription",
        subscription_data: { trial_period_days: 14 },
        success_url: `${process.env.NEXT_PUBLIC_APP_URL}/dashboard?session_id={CHECKOUT_SESSION_ID}`,
        cancel_url: `${process.env.NEXT_PUBLIC_APP_URL}/pricing`,
        client_reference_id: userId,
        metadata: { userId },
      });
    
      return NextResponse.json({ url: session.url });
    }
    
    // app/api/stripe/webhook/route.ts
    export async function POST(req: Request) {
      const body = await req.text();
      const signature = req.headers.get("stripe-signature") as string;
      let event;
    
      try {
        event = stripe.webhooks.constructEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET!);
      } catch (err) {
        return new Response(`Webhook Error: ${err.message}`, { status: 400 });
      }
    
      // Handle idempotency by checking event.id in DB here
      switch (event.type) {
        case "checkout.session.completed":
          const session = event.data.object;
          await updateUserSubscription(session.client_reference_id, session.customer);
          break;
        case "invoice.paid":
          await extendAccess(event.data.object.customer);
          break;
        case "customer.subscription.deleted":
          await revokeAccess(event.data.object.customer);
          break;
      }
    
      return new Response(null, { status: 200 });
    }
    

    Next steps

    1. Add STRIPE_PRO_PRICE_ID and STRIPE_WEBHOOK_SECRET to your .env.local.
    2. Run stripe listen --forward-to localhost:3000/api/stripe/webhook to test the fulfillment logic.
    3. Use the test card 4242 4242 4242 4242 to verify the 14-day trial checkout flow.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Integrating payments is a high-stakes task where small errors in webhook logic or idempotency lead to lost revenue and broken entitlements. This skill implements Stripe integrations correctly from the start, ensuring your backend handles the subscription lifecycle without relying on fragile client-side redirects.

    What it does

    • Multi-flow integration implements Stripe Checkout for fast deployment or Payment Element for custom UI.
    • Subscription management handles trials, coupons, upgrades, downgrades, and the Customer Portal.
    • Webhook orchestration builds signature-verified handlers for session completion, successful payments, and failures.
    • Database syncing maps local users to Stripe customer IDs and tracks subscription statuses.
    • Test-driven verification provides specific Stripe CLI commands and test card numbers for all edge cases.

    How it works

    1. Selection defines if the app needs one-time payments, subscriptions, or a marketplace Connect setup.
    2. Environment config sets up the necessary secret keys, publishable keys, and webhook secrets in .env.example.
    3. Route implementation creates the server-side Checkout Session or PaymentIntent and the corresponding client-side trigger.
    4. Webhook hardening writes the handler to process events like invoice.paid with idempotency and signature checks.
    5. Validation runs a suite of tests using the Stripe CLI to simulate successful and failed payment flows.

    Frameworks & tools

    Supports Next.js, Nuxt, Express, FastAPI, Django, and Laravel. Uses the official Stripe SDKs and the Stripe CLI for local development.

    Why this beats prompting it yourself

    Most LLMs default to client-side logic that fails if a user closes their browser before the redirect. This skill enforces a webhook-first architecture, ensuring your database stays in sync with Stripe's actual state regardless of browser behavior.

    Use cases

    • Add a SaaS pricing page with monthly and yearly subscription tiers.
    • Build a checkout flow that handles automatic tax calculation and promo codes.
    • Implement a customer billing portal for self-service plan management.
    • Debug a failing webhook integration that is missing signature verification.

    Known limitations

    Does not handle physical shipping logistics or inventory management. Requires a Stripe account and the Stripe CLI installed for local webhook testing.

    Requires Stripe CLI for local webhook testing. User must manually create Products and Prices in the Stripe Dashboard or provide IDs.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free forever

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 1 day ago

    • Free with an Agensi account

    Permissions

    Terminal / Shell
    Network Access
    Listed1 day ago

    What's inside

    Frequently Asked Questions

    This skill automates the setup of Stripe Checkout, subscription tiers, and robust webhook listeners, specifically solving the common problem of database desyncs caused by users closing browsers before a redirect completes.

    It is designed for modern full-stack environments, offering native support for Next.js, Nuxt, Express, FastAPI, Django, and Laravel using official Stripe SDKs.

    You will receive the pre-configured AI skill logic, a blueprint for server-side route implementation, and a comprehensive suite of Stripe CLI commands for local testing and validation.

    Yes, the skill includes logic for managing the Stripe Customer Portal, allowing your users to self-serve upgrades, downgrades, and billing updates without manual intervention.

    The skill provides a guided environment configuration for your secret keys and detailed instructions for using the Stripe CLI to simulate and verify real-time payment events locally.

    This skill enforces a webhook-first architecture with signature verification and idempotency keys, ensuring your integration is production-ready and resistant to duplicate events or spoofing.

    New in APIs & Backend