3

The Deep Link URI string look like

upi://pay?pa={payee_address}&pn={payee_name}&am={amount}&cu={currency_code}&tn={transaction_note}&sign={sign_key}

Rahul Mishra
  • 1,122
  • 1
  • 10
  • 25

1 Answers1

0

You can create a method to generate this UPI

private fun getUPIString(
    payeeAddress: String,
    payeeName: String,
    payeeAmount: String,
    currencyCode: String,
    transactionNote: String,
    signKey: String,
): String {
      val upi =
            "upi://pay?&pa=$payeeAddress&pn=$payeeName&am=$payeeAmount&cu=$currencyCode&tn=$transactionNote&sign=$signKey"
      return upi.replace(" ", "+")
}

Then you do a simple Intent to create the chooser

val intent = Intent()
intent.action = Intent.ACTION_VIEW
intent.data = Uri.parse(upi)
val chooser = Intent.createChooser(intent, "Pay with...")
startActivityForResult(chooser, 1, null)

Yo create the sign key you can use :

private fun generateSignKey() {
   val secureRandom = SecureRandom()
   val keyPairGenerator = KeyPairGenerator("RSA")
   keyPairGenerator.initialize(2048, secureRandom)
   val keyPair = keyPairGenerator.generateKeyPair()
}

Now the keyPair contains the private key and the public key, so you need to use the private key for signing the UPI transaction (signKey) payload and the public key for encrypting the payload and also for verifying the signature, make sure you store somewhere secure the private key encrypted.

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148