A flutter plugin to make payments by opening UPI applications using Android Intent and receiving the transaction information back in response.
The plugin also provides additional APIs to query and list installed applications.
Getting Started #
First, add the package to your flutter project's
pubspec.yaml as a dependency
dependencies: flutter: sdk: flutter # adding upi_pay as dependency upi_pay: ^0.2.0
Then, import the package where you need to use it
Start a UPI Transaction #
You can call the
UpiPay.initiateTransaction method to start an UPI Transaction
Method Call #
UpiTransactionResponse txnResponse = await UpiPay.initiateTransaction( /// must be a string value of two decimal digits amount: "10.00", /// UpiApplication class has all the supported applications /// only accepts a value from the UpiApplication class app: UpiApplication.payTM, /// Name of the person / merchant receiving the payment receiverName: "John", /// UPI VPA of the person / merchant receiving the payment receiverUpiAddress: "johnupi@paytm", /// unique ID for the transaction /// use your business / use case specific ID generation logic here transactionRef: 'ORD1215236', /// there are some other optional parameters like /// [url], [merchantCode] and [transactionNode] /// url can be used share some additional data related to the transaction like invoice copy, etc. url: 'www.johnshop.com/order/ORD1215236', /// this is code that identifies the type of the merchant /// if you have a merchant UPI VPA as the receiver address /// add the relevant merchant code for seamless payment experience /// some application may reject payment intent if merchant code is missing /// when making a P2M (payment to merchant VPA) transaction merchantCode: 1032, /// anything that provides some desription of the transaction transactionNote: 'Test transaction' )
The response will be an instance of
You can access the following properties on the response instance -
txnId- The Transaction ID from the PSP
responseCode- The UPI response code can be used to decipher the reason for failure (if any)
approvalRefNo- UPI Approval Reference Number
status- This can have one of the following status values
Always prefer the use of
UpiTransactionStatusenum to decipher the status of the transaction response for better code health
txnRef- The transaction ref that was passed when initiating the payment. Use this value to identify which transaction the response belongs to
You can also access the raw URL response by accessing
rawResponse on the response object
Take a look at the UPI Linking specification linked above to better understand the meaning of these fields
The method can throw the following errors -
InvalidUpiAddressException- if the UPI Receiver Address is not in valid format
InvalidAmountException- if the transaction amount is in invalid format (< 0 or > 1,00,000 or has more than 2 decimal digits)
Get UPI Applications #
You can list the UPI application that can handle an UPI Intent.
This API can be used to list all the UPI application on the user's device that can be used to complete an UPI transaction.
List<ApplicationMeta> upiApps = await UpiPay.getInstalledUpiApplications();
ApplicationMeta instance has the following properties on it -
upiApplication- an instance of the
UpiApplicationwhich can be passed as argument for the
packageName- the package name value like
icon- stores the icon of the package in
UInt8Listformat and hence can be used to render the icon as such
Image.memory(icon, width: 64, height: 64)
preferredOrder- the order of app in the UPI Intent results according to user's preference (earlier usage). This can be used to highlight the most recently used apps by the User for making UPI payments.
We have an example application in the same repo and that can be used a reference
- Initial release
- Added package description
- Added MIT License
- Upgraded kotlin_version to 1.3.61
- Removed UPI Intent mode parameter because some applications do not strictly follow the UPI Specification and fails when intent parameter is passed
Demonstrates how to use the upi_pay plugin.
Getting Started #
This project is a starting point for a Flutter application.
A few resources to get you started if this is your first Flutter project:
For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies: upi_pay: ^0.2.1
2. Install it
You can install packages from the command line:
$ flutter pub get
Alternatively, your editor might support
flutter pub get.
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.7.0
- pana: 0.13.4
- Flutter: 1.12.13+hotfix.5
Health issues and suggestions
Document public APIs. (-0.43 points)
51 out of 52 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.
|Dart SDK||>=2.1.0 <3.0.0|