onerouterjs-sdk
v2.0.5
Published
TypeScript SDK for OneRouter API - Works in any JavaScript runtime
Downloads
149
Maintainers
Readme
OneRouter JavaScript SDK - Quick Guide
TypeScript SDK for OneRouter API - Works in ANY JavaScript Runtime
✨ What's Included
- 💳 Payments: Create orders, capture payments, process refunds
- 🔄 Subscriptions: Create, manage, pause/resume subscriptions
- 🔗 Payment Links: Generate shareable payment links
- 💰 Payouts: Process vendor payouts
- 📱 SMS: Send SMS via Twilio integration
- 📧 Email: Send emails via Resend integration
- 🛡️ Type Safety: Full TypeScript support with autocomplete
- 🚀 Any Runtime: Node.js, Deno, Edge functions, browsers
Installation
npm install onerouter-js
# Or
yarn add onerouter-js
# Or
pnpm add onerouter-jsQuick Start
import { OneRouter } from 'onerouter-js';
const client = new OneRouter({ apiKey: 'your_api_key' });
// Create payment
const order = await client.payments.create({
amount: 500.00,
currency: 'INR'
});
console.log('✅ Order:', order.transaction_id);
console.log('📋 Checkout:', order.checkout_url);That's it! Your first payment is created.
Why TypeScript SDK?
| Feature | Python SDK | TypeScript SDK |
|----------|-------------|----------------|--------------|
| Type Safety | ⚠️ Runtime checks | ✅ Full TypeScript |
| Any Runtime | ⚠️ Python 3.8+ required | ✅ Node.js, Deno, Edge functions |
| Dependencies | httpx, httpx (heavy) | fetch (lightweight) |
| Type Hints | ⚠️ Limited | ✅ Full autocomplete |
| Bundle Size | ~10MB (httpx) | <1MB (native fetch) |
| Installation | pip install | npm install | npm install |
Quick Example
1. Create Payment
const order = await client.payments.create({
amount: 500.00,
currency: 'INR',
receipt: 'order_123'
});
console.log('Order ID:', order.transaction_id);
console.log('Checkout URL:', order.checkout_url);2. Get Payment Details
const details = await client.payments.get(order.transaction_id);
console.log('Status:', details.status);
console.log('Provider:', details.provider);
console.log('Amount:', details.amount);3. Create Subscription
const subscription = await client.subscriptions.create({
plan_id: 'plan_monthly_99',
customer_notify: true,
total_count: 12
});
console.log('Subscription:', subscription.subscription_id);
console.log('Plan:', subscription.plan_id);
console.log('Cycle:', subscription.current_cycle);4. Create Payment Link
// Create Razorpay payment link
const razorpayLink = await client.paymentLinks.create({
amount: 1000,
description: "Product Purchase",
provider: "razorpay",
environment: "test"
});
console.log('Razorpay Checkout:', razorpayLink.checkout_url);
// Create PayPal payment link
const paypalLink = await client.paymentLinks.create({
amount: 10,
description: "Credit Purchase",
provider: "paypal",
environment: "test"
});
console.log('PayPal Checkout:', paypalLink.checkout_url);6. Send Email
const emailResult = await client.email.send({
to: "[email protected]",
subject: "Welcome to OneRouter!",
html_body: "<h1>Welcome!</h1><p>Thank you for signing up.</p>",
text_body: "Welcome! Thank you for signing up."
});
console.log('✅ Email sent:', emailResult.email_id);
console.log('📧 Status:', emailResult.status);7. Handle Error
try {
const order = await client.payments.create({ amount: 500.00, currency: 'INR' });
} catch (error) {
if (error.name === 'AuthenticationError') {
console.error('❌ Invalid API key');
} else if (error.name === 'RateLimitError') {
console.error('⚠️ Rate limit exceeded. Retry later');
} else {
console.error('❌ Error:', error.message);
}
}Platform Examples
Next.js API Route
// app/api/payments/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { OneRouter } from '@onerouter/sdk';
const client = new OneRouter({ apiKey: process.env.ONEROUTER_API_KEY! });
export async function POST(request: NextRequest) {
const { amount, currency } = await request.json();
const order = await client.payments.create({
amount,
currency: currency || 'USD'
});
return NextResponse.json(order);
}Edge Function (Vercel/Cloudflare)
// pages/api/pay.ts (Edge function)
import { OneRouter } from '@onerouter/sdk';
export default async function handlePayment(request: Request) {
const { amount, currency } = await request.json();
const order = await client.payments.create({
amount,
currency: currency || 'USD'
});
return Response.json(order);
}Serverless Function (AWS Lambda)
// lambda/payments.js (AWS Lambda)
import { OneRouter } from '@onerouter/sdk';
export const handler = async (event) => {
const { amount, currency } = JSON.parse(event.body);
const order = await client.payments.create({
amount,
currency
});
return {
statusCode: 200,
body: JSON.stringify(order)
};
};Ready!
This TypeScript SDK is production-ready for any JavaScript runtime! It includes full TypeScript support for payments, subscriptions, SMS, and email functionality.
