Payment Gateway razorpay in Flutter :
This flutter tutorial post is payment getwayrazorpay in flutter.
dependencies
razorpay_flutter:
fluttertoast:
Import package
import ‘package:razorpay_flutter/razorpay_flutter.dart’;
Make sure that the minimum API level for your app is 19 or higher.Make sure that the minimum deployment target for your app is iOS 10.0 or higher. Also, don’t forget to enable bitcode for your project.
Attach event listeners
_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess); _razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError); _razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet); _razorpay.clear(); // Removes all listeners

main.dart
import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:razorpay_flutter/razorpay_flutter.dart'; import 'package:fluttertoast/fluttertoast.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { static const platform = const MethodChannel("razorpay_flutter"); Razorpay _razorpay; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Razorpay'), ), body: Center( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ RaisedButton(onPressed: openCheckout, child: Text('Open')) ])), ), ); } @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': 'Flutter Book', 'image': 'https://www.73lines.com/web/image/12427', 'description': 'Flutter Tutorial', 'prefill': {'contact': '', 'email': ''}, /*'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 flutter tutorial is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application
For more information about Flutter. visit www.fluttertutorial.in