Try to run this Code:
@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': 2000,
'name': 'Acme Corp.',
'description': 'Fine T-Shirt',
'prefill': {'contact': '8888888888', 'email': 'test@razorpay.com'},
'external': {
'wallets': ['paytm']
}
};
try {
_razorpay.open(options);
} catch (e) {
debugPrint(e);
}
}
void _handlePaymentSuccess(PaymentSuccessResponse response) {
Fluttertoast.showToast(
msg: "SUCCESS: " + response.paymentId, timeInSecForIos: 4);
}
void _handlePaymentError(PaymentFailureResponse response) {
Fluttertoast.showToast(
msg: "ERROR: " + response.code.toString() + " - " + response.message,
timeInSecForIos: 4);
}
void _handleExternalWallet(ExternalWalletResponse response) {
Fluttertoast.showToast(
msg: "EXTERNAL_WALLET: " + response.walletName, timeInSecForIos: 4);
}
The above error occurs when your provided money is not in correct format. RazorPay accepts money only in paise, therefore if you provide money in decimal format(i.e double) or any value less than 100 then it will throw that error. So if you have any decimal value try converting it as integer paise. I'm attaching a small code as well for reference.
RegExp regex = RegExp(r"([.]*0)(?!.*\d)");
double money = double.parse(widget.totalMoney);
double tMoney = money*100;
String stringMoney = tMoney.toString().replaceAll(regex, '');
int totalMoney = int.parse(stringMoney);
The regular expression will remove zero after the decimal from stringMoney. Or directly converting it into string will also do the same.
Hope this will help :)