Mockrithm Docs

Stripe Payment Processing & Subscriptions

This page documents the integration of Stripe payment gateways inside Mockrithm to manage subscriptions and pricing plans.


1. Checkout & Monetization Flow

Mockrithm utilizes Stripe Checkout to process subscription upgrades.

graph TD
    User[Candidate Dashboard] -->|Click Upgrade| Route[Next.js API: Initialize Checkout Session]
    Route -->|Call Stripe API| StripeCheckout[Redirect to Stripe Checkout Page]
    StripeCheckout -->|User Pays & Completes| RedirectSuccess[Redirect to /payment/success]
    StripeCheckout -->|User Cancels| RedirectCancel[Redirect to /payment/cancel]
    
    StripeCheckout -->|Async Event: checkout.session.completed| Webhook[Stripe Webhook Endpoint]
    Webhook -->|Verify Signature| UpdateDB[Update Firestore user tier: premium/pro]

2. Stripe Session Initialization Implementation

Below is the implementation code for initializing a Stripe Checkout session (app/api/payment/session/route.ts):

import { NextRequest, NextResponse } from "next/server";
import { auth } from "@clerk/nextjs/server";
import Stripe from "stripe";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
  apiVersion: "2023-10-16" as any,
});

export async function POST(request: NextRequest) {
  try {
    const { userId } = await auth();
    if (!userId) {
      return new NextResponse("Unauthorized request", { status: 401 });
    }

    const { priceId } = await request.json();
    if (!priceId) {
      return NextResponse.json({ error: "Missing priceId parameter" }, { status: 400 });
    }

    // Initialize Stripe Checkout session
    const session = await stripe.checkout.sessions.create({
      payment_method_types: ["card"],
      line_items: [
        {
          price: priceId,
          quantity: 1,
        },
      ],
      mode: "subscription",
      success_url: `${process.env.NEXT_PUBLIC_APP_URL}/payment/success?session_id={CHECKOUT_SESSION_ID}`,
      cancel_url: `${process.env.NEXT_PUBLIC_APP_URL}/payment/cancel`,
      metadata: {
        userId: userId, // Pass Clerk ID to match in webhook callback
      },
    });

    return NextResponse.json({ url: session.url });

  } catch (error) {
    console.error("Failed to initialize checkout session:", error);
    return NextResponse.json({ error: "Checkout session initialization failed" }, { status: 500 });
  }
}

3. Product & Price Mapping IDs

Configure your local environment and Stripe product catalogs using the parameters below:

Plan TierPrice ID Parameter (Stripe Console)Monthly CostPlatform Capabilities Unlocked
FreemiumDefault (null)$0/mo1 AI voice session, basic pacing analysis.
Premiumprice_1PzExamplePremium$10/moUnlimited voice sessions, filler word audits, and ATS checker reports.
Proprice_1PzExamplePro$25/moCustom resume templates, resume exports, and API keys.

4. Security & Best Practices

Metadata Tracking

Always include the candidate's authenticated Clerk userId inside the Stripe Checkout session metadata properties. When the asynchronous webhook payload arrives, the system uses this ID to identify which user profile to upgrade.

On this page