Food Delivery App 16 - Placing Order from Cart using Razorpay
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: ^1.1.1
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: ^3.1.0
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 theRazorpay
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 theRazorpay
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
.
Comments
Post a Comment