Skip to content

Instantly share code, notes, and snippets.

@parthdesai1208
Created March 7, 2021 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parthdesai1208/644a05cd1b28f4fdc93dfbf3de00f172 to your computer and use it in GitHub Desktop.
Save parthdesai1208/644a05cd1b28f4fdc93dfbf3de00f172 to your computer and use it in GitHub Desktop.
Accept payment using GPay UPI
private val GOOGLE_REQUEST_CODE: Int = 123
val uriapp = Uri.Builder()
.scheme("upi")
.authority("pay")
.appendQueryParameter("pa", "merchant@bank") //VPA Name here
.appendQueryParameter("pn", "Merchant Name") //merchant name here
.appendQueryParameter("mc", "1234") //merchant code here
.appendQueryParameter("tr", "123456789") //transaction reference id here
.appendQueryParameter("tn", "For shopping") //transaction note here
.appendQueryParameter("am", "100") //amount here
.appendQueryParameter("cu", "INR") //currency code here e.g., INR,etc
.appendQueryParameter("url", "https://merchant.website") //website of merchant here
.build()
val intent = Intent(Intent.ACTION_VIEW)
intent.data = uriapp
intent.setPackage("com.google.android.apps.nbu.paisa.user")
if (intent.resolveActivity(packageManager) != null) {
startActivityForResult(intent, GOOGLE_REQUEST_CODE)
} else {
Toast.makeText(this, "This payment mode is not available on your device.", Toast.LENGTH_LONG).show()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == GOOGLE_REQUEST_CODE) {
Log.e("focus", data.toString())
data?.getStringExtra("Status")?.let {
Log.e("result", it)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment