upi_pay 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

upi_pay #

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.

The plugins follows the UPI Deep Linking Specification

Getting Started #

First, add the package to your flutter project's pubspec.yaml as a dependency

    sdk: flutter
  # adding upi_pay as dependency
  upi_pay: ^0.2.0

Then, import the package where you need to use it

import 'package:upi_pay/upi_pay.dart';

Documentation #

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'

Response #

The response will be an instance of UpiTransactionResponse

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

    • UpiTransactionStatus.Success
    • UpiTransactionStatus.Failure
    • UpiTransactionStatus.Submitted

    Always prefer the use of UpiTransactionStatus enum 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

Exceptions #

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();

The ApplicationMeta instance has the following properties on it -

  • upiApplication - an instance of the UpiApplication which can be passed as argument for the app parameter in UpiPay.initiateTransaction
  • packageName - the package name value like net.one97.paytm or com.phonepe.app
  • icon - stores the icon of the package in UInt8List format 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.

Example #

We have an example application in the same repo and that can be used a reference

0.1.0 #

  • Initial release

0.1.1 #

  • Added package description

0.1.2 #

  • Added MIT License

0.2.0 #

  • Upgraded kotlin_version to 1.3.61

0.2.1 #

  • Removed UPI Intent mode parameter because some applications do not strictly follow the UPI Specification and fails when intent parameter is passed


upi_pay_example #

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:

  upi_pay: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:

$ 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:

import 'package:upi_pay/upi_pay.dart';
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]
Learn more about scoring.

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.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
decimal ^0.3.5 0.3.5
flutter 0.0.0
tuple ^1.0.3 1.0.3
Transitive dependencies
collection 1.14.11 1.14.12
matcher 0.12.6
meta 1.1.8
path 1.6.4
quiver 2.1.2+1
rational 0.3.7
sky_engine 0.0.99
stack_trace 1.9.3
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies