I am working in flutter application. I want to integrate razorpay in my application
My implementation till now as follows
var _razorpay = Razorpay();
_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) {
// Do something when payment fails
print("Payment Successful");
}
void _handlePaymentError(PaymentFailureResponse response) {
// Do something when payment fails
print("Payment Failed");
}
void _handleExternalWallet(ExternalWalletResponse response) {
// Do something when an external wallet is selected
print("Payment Successful");
}
var options = {
'key': 'rzp_test_FV4AbXsCYMqPcC', //test
'amount': 50000, //in the smallest currency sub-unit.
'currency': 'INR',
'name': 'Actofit',
'order_id': 'Product Id. # 1234', // Generate order_id using Orders API
'description': 'Product Id. # 1234',
'timeout': 60, // in seconds
'prefill': {'contact': '', 'email': 'actofit@yopmail.comm'}
};
try {
_razorpay.open(options);
} catch (e) {
debugPrint(e as String?);
}
After this i am getting error like
D/OpenGLRenderer(28284): --- Failed to create image decoder with message 'unimplemented' V/FA (28284): Recording user engagement, ms: 2052 E/flutter (28284): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'String' is not a subtype of type 'Map<dynamic, dynamic>?' in type cast E/flutter (28284): #0 PaymentFailureResponse.fromMap (package:razorpay_flutter/razorpay_flutter.dart:150:44) E/flutter (28284): #1 Razorpay._handleResult (package:razorpay_flutter/razorpay_flutter.dart:72:42) E/flutter (28284): #2 Razorpay.open (package:razorpay_flutter/razorpay_flutter.dart:54:5)
You need to pass a valid product Id. Go to your Razorpay dashboard/Console and create a product and get that productId. now Paste this productId in your code in options json like
'key': 'rzp_test_FV4AbXsCYMqPcC', //test
'amount': 50000, //in the smallest currency sub-unit.
'currency': 'INR',
'name': 'Actofit',
'order_id': Your_Generated_Product_Id, // Generate order_id using Orders API
'description': 'Product Id. # 1234',
'timeout': 60, // in seconds
'prefill': {'contact': '', 'email': 'actofit@yopmail.comm'}
};
As you can see it in comment as well.
When you need to do it dynamic then, You have call your backend Api that will give you a product Id and you can use that here.
But simply for testing purpose you can create a product and get its id using Razorpay dashboard.
For creating product and getting its Id use this link. Login using same credentials by which you generated your api and secret keys https://razorpay.com/docs/api/orders/#create-an-order
Thankyou. Please mark this question as correct if it helped you so that others can know.