Skip to content

Instantly share code, notes, and snippets.

@arthtilva
Last active June 4, 2018 19:46
Show Gist options
  • Save arthtilva/ccade7069afa87804d17469fde6ae14f to your computer and use it in GitHub Desktop.
Save arthtilva/ccade7069afa87804d17469fde6ae14f to your computer and use it in GitHub Desktop.
UPI payment
private void launchUPI() {
// look below for a reference to these parameters
Uri uri = Uri.parse("upi://pay").buildUpon()
.appendQueryParameter("pa", "xxx@xxxxx")
.appendQueryParameter("pn", "XYZXYZ")
.appendQueryParameter("tn", "Pay for in-app purchase")
.appendQueryParameter("am", "20")
.appendQueryParameter("cu", "INR")
.build();
Intent upiPayIntent = new Intent(Intent.ACTION_VIEW);
upiPayIntent.setData(uri);
Intent chooser = Intent.createChooser(upiPayIntent, "Pay with");
if (null != chooser.resolveActivity(getPackageManager())) {
Log.d("TAG", "UPI Payment resolved to activity");
startActivityForResult(chooser, 12);
} else {
Log.d("TAG", "No activity found to handle UPI Payment");
}
}
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(REQ_UPIPAYMENT == requestCode){
if(RESULT_OK == resultCode){
Log.d(TAG, "UPI Payment successfull");
} else {
Log.d(TAG, "UPI Payment failed");
}
}
}
pa: UPI Virtual address of the payee (the one who receives the payment)
pn: Name of the payee. Can be name of merchant or store.
tn: Transaction note. A simple description of the transaction, like, payment for in-app items, bill payments, etc.
am: Monetary amount of transaction in decimal format.
cu: Currency used in the transaction. Currently only INR is supported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment