Razorpay Payment In Flutter
Razor Pay is one of the best payment gateways which provided plugin in a flutter. It was the most straightforward to integrate in-product payment widget that kicked us off with Razorpay yet it was the quick and dependable help for both issue settlement and on-boarding new highlights that have kept us cooperating with them!.
Assemble a protected installment arrangement on your site or portable application with Razorpay and get installments from your clients utilizing different installment techniques on your Checkout structure. You can follow installments at each progression of its life cycle and effectively manage them.
How to Generate API Key
- Sign in to your Dashboard with suitable credentials.
- Select the mode (Test or Live) for which you need to create the API key
- Explore to Settings → API Keys → Generate Key to create a key for the chose mode.
Note:
You need to produce separate API Keys for the test and live modes. No cash is deducted from your record in test mode.
Implementation:
Step 1: Add the dependencies
Add dependencies to pubspec.yaml file.
dependencies:
razorpay_flutter: latest version
Step 2: Import
import 'package:razorpay_flutter/razorpay_flutter.dart';
Minimum Version Requirement:
For Android, guarantee that the base minimum API level for your app is 19 or higher.
For iOS, guarantee that the base minimum deployment target for your app is iOS 10.0 or higher.Likewise, remember to enable bitcode for your project.
Step 3: Run flutter packages get
in the root directory of your app.
Now core concepts of the Razorpay Payment.
You need to implement it in your code respectively:
Create Razorpay instance:
Use this code to create a Razorpay instance.
_razorpay = Razorpay();
Event Listeners:
The plugin utilizes event-based communication and transmits events when payments fail or succeed.
The event names are uncovered using the constants EVENT_PAYMENT_SUCCESS
, EVENT_PAYMENT_ERROR
and EVENT_EXTERNAL_WALLET
from the Razorpay
class.
Use the on(String event, Function handler)
method on the Razorpay
instance to append event listeners.
_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError);
_razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet);
Handler:
The handlers would be defined in the class and handle the different responses.
In this handler, you can add one more dependencies
fluttertoast: ^latest version
then again run flutter packages get
in the root directory of your app.
Setup Options:
Introduce the details in options and pass your Razorpay key Id here. if you don’t have one go here.
To clear event listeners, use the clear
method on the Razorpay
instance.
_razorpay.clear(); // Removes all listeners
Error Codes:
The error codes have been uncovered as integers by the Razorpay
class.
The error code is accessible as the code field of the PaymentFailureResponse
the instance passed to the callback.
- NETWORK_ERROR: There was a network error. For example, loss of internet connectivity.
- INVALID_OPTIONS: An issue with options passed in
Razorpay.open
. - PAYMENT_CANCELLED: The user canceled the payment.
- TLS_ERROR: The device does not support TLS v1.1 or TLS v1.2.
- UNKNOWN_ERROR: An unknown error occurred.
Event Names:
The event names have been uncovered as strings
by the Razorpay
class.
> EVENT_PAYMENT_SUCCESS: The payment was successful.
> EVENT_PAYMENT_ERROR: The payment was not successful.
> EVENT_EXTERNAL_WALLET: An external wallet was selected.
Payment Success Response:
- Payment Id:
string
The ID for the payment. - Order Id:
string
The order ID if the payment was for an order, otherwisenull
. - Signature:
string
The signature to be used for payment verification. Only valid for orders, otherwisenull
.
Payment Failure Response:
=> Code: integer
The error code.
=>Message: string
The error message.
External Wallet Response:
Wallet Name: string
The name of the external wallet selected.
https://gist.github.com/ShaiqAhmedkhan/ec34b4c903b313b927301761c44c1a6f#file-cart-dart
This is a small bakery flutter example will integrate Razorpay payment, in this code, you will see how to add Razorpay in our code and how to get an order with online payment. This below video shows how Razorpay Payment will work.
So this was the basic example of the Bakery app integrated with Razorpay Payment where we did a simple example and you can learn it and also you can do it.
Thanks for reading this article ❤
If I got something wrong? Let me know in the comments. I would love to improve.
Clap 👏 If this article helps you.
Click the GitHub link below to find the source code of the Bakery App integrated with Razorpay.
flutter-devs/Flutter_Bakery_App_Demo
This App has a decent UI as well as we have integrated Razor Payment Gateway — flutter-devs/Flutter_Bakery_App_Demogithub.com
Feel free to connect with us:
And read more articles from FlutterDevs.com.
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter-related queries.
We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.