Created
March 7, 2021 14:48
-
-
Save parthdesai1208/644a05cd1b28f4fdc93dfbf3de00f172 to your computer and use it in GitHub Desktop.
Accept payment using GPay UPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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