Implementing Razorpay Payment Gateway In Flutter/Dart

razorpay_flutter: ^1.2.3
flutter pub get
import 'package:razorpay_flutter/razorpay_flutter.dart';
Razorpay _razorpay;@override
void initState() {
super.initState();
_razorpay = Razorpay();
}
void openCheckout() async {
var options = {
'key': 'rzp_test_1DP5mmOlF5G5ag',
'amount': 2000,
'name': 'Acme Corp.',
'description': 'Fine T-Shirt',
'image' : 'https://firebasestorage.googleapis.com/v0/b/mytestApp.appspot.com/o/images%2FpZm8daajsIS4LvqBYTiWiuLIgmE2?alt=media&token=3kuli4cd-dc45-7845-b87d-5c4acc7da3c2',
'prefill': {'contact': '8888888888', 'email': 'test@razorpay.com'},
'external': {
'wallets': ['paytm']
}
};

try {
_razorpay.open(options);
}
catch (e) {
debugPrint(e);
}
}
void _handlePaymentSuccess(PaymentSuccessResponse response) {
// handle response....
}
void _handlePaymentError(PaymentFailureResponse response) {
// handle response
}
void _handleExternalWallet(ExternalWalletResponse response) {
// handle response
}
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);
}
RaisedButton(onPressed: openCheckout, child: Text('Pay'))
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}

-keepattributes JavascriptInterface
-keepattributes *Annotation*

-dontwarn com.razorpay.**
-keep class com.razorpay.** {*;}

-optimizations !method/inlining/*

-keepclasseswithmembers class * {
public void onPayment*(...);
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

--

--

--

Flutter || Android Developer Since 2018

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Android Mid-level Interview questions

Working with OpenGL ES to make 3D figures

Android VTS

View Animation and Property Animation in Android

Getting a Fully-Expanded RecyclerView to Scroll With Other Content On the Page

Android Developer Triaxo Solution

BitCore BTX introduces its first BEP-20 token

Working with Flutter Commands

Working with flutter commands

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akshay Papneja

Akshay Papneja

Flutter || Android Developer Since 2018

More from Medium

Flutter MoEngage Tracking Event  :Practical Guide

Format Dates in Flutter

Integrating Cloud Functions in a Flutter application

Flutter environment