If you are using flutter this is how it can be done.
You need a package called url_launcher to be added in pubspec to this get work.
Check the documentation here to see the details of parameters used in the URL.
https://developers.google.com/pay/india/api/web/create-payment-method#create-payment-method
All parameters are required.
pa: UPI id of the requesting person
pn: Name of the requesting person
am: Amount
cu: Currency. I read somewhere that only INR is supported now.
One main problem with this method is that this doesn't give any call back to check whether the payment has been successful or failed.
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Google Pay',
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
initiateTransaction() async {
String upi_url =
'upi://pay?pa=aneesshameed@oksbi&pn=Anees Hameed&am=1.27&cu=INR;
await launch(upi_url).then((value) {
print(value);
}).catchError((err) => print(err));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Google Pay'),
),
body: Center(
child: Column(
children: [
RaisedButton(
child: Text(
'Pay',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
onPressed: () {
initiateTransaction();
},
),
],
),
),
);
}
}
If you are using a business UPI id then there need few more parameters in the upi_url. For eg: I have a rpy.payto000006621197825@icici UPI for accepting business payments. Then there needs to add a few more parameters
pa: UPI id of the requesting business account
pn: Name of the requesting business account
am: Amount
cu: Currency. I read somewhere that only INR is supported now.
mc: Merchant category code.
You can get this Merchant category code from where you have created UPI business id. For eg: I created the upi id 'rpy.payto000006621197825@icici' through razorpay and I received this code somewhere from their window. But this code is similar for all the payment services like, paypal, stripe, Citibank etc: Below are few links:
https://docs.checkout.com/resources/codes/merchant-category-codes
https://www.citibank.com/tts/solutions/commercial-cards/assets/docs/govt/Merchant-Category-Codes.pdf
tr: Transaction id.
I couldn't find any use for this, this transaction id is showing neither in Google pay transaction details nor in the Razorpay transaction window. But the Google pay is not working when this is not used.
URL: The URL which shows the details of the transaction. When you go to Google pay and open the transaction details, then on the same page at the bottom you will see a button 'More details'. The value of URL parameter defines the target for the more details button. You can use this URL so that the customer can find more information about the transactions been made.
UPI String example:
String upi_url =
'upi://pay?pa=rpy.payto000006621197825@icici&pn=Elifent&mc=4900&tr=1234ABCD&url=https://elifent.tech/tr/1234&am=1.27&cu=INR';
If you make a test payment then the payment will be credited to my google pay account. Go ahead!!! :D