stripe-integration
暂无简介
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-05
- Stars
- ★ 1
- Forks
- 0
03 SKILL.md 正文
Stripe Integration Patterns for Next.js
Official patterns from Stripe engineering.
Setup
npm install stripe @stripe/stripe-js
// src/lib/payments/stripe.ts — server-side client
import Stripe from 'stripe';
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
apiVersion: '2024-12-18.acacia',
typescript: true,
});
// src/lib/payments/stripe-client.ts — client-side
import { loadStripe } from '@stripe/stripe-js';
export const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!);
Checkout Session Pattern
// app/api/billing/stripe/checkout/route.ts
import { stripe } from '@/lib/payments/stripe';
import { getServerSession } from '@/lib/auth/session';
export async function POST(req: NextRequest) {
const session = await getServerSession();
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
const checkoutSession = await stripe.checkout.sessions.create({
mode: 'subscription',
customer_email: session.user.email,
line_items: [{ price: priceId, quantity: 1 }],
success_url: `${process.env.NEXT_PUBLIC_APP_URL}/billing?success=true`,
cancel_url: `${process.env.NEXT_PUBLIC_APP_URL}/billing`,
metadata: { userId: session.user.id },
});
return NextResponse.json({ url: checkoutSession.url });
}
Webhook Handler (Critical)
// app/api/billing/stripe/webhook/route.ts
import { stripe } from '@/lib/payments/stripe';
import { headers } from 'next/headers';
export async function POST(req: NextRequest) {
const body = await req.text();
const signature = headers().get('stripe-signature')!;
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(
body,
signature,
process.env.STRIPE_WEBHOOK_SECRET!
);
} catch {
return NextResponse.json({ error: 'Invalid signature' }, { status: 400 });
}
switch (event.type) {
case 'checkout.session.completed':
await handleCheckoutCompleted(event.data.object);
break;
case 'customer.subscription.updated':
await handleSubscriptionUpdated(event.data.object);
break;
case 'customer.subscription.deleted':
await handleSubscriptionCanceled(event.data.object);
break;
}
return NextResponse.json({ received: true });
}
Subscription Plans (Kalmeron mapping)
// Map Kalmeron plans to Stripe price IDs
const PLAN_PRICE_MAP = {
starter: process.env.STRIPE_PRICE_STARTER!,
pro: process.env.STRIPE_PRICE_PRO!,
enterprise: process.env.STRIPE_PRICE_ENTERPRISE!,
} as const;
Customer Portal
// app/api/billing/stripe/portal/route.ts
const portalSession = await stripe.billingPortal.sessions.create({
customer: stripeCustomerId,
return_url: `${process.env.NEXT_PUBLIC_APP_URL}/billing`,
});
return NextResponse.redirect(portalSession.url);
Kalmeron Context
Kalmeron's primary payment processor is Fawry (Egypt-specific). Stripe is a secondary option for international users.
Existing Fawry integration: app/api/billing/fawry/checkout/route.ts
Fawry dialog component: components/billing/FawryDialog.tsx
When adding Stripe:
- Add to Replit Secrets:
STRIPE_SECRET_KEY,STRIPE_PUBLISHABLE_KEY,STRIPE_WEBHOOK_SECRET - Create new routes under
app/api/billing/stripe/ - Add Stripe option to
FawryDialog.tsxor createStripeDialog.tsx - Update
registry.ts— addstripe-integrationtocfo_agent
Security Notes
- Never log full Stripe events (contain PII)
- Always verify webhook signatures with
constructEvent() - Store
stripeCustomerIdin Firestore, never in client state - Use
stripe.webhooks.constructEvent()with raw body (not parsed JSON)
04 同仓库更多 Skills
skill-creator
To create new CLI skills following Anthropic's official best practices with zero manual configuration. This skill automates brainstorming, template application, validation, and installation processes while maintaining progressive disclosure patterns and writing style standards.
business-investment-advisor
Business investment analysis and capital allocation advisor. Use when evaluating whether to invest in equipment, real estate, a new business, hiring, technology, or any capital expenditure. Also use for ROI calculations, IRR, NPV, payback period, build vs buy decisions, lease vs buy analysis, vendor evaluation, or deciding where to allocate limited budget for maximum return.
add-new-agent
خطوات تفصيليّة لإضافة وكيل ذكاء اصطناعي جديد إلى منصّة Kalmeron من الفكرة إلى الإنتاج
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
writing-plans
Use when you have a spec or requirements for a multi-step task, before touching code
web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".