razorpay_dart 0.0.3
razorpay_dart: ^0.0.3 copied to clipboard
A Dart package for interacting with the Razorpay API.
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.