UPI India is a versatile Flutter plugin designed to seamlessly facilitate UPI transactions across various Android apps, making it easier than ever to handle digital payments in your Flutter application.
- Retrieve a list of UPI apps installed on the device.
- Start UPI transactions with ease.
- Handle various UPI payment statuses and exceptions gracefully.
Add the UPI India plugin to your pubspec.yaml
file:
dependencies:
upi_india: ^1.0.0
-
UpiIndia - The main class containing two essential methods:
-
getAllUpiApps()
- Retrieves a list of UPI apps installed on the device. -
startTransaction()
- Initiates a UPI transaction.
-
-
UpiApp - Represents supported UPI apps and serves as a model class for the apps returned by
getAllUpiApps()
. -
UpiResponse - Use this class to capture responses from the requested UPI app.
-
UpiPaymentStatus - Check the status of UPI payments with this class.
Handle exceptions gracefully:
-
UpiIndiaAppNotInstalledException - Raised when the requested UPI app is not installed on the device.
-
UpiIndiaUserCancelledException - Raised when the user cancels the transaction.
-
UpiIndiaNullResponseException - Raised when the requested UPI app doesn't return any response.
-
UpiIndiaInvalidParametersException - Raised when the requested UPI app cannot handle the transaction.
-
UpiIndiaActivityMissingException - Raised for missing activity during the transaction.
-
UpiIndiaAppsGetException - Raised for errors while retrieving UPI apps.
Follow these steps to initiate a UPI transaction in your Flutter app:
Import the UPI India package in your Dart code:
import 'package:upi_india/upi_india.dart';
Instantiate an UpiIndia
object:
UpiIndia _upiIndia = UpiIndia();
Retrieve a list of UPI apps installed on the device:
List<UpiApp>? apps;
@override
void initState() {
_upiIndia.getAllUpiApps(mandatoryTransactionId: false).then((value) {
setState(() {
apps = value;
});
}).catchError((e) {
apps = [];
});
super.initState();
}
Alternatively, you can directly use predefined apps like this:
UpiApp app = UpiApp.googlePay;
Assign the desired UPI app to the app
parameter in Step 4.
Create a method to start the transaction when called:
Future<UpiResponse> initiateTransaction(UpiApp app) async {
return _upiIndia.startTransaction(
app: app,
receiverUpiId: "receiver@example.com",
receiverName: 'John Doe',
transactionRefId: 'Transaction123',
transactionNote: 'Payment for goods',
amount: 100.00,
);
}
Trigger the transaction method on a button click or using a FutureBuilder
, and handle the response.
After receiving the snapshot from the Future, check for errors:
if (snapshot.hasError) {
switch (snapshot.error.runtimeType) {
case UpiIndiaAppNotInstalledException:
print("Requested app not installed on device");
break;
case UpiIndiaUserCancelledException:
print("You cancelled the transaction");
break;
case UpiIndiaNullResponseException:
print("Requested app didn't return any response");
break;
case UpiIndiaInvalidParametersException:
print("Requested app cannot handle the transaction");
break;
default:
print("An unknown error has occurred");
break;
}
}
If snapshot.hasError
is false, access the response UpiResponse
from snapshot.data
and extract relevant information such as:
- Transaction ID
- Response Code
- Approval Reference Number
- Transaction Reference ID
- Status
These apps have been tested and are verified to work with this plugin:
- All Bank
- Amazon Pay
- Axis Pay
- Baroda Pay
- BHIM
- Cent UPI
- Cointab
- Corp UPI
- DCB UPI
- Fino BPay
- Freecharge
- Google Pay
- iMobile ICICI
- Indus Pay
- Khaali Jeb
- Maha UPI
- Mobikwik
- Oriental Pay
- Paytm
- Paywiz
- PhonePe
- PSB
- SBI Pay
- Yes Pay
Some apps do not return a Transaction ID in their response. To use them, pass mandatoryTransactionId: false
when calling getAllUpiApps()
:
- MiPay (Both Play Store and GetApps version)
- HSBC Simply Pay
These apps haven't been tested yet, but you can use them by passing allowNonVerifiedApps: true
when calling getAllUpiApps()
:
- True Caller
- BOI UPI
- CSB UPI
- CUB UPI
- digibank
- Equitas UPI
- Kotak
- PayZapp
- PNB
- RBL Pay
- realme PaySa
- United UPI Pay
- Vijaya UPI
These apps are currently not working as expected:
- Airtel Thanks
- AUPay
- Bandhan Bank UPI
- CANDI
- Indian Bank UPI
- Jet Pay
- KBL UPI
- KVB UPI
- LVB UPAAY
- Synd UPI
- UCO UPI
- Ultra Cash