Skip to main content

upi_link 0.1.1 copy "upi_link: ^0.1.1" to clipboard
upi_link: ^0.1.1 copied to clipboard

Build and parse UPI payment links (upi://pay) in pure Dart, with validation and exact amounts.

upi_link #

pub package CI License: MIT

Build and parse UPI payment links (upi://pay?...) in pure Dart.

upi_link turns payment details into a spec-correct UPI link and reads one back. It has no dependencies and no Flutter requirement, so it works in Flutter apps, Dart backends that generate payment links, and CLI tools.

Features #

  • Build a upi://pay link from typed, named parameters.
  • Parse a link (from a QR code or deep link) back into a UpiLink.
  • Round-trip safe: UpiLink.parse(link.toString()) == link.
  • Exact amounts: amounts are decimal strings with at most 2 places, never double, so no rounding error can reach a payment.
  • Spec-correct encoding: spaces become %20, not +. Dart's Uri(queryParameters: ...) writes +, which some UPI apps display literally.
  • Fails early: invalid input throws when you build the link, naming the field, instead of failing inside the payer's UPI app.

Install #

dart pub add upi_link

Usage #

import 'package:upi_link/upi_link.dart';

final link = UpiLink(
  payeeAddress: 'chaipoint@okaxis',
  payeeName: 'Chai Point',
  amount: '149.50',
  transactionNote: 'Order 42',
  transactionRef: 'ORD-42',
);

print(link);
// upi://pay?pa=chaipoint@okaxis&pn=Chai%20Point&am=149.50&cu=INR&tn=Order%2042&tr=ORD-42

Pass link.toString() to a QR code widget, or link.toUri() to url_launcher to open the payer's UPI app.

final link = UpiLink.parse(scannedText); // throws FormatException if invalid
print(link.payeeName);
print(link.amount);

final maybe = UpiLink.tryParse(scannedText); // null if invalid

Handle invalid input #

try {
  UpiLink(payeeAddress: 'chaipoint', payeeName: 'Chai Point');
} on UpiLinkException catch (e) {
  print(e.field);   // payeeAddress
  print(e.message); // Expected a UPI address like "name@bank", got "chaipoint"
}

Supported parameters #

Dart field Spec key Rules
payeeAddress pa Required. name@handle
payeeName pn Required. Not blank
amount am Positive, at most 2 decimal places, e.g. '149.50'
transactionNote tn Not blank when given
transactionRef tr Not blank when given
merchantCode mc Exactly 4 digits
transactionId tid Not blank when given
referenceUrl url Absolute http/https URL

cu=INR is always written. When parsing, cu may be absent but must be INR if present.

Strict parsing #

UpiLink.parse rejects anything outside the table above, including unknown or repeated keys. Many bank-issued merchant QR codes carry extra keys such as mode, orgid, sign or purpose, so this version will reject them. Support for those keys may be added later; doing so will not break existing code.

How it compares #

Most UPI packages on pub.dev are Flutter plugins that launch UPI apps. They need Flutter and platform code. upi_link only builds and parses the link, so you can use it on its own or together with any of them.

Contributing #

Issues and pull requests are welcome at github.com/devMKunal/upi_link.

License #

MIT. See LICENSE.

0
likes
160
points
--
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Build and parse UPI payment links (upi://pay) in pure Dart, with validation and exact amounts.

Repository (GitHub)
View/report issues

Topics

#upi #payments #india #deep-linking #parser

License

MIT (license)

More

Packages that depend on upi_link