You want to accept payments in your Node.js app. You install Stripe's SDK, write charge creation logic, build a checkout form, set up webhooks. Then your product manager says "we also need Razorpay for India." Now you're maintaining two parallel integrations with different APIs, different webhook formats, and different error shapes.
PayKit eliminates that problem. One SDK, one API, every provider.
What is PayKit?
PayKit is a unified TypeScript payment SDK. You write your payment logic once — charges, refunds, webhooks, checkout — and swap providers by changing a single import. The core SDK, Stripe, Razorpay, and PayPal adapters are MIT-licensed and free.
Step 1: Install
npm install @squaredr/paykit stripeThat's it. The stripe package is a peer dependency — PayKit's adapter wraps it to provide the unified interface.
Step 2: Create your first charge
import { PayKit } from '@squaredr/paykit'
import { StripeAdapter } from '@squaredr/paykit/stripe'
export const paykit = new PayKit({
adapter: new StripeAdapter({
secretKey: process.env.STRIPE_SECRET_KEY!,
}),
})import { paykit } from '@/lib/paykit'
export async function POST(request: Request) {
const { amount, currency } = await request.json()
const charge = await paykit.charges.create({
amount, // in smallest unit (e.g. 5000 = $50.00)
currency,
metadata: { source: 'website' },
})
return Response.json({
clientSecret: charge.clientSecret,
})
}The clientSecret is passed to your frontend to confirm the payment using Stripe's Payment Element.
Step 3: Frontend checkout
'use client'
import { PayKitProvider, CheckoutForm } from '@squaredr/paykit-react'
import { StripeClientAdapter } from '@squaredr/paykit/stripe/client'
const stripeClient = new StripeClientAdapter(
process.env.NEXT_PUBLIC_STRIPE_PK!
)
export function Checkout({ clientSecret }: { clientSecret: string }) {
return (
<PayKitProvider clientAdapter={stripeClient} clientSecret={clientSecret}>
<CheckoutForm
onSuccess={(result) => console.log('Paid:', result.id)}
onError={(err) => console.error(err.message)}
/>
</PayKitProvider>
)
}PayKitProvider loads the provider's script, mounts the payment form, and handles confirmation. You get onSuccess and onError callbacks — no provider-specific code needed.
Step 4: Switch to Razorpay
Here's where PayKit shines. To switch from Stripe to Razorpay, change one file:
import { PayKit } from '@squaredr/paykit'
import { RazorpayAdapter } from '@squaredr/paykit/razorpay'
export const paykit = new PayKit({
adapter: new RazorpayAdapter({
keyId: process.env.RAZORPAY_KEY_ID!,
keySecret: process.env.RAZORPAY_KEY_SECRET!,
}),
})Your checkout route, webhook handler, and frontend component stay exactly the same. paykit.charges.create() now creates a Razorpay order instead of a Stripe PaymentIntent — but the return shape is identical.
Step 5: Handle webhooks
Payment events (successful charge, failed charge, refund) arrive via webhooks. PayKit normalises every provider's webhook payload into a unified event:
import { paykit } from '@/lib/paykit'
export async function POST(request: Request) {
const payload = await request.text()
const signature = request.headers.get('stripe-signature')!
const event = paykit.webhooks.construct({
payload,
signature,
secret: process.env.STRIPE_WEBHOOK_SECRET!,
})
switch (event.type) {
case 'charge.succeeded':
// fulfil the order
break
case 'charge.failed':
// notify the customer
break
}
return new Response('ok', { status: 200 })
}Whether the webhook comes from Stripe (payment_intent.succeeded) or Razorpay (payment.captured), your handler sees charge.succeeded. PayKit maps 22 event types across all providers.
What's next?
You now have a working payment integration that can switch providers with a single line change. From here:
- Multi-provider routing — run Stripe for USD and Razorpay for INR simultaneously using
PaymentRouter - Webhook deep dive — idempotency patterns, multi-provider webhook routing, and local testing
- Try the interactive demos — see PayKit in action with live Stripe and Razorpay checkout flows
PayKit is open source on GitHub. The core SDK and three provider adapters (Stripe, Razorpay, PayPal) are free and MIT-licensed.