One API for Stripe, Razorpay, PayPal, and 25+ payment providers
Features β’ Quick Start β’ Documentation β’ Examples β’ Adapters
Problem: Payment providers have different APIs, data formats, and integration patterns. Switching providers or supporting multiple regions means rewriting your entire payment stack.
Solution: PayKit provides a single, type-safe API that works across all major payment providers. Write your integration once, swap providers instantly.
// Same code works for Stripe, Razorpay, PayPal, and 25+ providers
const charge = await paykit.charges.create({
amount: 5000,
currency: 'usd',
metadata: { orderId: 'order_123' }
});Switch providers in 2 lines:
- import { StripeAdapter } from '@squaredr/paykit/stripe';
- const paykit = new PayKit({ adapter: new StripeAdapter({ secretKey }) });
+ import { RazorpayAdapter } from '@squaredr/paykit/razorpay';
+ const paykit = new PayKit({ adapter: new RazorpayAdapter({ keyId, keySecret }) });Your business logic stays the same. No rewrites. No vendor lock-in.
|
One interface for charges, refunds, customers, subscriptions, webhooks, and payment methods across all providers Full TypeScript coverage with normalized types. IntelliSense works everywhere, catching errors at compile-time Swap providers without changing business logic. Test locally with mock adapter, deploy with real providers |
Unified webhook events regardless of provider. Write one handler for all payment events Route payments by currency, region, or custom rules. Accept INR via Razorpay, USD via Stripe automatically Drop-in |
Plus: Tree-shakeable exports β’ Official SDKs under the hood β’ Comprehensive error normalization β’ Health checks β’ Test mode support β’ Edge runtime compatible
| Package | Description | Size | npm |
|---|---|---|---|
| @squaredr/paykit | Core SDK + all adapters (Stripe, Razorpay, PayPal) | 26 KB | |
| @squaredr/paykit-react | React components & hooks | 7 KB | |
| @squaredr/paykit-js | Vanilla JS/TS frontend SDK (headless) | 4 KB |
# Install core SDK
npm install @squaredr/paykit
# Install provider SDKs (peer dependencies - choose what you need)
npm install stripe # For Stripe
npm install razorpay # For Razorpay
npm install @paypal/paypal-server-sdk # For PayPal
# For React
npm install @squaredr/paykit-reactimport { PayKit } from '@squaredr/paykit';
import { StripeAdapter } from '@squaredr/paykit/stripe';
// Initialize with your provider
const paykit = new PayKit({
adapter: new StripeAdapter({
secretKey: process.env.STRIPE_SECRET_KEY!
})
});
// Create a charge
const charge = await paykit.charges.create({
amount: 5000, // $50.00 (amounts in smallest unit)
currency: 'usd',
description: 'Premium subscription',
metadata: {
userId: 'user_123',
plan: 'premium'
}
});
// Send clientSecret to frontend
res.json({ clientSecret: charge.clientSecret });import { PayKitProvider, CheckoutForm } from '@squaredr/paykit-react';
import { StripeClientAdapter } from '@squaredr/paykit/stripe/client';
function App() {
const [clientSecret, setClientSecret] = useState('');
return (
<PayKitProvider
clientAdapter={new StripeClientAdapter(process.env.NEXT_PUBLIC_STRIPE_KEY!)}
>
<CheckoutForm
clientSecret={clientSecret}
onSuccess={(result) => {
console.log('Payment successful!', result);
// Show success message, redirect to thank you page
}}
onError={(error) => {
console.error('Payment failed:', error.message);
// Show error message
}}
appearance={{
theme: 'stripe',
variables: { colorPrimary: '#0070f3' }
}}
/>
</PayKitProvider>
);
}import express from 'express';
app.post('/webhooks', express.raw({ type: 'application/json' }), async (req, res) => {
const signature = req.headers['stripe-signature'] as string;
// Verify and parse webhook
const event = paykit.webhooks.construct({
payload: req.body,
signature,
secret: process.env.STRIPE_WEBHOOK_SECRET!
});
// Handle unified events (same for all providers!)
switch (event.type) {
case 'charge.succeeded':
await fulfillOrder(event.data.id);
break;
case 'charge.failed':
await handleFailure(event.data.id);
break;
case 'subscription.canceled':
await cancelAccess(event.data.customer);
break;
}
res.json({ received: true });
});| Provider | Status | Subpath Import | Features |
|---|---|---|---|
| Stripe | β Stable | @squaredr/paykit/stripe |
Charges, Refunds, Customers, Subscriptions, Payment Methods, Webhooks |
| Razorpay | β Stable | @squaredr/paykit/razorpay |
Charges, Refunds, Customers, Subscriptions, Payment Methods, Webhooks |
| PayPal | β Stable | @squaredr/paykit/paypal |
Charges, Refunds, Subscriptions, Payment Methods (Vault), Webhooks |
| Mock | β Stable | @squaredr/paykit/testing |
Full API simulation for local development |
Frontend Adapters:
@squaredr/paykit/stripe/client- Stripe Elements integration@squaredr/paykit/razorpay/client- Razorpay Checkout integration
Additional providers available as one-time purchase adapter bundles:
| Bundle | Price | Providers Included |
|---|---|---|
| Individual | $19 | Any single provider |
| India Pack | $49 | Cashfree, PhonePe, Paytm, BillDesk |
| Global Pack | $79 | Square, Adyen, Mollie, Braintree, Authorize.net |
| All Access | $149 | All current + future adapters (lifetime) |
Route payments intelligently based on currency or region:
import { PaymentRouter } from '@squaredr/paykit';
import { StripeAdapter } from '@squaredr/paykit/stripe';
import { RazorpayAdapter } from '@squaredr/paykit/razorpay';
const router = new PaymentRouter({
adapters: [
new StripeAdapter({ secretKey: process.env.STRIPE_SECRET_KEY! }),
new RazorpayAdapter({
keyId: process.env.RAZORPAY_KEY_ID!,
keySecret: process.env.RAZORPAY_KEY_SECRET!
})
],
rules: [
{ currency: 'inr', provider: 'razorpay' }, // INR β Razorpay
{ currency: 'usd', provider: 'stripe' }, // USD β Stripe
{ default: 'stripe' } // Fallback β Stripe
]
});
// Automatically routes to the right provider
const charge = await router.createCharge({
amount: 50000,
currency: 'inr' // Will use Razorpay
});// Create a subscription
const subscription = await paykit.subscriptions.create({
customer: 'cus_123',
amount: 2999, // $29.99/month
currency: 'usd',
interval: 'month',
intervalCount: 1
});
// Cancel subscription
await paykit.subscriptions.cancel(subscription.id);
// List customer subscriptions
const subs = await paykit.subscriptions.list({ customer: 'cus_123' });// Full refund
await paykit.refunds.create({
chargeId: 'ch_123',
reason: 'Customer requested'
});
// Partial refund
await paykit.refunds.create({
chargeId: 'ch_123',
amount: 2500, // $25.00
reason: 'Partial order cancellation'
});import { PaymentError } from '@squaredr/paykit';
try {
await paykit.charges.create({ amount, currency });
} catch (error) {
if (error instanceof PaymentError) {
switch (error.code) {
case 'card_declined':
// Show user-friendly message
break;
case 'insufficient_funds':
// Suggest alternative payment method
break;
case 'authentication_required':
// Trigger 3D Secure flow
break;
default:
// Generic error handling
}
}
}ββββββββββββββββββββββββββββββββββββββββββββ
β Your Application Layer β
β (Express, Next.js, Fastify, etc.) β
βββββββββββββββββββ¬βββββββββββββββββββββββββ
β
v
ββββββββββββββββββββββββββββββββββββββββββββ
β @squaredr/paykit (Core) β
β β’ PayKit Client β
β β’ Unified Types & Interfaces β
β β’ Payment Router β
β β’ Error Normalization β
βββββββββββββββββββ¬βββββββββββββββββββββββββ
β
ββββββββββββ΄βββββββββββ¬βββββββββββββββ
v v v
βββββββββββββββ βββββββββββββββ ββββββββββββββββ
β Stripe β β Razorpay β β PayPal β
β Adapter β β Adapter β β Adapter β
ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬ββββββββ
β β β
v v v
βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββ
β stripe β β razorpay β β @paypal/paypal- β
β (npm) β β (npm) β β server-sdk (npm) β
β Peer Dep β β Peer Dep β β Peer Dep β
βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββ
How it works:
- Your app uses PayKit's unified API
- PayKit routes to the appropriate adapter
- Adapter translates to provider's native SDK
- Provider SDK makes actual API calls
- Response is normalized back to PayKit types
Benefits:
- β Use official SDKs under the hood (not reinventing the wheel)
- β Swap providers without code changes
- β Test locally with mock adapter
- β Tree-shake unused adapters (only bundle what you use)
- Node.js >= 20.0.0
- pnpm >= 9.15.3 (recommended) or npm >= 11.0.0
git clone https://github.com/SquaredR98/paykit.git
cd paykit
pnpm install
pnpm run build
pnpm testpaykit/
βββ packages/
β βββ core/ # @squaredr/paykit (SDK + all adapters)
β β βββ src/
β β β βββ adapters/
β β β β βββ stripe/ # Stripe adapter + client
β β β β βββ razorpay/ # Razorpay adapter + client
β β β β βββ paypal/ # PayPal adapter
β β β βββ types/ # Unified types
β β β βββ index.ts # Main exports
β β βββ package.json
β βββ sdk-js/ # @squaredr/paykit-js (frontend SDK)
β βββ react/ # @squaredr/paykit-react (React components)
βββ website/ # Documentation site (Fumadocs)
βββ turbo.json
βββ package.json
pnpm run build # Build all packages
pnpm test # Run all tests (252 passing)
pnpm run test:watch # Watch mode
pnpm run typecheck # Type check all packages
pnpm run lint # Lint with Biome
pnpm run lint:fix # Auto-fix linting issues
pnpm run clean # Clean build artifactsAll packages use Vitest.
# Run all tests
pnpm test
# Test specific package
pnpm test --filter @squaredr/paykit
# Watch mode
pnpm test:watch
# Coverage
pnpm test --coverageFull documentation: squaredr.tech/products/paykit/docs
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- π Bug fixes and issue reports
- π Documentation improvements
- β¨ Feature requests and RFC discussions
- π§ͺ Test coverage expansion
- π Internationalization
MIT License - see LICENSE for details.
β
Core SDK (@squaredr/paykit)
β
All included adapters (Stripe, Razorpay, PayPal)
β
React components (@squaredr/paykit-react)
β
JS SDK (@squaredr/paykit-js)
β
Mock/testing adapter
β
Full source code
β
Commercial use allowed
β
No attribution required
Additional provider adapters (Square, Adyen, Cashfree, etc.) are available as one-time purchase adapter bundles. No subscriptions, no vendor lock-in.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Docs: squaredr.tech/products/paykit/docs
- Email: support@squaredr.tech
- Twitter: @SquaredRDev
If PayKit saves you time and effort, please consider:
- β Starring the repo
- π¦ Sharing on Twitter
- π Writing a blog post about your experience
- π¬ Joining our community discussions
- β Core SDK with Stripe & Razorpay
- β React components
- β PayPal adapter (official SDK migration)
- π§ Documentation site
- π Square adapter (paid)
- π Adyen adapter (paid)
- π India Pack (Cashfree, PhonePe, Paytm)
- π Global Pack (Mollie, Braintree, Authorize.net)
- π Advanced routing rules
- π Payment analytics dashboard
- π Mobile SDKs (React Native, Flutter)
- π Serverless framework plugins
- π CLI for provider migration
Built with β€οΈ by SquaredR
Website β’ Documentation β’ GitHub β’ npm
