Unified API client for payments, subscriptions, and more
Project description
OneRouter Python SDK
Official Python SDK for OneRouter - Unified API for payments, subscriptions, and more.
Installation
pip install onerouter
Quick Start
from onerouter import OneRouter
# Initialize client
client = OneRouter(api_key="unf_live_xxx")
# Create payment
order = await client.payments.create(
amount=500.00,
currency="INR"
)
print(f"Order ID: {order['transaction_id']}")
print(f"Checkout URL: {order['checkout_url']}")
Features
- ✅ Unified API: Single interface for Razorpay, PayPal, Stripe, etc.
- ✅ Automatic Retries: Built-in retry logic with exponential backoff
- ✅ Idempotency: Prevent duplicate payments automatically
- ✅ Type Hints: Full type support for better IDE autocomplete
- ✅ Error Handling: Comprehensive exception hierarchy
- ✅ Async & Sync: Support for both async/await and synchronous code
Usage Examples
Async Usage (Recommended)
import asyncio
from onerouter import OneRouter
async def main():
async with OneRouter(api_key="unf_live_xxx") as client:
# Create payment
order = await client.payments.create(
amount=500.00,
currency="INR",
receipt="order_123"
)
# Get payment status
status = await client.payments.get(order['transaction_id'])
# Create refund
refund = await client.payments.refund(
payment_id=order['provider_order_id'],
amount=100.00 # Partial refund
)
asyncio.run(main())
Sync Usage (for non-async code)
from onerouter import OneRouterSync
client = OneRouterSync(api_key="unf_live_xxx")
try:
# Create payment (no await needed)
order = client.payments.create(
amount=500.00,
currency="INR"
)
print(f"Order: {order['transaction_id']}")
finally:
client.close()
Subscriptions
# Create subscription
subscription = await client.subscriptions.create(
plan_id="plan_monthly_99",
customer_notify=True,
total_count=12
)
# Get subscription
sub_details = await client.subscriptions.get(subscription['id'])
# Cancel subscription
await client.subscriptions.cancel(
subscription_id=subscription['id'],
cancel_at_cycle_end=True
)
Payment Links
# Create payment link
link = await client.payment_links.create(
amount=999.00,
description="Premium Plan",
customer_email="user@example.com"
)
print(f"Share this link: {link['short_url']}")
Error Handling
from onerouter import (
OneRouter,
AuthenticationError,
RateLimitError,
ValidationError,
APIError
)
async with OneRouter(api_key="unf_live_xxx") as client:
try:
order = await client.payments.create(amount=500.00)
except AuthenticationError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limit exceeded. Retry after {e.retry_after} seconds")
except ValidationError as e:
print(f"Validation error: {e}")
except APIError as e:
print(f"API error ({e.status_code}): {e}")
Configuration
client = OneRouter(
api_key="unf_live_xxx",
base_url="https://api.onerouter.com", # Optional: Custom API URL
timeout=30, # Optional: Request timeout (seconds)
max_retries=3 # Optional: Max retry attempts
)
API Reference
Payments
| Method | Description |
|---|---|
payments.create() |
Create a payment order |
payments.get(transaction_id) |
Get payment details |
payments.refund(payment_id, amount) |
Create refund |
Subscriptions
| Method | Description |
|---|---|
subscriptions.create() |
Create subscription |
subscriptions.get(subscription_id) |
Get subscription details |
subscriptions.cancel(subscription_id) |
Cancel subscription |
Payment Links
| Method | Description |
|---|---|
payment_links.create() |
Create payment link |
Testing
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=onerouter tests/
Support
- Documentation: https://docs.onerouter.com
- GitHub: https://github.com/onerouter/onerouter-python
- Email: support@onerouter.com
License
MIT License - see LICENSE file for details
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
onerouter-1.0.0.tar.gz
(10.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
onerouter-1.0.0-py3-none-any.whl
(10.1 kB
view details)
File details
Details for the file onerouter-1.0.0.tar.gz.
File metadata
- Download URL: onerouter-1.0.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.32.5 requests-toolbelt/1.0.0 urllib3/2.5.0 tqdm/4.67.1 importlib-metadata/6.11.0 keyring/25.6.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f32f9a4e5c019145d38affa1c4567de9910928bc8f9168ea99ee190a2ab94c0
|
|
| MD5 |
d372801ae993f7488cefc4ff703fdfcb
|
|
| BLAKE2b-256 |
a135dce5672baac489f3c54bc000b609e3c46022addd96ebcc98951d891cc494
|
File details
Details for the file onerouter-1.0.0-py3-none-any.whl.
File metadata
- Download URL: onerouter-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.32.5 requests-toolbelt/1.0.0 urllib3/2.5.0 tqdm/4.67.1 importlib-metadata/6.11.0 keyring/25.6.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a48110f251985fdf27f9f5bb0a640994d2adb8afe88ec44f2f5690d3d1fc28f
|
|
| MD5 |
93280f160efe21a07d93484dcd0a556e
|
|
| BLAKE2b-256 |
aacd66d60422faab57818bc1b873ee2e41f1f309676b31b4e078f211c07cd1f8
|