razorpay_web
Razorpay SDK용 Flutter 플러그인입니다. Android, iOS, Web, Windows, Linux, macOS를 지원합니다.
gauravmehta13/razorpay_web open-source repository details.
{"sdk":"flutter"}{"sdk":"flutter"}^1.0.1^9.0.0^1.1.0^1.1.1^6.2.0-beta.3{"sdk":"flutter"}^1.26.3^6.0.0아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
pub package License: MIT Flutter Platform
Android • iOS • Web • Windows • Linux • macOS
Getting Started • Installation • Usage • API Reference • Examples
As a full-time developer working on this plugin in my limited spare time, your support means the world! Every contribution helps me dedicate more hours to:
✨ Adding new features • 🐛 Fixing bugs faster • 📚 Improving documentation • 🚀 Supporting new platforms
🌟 If this plugin saved you hours of work, consider buying me a chai!
Your support directly impacts how much time I can invest in making this plugin better for everyone.
Before integrating this plugin, you'll need:
💡 New to Razorpay? Learn about the payment flow before integrating.
Add razorpay_web to your pubspec.yaml:
dependencies:
razorpay_web: ^3.1.1
Then run:
flutter pub get
Update android/app/build.gradle:
android {
defaultConfig {
minSdkVersion 19 // Ensure this is at least 19
}
}
Add to your ProGuard configuration:
-keepattributes *Annotation*
-dontwarn com.razorpay.**
-keep class com.razorpay.** {*;}
-optimizations !method/inlining/
-keepclasseswithmembers class * {
public void onPayment*(...);
}
Update ios/Podfile:
platform :ios, '10.0'
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'YES'
config.build_settings['SWIFT_VERSION'] = '5.0'
end
end
end
Add use_frameworks! if you encounter Swift header issues:
use_frameworks!
Then run:
cd ios && pod install
Add the Razorpay checkout script to web/index.html inside the <body> tag:
<body>
<!-- Other content -->
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
No additional configuration needed! The plugin uses flutter_inappwebview to provide a native-like payment experience.
⚠️ Important: You must pass
contextparameter when callingopen()on Windows.
Uses the same WebView implementation as Windows. No additional setup required.
Uses the same WebView implementation as Windows.
Add network client permission to your entitlements files:
macos/Runner/DebugProfile.entitlements:
<key>com.apple.security.network.client</key>
<true/>
macos/Runner/Release.entitlements:
<key>com.apple.security.network.client</key>
<true/>
This is required for the WebView to load Razorpay's checkout page.
⚠️ Important: You must pass
contextparameter when callingopen()on macOS.
import 'package:flutter/material.dart';
import 'package:razorpay_web/razorpay_web.dart';
class PaymentScreen extends StatefulWidget {
@override
_PaymentScreenState createState() => _PaymentScreenState();
}
class _PaymentScreenState extends State<PaymentScreen> {
late Razorpay _razorpay;
@override
void initState() {
super.initState();
_razorpay = Razorpay();
_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError);
_razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet);
}
@override
void dispose() {
super.dispose();
_razorpay.clear();
}
void openCheckout() async {
var options = {
'key': 'rzp_test_1DP5mmOlF5G5ag',
'amount': 100, // amount in the smallest currency unit (paise)
'name': 'Acme Corp.',
'description': 'Fine T-Shirt',
'prefill': {
'contact': '8888888888',
'email': 'test@razorpay.com'
},
'external': {
'wallets': ['paytm']
}
};
try {
_razorpay.open(options, context: context);
} catch (e) {
debugPrint('Error: $e');
}
}
void _handlePaymentSuccess(PaymentSuccessResponse response) {
print('Success: ${response.paymentId}');
// Do something when payment succeeds
}
void _handlePaymentError(PaymentFailureResponse response) {
print('Error: ${response.code} - ${response.message}');
// Do something when payment fails
}
void _handleExternalWallet(ExternalWalletResponse response) {
print('External Wallet: ${response.walletName}');
// Do something when an external wallet is selected
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Razorpay Payment')),
body: Center(
child: ElevatedButton(
onPressed: openCheckout,
child: Text('Pay Now'),
),
),
);
}
}
import 'package:razorpay_web/razorpay_web.dart';
late Razorpay _razorpay;
@override
void initState() {
super.initState();
_razorpay = Razorpay();
}
The plugin uses an event-driven architecture. Attach listeners for payment events:
_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError);
_razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet);
void _handlePaymentSuccess(PaymentSuccessResponse response) {
// Payment ID: response.paymentId
// Order ID: response.orderId (if order was created)
// Signature: response.signature (for verification)
}
void _handlePaymentError(PaymentFailureResponse response) {
// Error code: response.code
// Error message: response.message
}
void _handleExternalWallet(ExternalWalletResponse response) {
// Wallet name: response.walletName
}
var options = {
'key': 'YOUR_RAZORPAY_KEY', // Required
'amount': 50000, // Required (in paise: 50000 = ₹500)
'name': 'Your Business Name',
'description': 'Product Description',
'order_id': 'order_xyz123', // Optional: for order-based payments
'prefill': {
'contact': '9876543210',
'email': 'customer@example.com'
},
'theme': {
'color': '#F37254'
}
};
📚 See all available options
// For Android, iOS, and Web
_razorpay.open(options);
// For Windows, Linux, and macOS (context required)
_razorpay.open(options, context: context);
@override
void dispose() {
super.dispose();
_razorpay.clear(); // Remove all event listeners
}
Razorpay provides test credentials for sandbox testing:
| UPI ID | Result |
|---|---|
success@razorpay |
✅ Payment Success |
failure@razorpay |
❌ Payment Failure |
| Card Number | CVV | Expiry | Result |
|---|---|---|---|
| 4111 1111 1111 1111 | Any | Future | ✅ Success |
| 4012 8888 8888 1881 | Any | Future | ✅ Success |
| 5555 5555 5555 4444 | Any | Future | ✅ Success |
💡 Tip: Use any future expiry date and any CVV for test cards.
The plugin includes comprehensive unit tests:
# Run all tests
flutter test
# Run specific test file
flutter test test/razorpay_flutter_test.dart
# Run with coverage
flutter test --coverage
📚 Learn more about Razorpay Test Mode
open(Map<String, dynamic> options, {BuildContext? context})Opens the Razorpay checkout interface.
Parameters:
options (required): Payment configuration map
key (required): Your Razorpay API keyamount (required): Amount in smallest currency unit (paise for INR)name: Business/product namedescription: Payment descriptionorder_id: Order ID for order-based paymentsprefill: Pre-filled customer detailstheme: Checkout UI customizationcontext (optional): BuildContext - Required for Windows, Linux, and macOSExample:
_razorpay.open({
'key': 'rzp_test_1DP5mmOlF5G5ag',
'amount': 100,
'name': 'Acme Corp.',
}, context: context);
on(String event, Function handler)Registers an event listener for payment events.
Parameters:
event: Event name (use constants from Razorpay class)handler: Callback function with appropriate response typeExample:
_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, (PaymentSuccessResponse response) {
print('Payment ID: ${response.paymentId}');
});
clear()Removes all event listeners. Call this in dispose() to prevent memory leaks.
Example:
@override
void dispose() {
_razorpay.clear();
super.dispose();
}
Use these constants from the Razorpay class:
| Constant | Value | Description |
|---|---|---|
EVENT_PAYMENT_SUCCESS |
"payment.success" |
Payment completed successfully |
EVENT_PAYMENT_ERROR |
"payment.error" |
Payment failed or encountered an error |
EVENT_EXTERNAL_WALLET |
"payment.external_wallet" |
External wallet was selected |
Emitted when payment succeeds.
| Property | Type | Description |
|---|---|---|
paymentId |
String? |
Unique payment identifier |
orderId |
String? |
Order ID (if order-based payment) |
signature |
String? |
Payment signature for verification (orders only) |
Methods:
toJson(): Convert response to JSON maptoString(): Get string representationExample:
void _handlePaymentSuccess(PaymentSuccessResponse response) {
print('Payment ID: ${response.paymentId}');
print('Order ID: ${response.orderId}');
print('Signature: ${response.signature}');
// Convert to JSON for backend verification
Map<String, dynamic> json = response.toJson();
}
Emitted when payment fails.
| Property | Type | Description |
|---|---|---|
code |
int? |
Error code (see error codes below) |
message |
String? |
Human-readable error message |
orderId |
String? |
Order ID (if order-based payment) |
paymentId |
String? |
Payment ID (if payment was initiated) |
Methods:
toJson(): Convert response to JSON maptoString(): Get string representationExample:
void _handlePaymentError(PaymentFailureResponse response) {
print('Error Code: ${response.code}');
print('Error Message: ${response.message}');
print('Order ID: ${response.orderId}');
// Log error details
print(response.toString());
}
Emitted when user selects an external wallet.
| Property | Type | Description |
|---|---|---|
walletName |
String? |
Name of the selected wallet (e.g., "paytm") |
Methods:
toJson(): Convert response to JSON maptoString(): Get string representationExample:
void _handleExternalWallet(ExternalWalletResponse response) {
print('Wallet: ${response.walletName}');
// Handle wallet-specific logic
if (response.walletName == 'paytm') {
// Paytm-specific handling
}
}
Access these constants from the Razorpay class:
| Constant | Value | Description |
|---|---|---|
NETWORK_ERROR |
0 |
Network connectivity issue |
INVALID_OPTIONS |
1 |
Invalid options passed to open() |
PAYMENT_CANCELLED |
2 |
User cancelled the payment |
TLS_ERROR |
3 |
Device doesn't support TLS v1.1 or v1.2 |
UNKNOWN_ERROR |
4 |
An unknown error occurred |
Example:
void _handlePaymentError(PaymentFailureResponse response) {
if (response.code == Razorpay.NETWORK_ERROR) {
print('Network error occurred');
} else if (response.code == Razorpay.PAYMENT_CANCELLED) {
print('User cancelled the payment');
}
}
void makePayment() {
var options = {
'key': 'rzp_test_1DP5mmOlF5G5ag',
'amount': 50000, // ₹500
'name': 'Product Name',
'description': 'Product Description',
};
_razorpay.open(options, context: context);
}
void makeOrderPayment() {
// First, create an order on your backend
// Then use the order_id in options
var options = {
'key': 'rzp_test_1DP5mmOlF5G5ag',
'amount': 50000,
'name': 'Product Name',
'order_id': 'order_xyz123', // Order ID from backend
'prefill': {
'contact': '9876543210',
'email': 'customer@example.com'
}
};
_razorpay.open(options, context: context);
}
void makeStyledPayment() {
var options = {
'key': 'rzp_test_1DP5mmOlF5G5ag',
'amount': 50000,
'name': 'Your Business',
'theme': {
'color': '#F37254',
'backdrop_color': '#000000'
},
'image': 'https://your-logo-url.com/logo.png',
};
_razorpay.open(options, context: context);
}
void makeWalletPayment() {
var options = {
'key': 'rzp_test_1DP5mmOlF5G5ag',
'amount': 50000,
'name': 'Product Name',
'external': {
'wallets': ['paytm', 'phonepe', 'googlepay']
}
};
_razorpay.open(options, context: context);
}
Check out the example app for a full working implementation with:
Error:
Specs satisfying the `razorpay_flutter` dependency were found, but they required a higher minimum deployment target.
Solution:
Update ios/Podfile:
platform :ios, '10.0'
Then run:
cd ios && pod install
Error:
'razorpay_flutter/razorpay_flutter-Swift.h' file not found
Solution:
Add use_frameworks! to ios/Podfile:
use_frameworks!
Then run:
cd ios && pod install
Error:
uses-sdk:minSdkVersion 16 cannot be smaller than version 19
Solution:
Update android/app/build.gradle:
defaultConfig {
minSdkVersion 19
}
Error:
BuildContext is required for Windows/Linux/macOS platform
Solution:
Always pass context when calling open() on desktop platforms:
_razorpay.open(options, context: context);
The plugin uses InAppWebView for desktop platforms, which requires a BuildContext to display the payment dialog.
Error:
onWebContentProcessDidTerminate
Solution: Add network client entitlement to both entitlements files:
macos/Runner/DebugProfile.entitlements:
<key>com.apple.security.network.client</key>
<true/>
macos/Runner/Release.entitlements:
<key>com.apple.security.network.client</key>
<true/>
Then rebuild your app:
flutter clean
flutter build macos
Error:
type 'PaymentFailureResponse' is not a subtype of type 'PaymentSuccessResponse'
Solution: Ensure your event handlers have correct signatures:
void _handlePaymentSuccess(PaymentSuccessResponse response) { }
void _handlePaymentError(PaymentFailureResponse response) { }
void _handleExternalWallet(ExternalWalletResponse response) { }
Error:
ReferenceError: Razorpay is not defined
Solution:
Ensure you've added the Razorpay script to web/index.html:
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
The script must be loaded before your Flutter app initializes.
Issue: Payment dialog doesn't appear on Windows/Linux/macOS.
Solution:
Ensure you're passing context parameter:
_razorpay.open(options, context: context);
Check that flutter_inappwebview is properly installed:
flutter pub get
flutter clean
flutter run
For Windows, verify Edge WebView2 Runtime is installed (pre-installed on Windows 10/11).
Issue: Event handlers being called multiple times or memory warnings.
Solution:
Always call clear() in your widget's dispose() method:
@override
void dispose() {
_razorpay.clear(); // Removes all event listeners
super.dispose();
}
Error:
Error Code: 1 - Invalid options
Solution: Ensure required fields are present:
var options = {
'key': 'YOUR_KEY', // Required
'amount': 100, // Required (must be integer)
'name': 'Business Name' // Recommended
};
Amount must be in smallest currency unit (paise for INR):
Contributions are welcome! Here's how you can help:
git checkout -b feature/amazing-feature)flutter test)flutter analyze)dart format .)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)# Clone the repository
git clone https://github.com/gauravmehta13/razorpay_web.git
cd razorpay_web
# Get dependencies
flutter pub get
# Run tests
flutter test
# Run example app
cd example
flutter run
This project is licensed under the MIT License - see the LICENSE file for details.
Thanks to all contributors who have helped improve this plugin! 🎉
To everyone who has:
This is NOT an official Razorpay plugin.
This plugin is an independent, community-driven project and is not affiliated with, endorsed by, or officially supported by Razorpay.
Use at your own risk. The author and contributors:
For official Razorpay integrations and support, please refer to Razorpay's official documentation.
Made with ❤️ for the Flutter community