razorpay_dart
A Dart package for interacting with the Razorpay API, ported from the official razorpay-node library.
⚠️ Warning: Early Stage Package ⚠️
This package is currently in its early stages of development. While functional, it may contain bugs or incomplete features. Thorough testing is required before considering its use in a production environment. Contributions and feedback are highly welcome!
Features
- Provides Dart interfaces for common Razorpay API endpoints:
- Orders
- Payments
- Refunds
- Customers
- Invoices
- Payment Links
- Settlements
- Transfers
- Virtual Accounts
- Utility functions for signature verification.
- Type-safe models for API requests and responses (using
freezed
).
Getting Started
Prerequisites
- Flutter SDK: >= 3.0.0 (or Dart SDK >= 3.0.0 for non-Flutter projects)
- A Razorpay account and API keys (Sign up here)
Installation
Add razorpay_dart
to your pubspec.yaml
dependencies:
dependencies:
razorpay_dart: ^0.0.3 # Use the latest version
Then, run flutter pub get
(or dart pub get
).
Usage
Import the package and initialize the Razorpay client:
import 'package:razorpay_dart/razorpay_dart.dart';
void main() async {
// Replace with your actual Key ID and Key Secret
const keyId = 'TEST_KEY_ID';
const keySecret = 'TEST_KEY_SECRET';
final razorpay = Razorpay(keyId: keyId, keySecret: keySecret);
// Create a plan
final plan = await razorpay.plans.create(
params: const RazorpayPlanCreateRequestBody(
interval: 12,
item: RazorpayItemBaseRequestBody(
name: 'Test Plan',
amount: 1000,
currency: 'INR',
),
period: PlanPeriod.monthly,
notes: {
'key': 'value',
},
),
);
print(plan.toJson());
// Get a plan
final singlePlan = await razorpay.plans.fetch(planId: plan.id);
print(singlePlan.toJson());
final getAllPlans = await razorpay.plans.all();
print(getAllPlans.toJson((value) => value.toJson()));
}
API Reference
The library aims to mirror the structure of the razorpay-node
library. You can interact with different Razorpay entities through the Razorpay
instance:
razorpay.orders
razorpay.payments
razorpay.refunds
razorpay.customers
razorpay.invoices
razorpay.paymentLinks
razorpay.settlements
razorpay.transfers
razorpay.virtualAccounts
razorpay.utils
(for signature verification)razorpay.utils.verifyPaymentSignature(...)
razorpay.utils.verifyWebhookSignature(...)
Detailed documentation for each API method is planned for future releases. For now, please refer to the source code and the official Razorpay API Documentation.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name
). - Make your changes.
- Add tests for your changes.
- Ensure all tests pass (
flutter test
). - Format your code (
dart format .
). - Commit your changes (
git commit -am 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature-name
). - Create a new Pull Request.
Testing
Run tests using:
flutter test
License
This package is licensed under the MIT License - see the LICENSE file for details.
Libraries
- api
- models/accounts_model
- models/addons_model
- models/api_model
- models/cards_model
- models/customers_model
- models/disputes_model
- models/documents_model
- models/error_model
- models/fund_account_model
- models/iins_model
- models/invoices_model
- models/items_model
- models/models
- models/oauth_token_model
- models/orders_model
- models/payment_link_model
- models/payments_model
- models/plans_model
- models/products_model
- models/qr_code_model
- models/refunds_model
- models/settlements_model
- models/stakeholders_model
- models/subscriptions_model
- models/tokens_model
- models/transfers_model
- models/virtual_accounts_model
- models/webhooks_model
- oauth_token_client
- razorpay_dart
- resources/accounts
- resources/addons
- resources/cards
- resources/customers
- resources/disputes
- resources/documents
- resources/fund_account
- resources/iins
- resources/invoices
- resources/items
- resources/orders
- resources/payment_link
- resources/payments
- resources/plans
- resources/products
- resources/qr_code
- resources/refunds
- resources/resources
- resources/settlements
- resources/stakeholders
- resources/subscriptions
- resources/tokens
- resources/transfers
- resources/virtual_accounts
- resources/webhooks
- utils