How to integrate BHIM app payment gateway in an Android App?

Viewed 21789

How to integrate BHIM app payment gateway in an android app, through upi id?
I have no idea about payment gateway,I have not implemented payment gateway before.

Please help me how to integrate payment gateway in an android app?(I want to integrate payment through BHIM app)

5 Answers

You can try DeepLinking UPI to start BHIM from your app.

Code for deeplinking is as follow:

Uri uri = Uri.parse("upi://pay?pa=payee_address&pn=payee_name&tn=transaction_name&am=1&cu=INR&url=url");//url with http or https
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//Now magic starts here
intent.setClassName("in.org.npci.upiapp","in.org.npci.upiapp.HomeActivity");
startActivityForResult(intent,1);

You can open any specific application using its packageName and ClassName.

Now you can collect payment using only BHIM. You can get proper response using BHIM.

Not an answer to the question. But important enough to be mentioned.

If you choose to take payment from, please note that UPI AFAIK has no mechanism to check if the payment has actually been deposited to your account. That means the server can't check if the transaction ever happened or the authenticity of information. You will have to check with your bank if they provide an API to do so.

AFAIK ICIC Bank and Yes Bank have an API.

What to do then? Register yourself with PayTM and get your app verified. PayTM allows you to restrict payment modes, so you can specify only UPI. Also at the time of writing, UPI is free of cost with no limit

If you need payment integration based on UPI then the simplest way is to use Intent

Refer following UPI payment intent

private fun onPayClick() {
    val uri: Uri = Uri.Builder().scheme("upi").authority("pay")
        .appendQueryParameter("pa", "your-merchant-vpa@xxx")
        .appendQueryParameter("pn", "your-merchant-name")
        .appendQueryParameter("mc", "your-merchant-code")
        .appendQueryParameter("tr", "your-transaction-ref-id")
        .appendQueryParameter("tn", "your-transaction-note")
        .appendQueryParameter("am", "your-order-amount")
        .appendQueryParameter("cu", "INR")
        .build()

    val intent = Intent(Intent.ACTION_VIEW)
    intent.data = uri
    if (intent.resolveActivity(packageManager) == null) {
        showMessage("No any payment app found to handle UPI payment")
    } else {
        startActivityForResult(intent, PAY_REQUEST_CODE)
    }
}

Now in onActivityResult get transaction details

onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
    if (requestCode == PAY_REQUEST_CODE) {
        if (data != null) {
            // Get Response from activity intent
            val response = intent.getStringExtra("response")
        }
    }
}

Note: You need to have merchant account to integrate this

IMP Reference: Google Pay Example, Easy UPI Payment, Merchant Account Creation

Related