Virtual Cards Integration

You can integrate Virtual card using PayUPPIAndroidSDK in Android.Β 

Step 1: Gradle changes

Add the following dependency in your app level gradle file.Β 

implementation 'in.payu:payu-ppi-sdk:1.0.0'`

Step 2: SDK Initialisation

  1. Create a OnePayUJSParams Object
OnePayUJSParams( Β  Β  Β  Β  Β  Β environment = <Environment - Prod or Test>, Β  Β  Β  Β  Β  Β merchantKey = <String - Merchant Key>, Β  Β  Β  Β  Β  Β mobileNumber = <String - user mobile number>, Β  Β  Β  Β  Β  Β walletIdentifier = <String - merchant wallet Identifier>, Β  Β  Β  Β  Β  Β walletUrn = <String - User wallet urn linked with aboved mobile number>, Β  Β  Β  Β  Β  Β referenceId = <String - Any unique reference id> Β  Β  Β  Β )
  1. Call the showCards function
OnePayUJSSDK.showCards(activity, onePayUJSParams, onePayUJSListener) Params: activity: Current Activity in which want to open cards fragment onePayUJSParams: OnePayUJSModel object with all parameters and hash OnePayUJSListener: This is a delegate class in which you will got below callbacks Β 1. onCancel() - If user press back button on card page or verify otp page Β 2. fun onError(code: Int, message: String) - Β If any error occured Β 3. fun generateHash( Β  Β  Β  Β map: HashMap<String, String?>, Β  Β  Β  Β hashGenerationOnePayUJKListener: OnePayUJSHashGenerationListener Β  Β ) - Β create and send dynamic hash.

Step 3: Construct hash

You will get the hash string in map hashString key and hash name hashName in generateHash.Β  You need to send this string to server and append salt there, after appending salt convert string to sha512 hash and return back to SDK in OnePayUJSHashGenerationListener onHashGenerated asΒ  ([<hashName>:<hash>]). For more information, refer to Generate Static Hash.

Β OnePayUJSHashGenerationListener - Β  Β  fun onHashGenerated(map: HashMap<String, String>)}

Sample Code

override fun generateHash( Β  Β  Β  Β map: HashMap<String, String?>, Β  Β  Β  Β hashGenerationOnePayUJKListener: OnePayUJSHashGenerationListener Β  Β ) { Β  Β  Β  Β if (map.containsKey("hashString") && map.containsKey("hashName") Β  Β  Β  Β ) { Β  Β  Β  Β  Β  Β val hashStringWithoutSalt = map["hashString"] Β  Β  Β  Β  Β  Β val commandName = map["hashName"] Β  Β  Β  Β  Β  Β // get hash for "commandName" from server Β  Β  Β  Β  Β  Β // get hash for "hashStringWithoutSalt" from server Β  Β  Β  Β  Β  // After fetching hash set its value in below variable "hashValue" Β  Β  Β  Β  Β  Β val hash = <fetch hash from server, on server add salt in last of hashStringWithoutSalt and create sha512 Hash> Β  Β  Β  Β  Β  Β if (!TextUtils.isEmpty(hash)) { Β  Β  Β  Β  Β  Β  Β  Β val hashMap: HashMap<String, String> = HashMap() Β  Β  Β  Β  Β  Β  Β  Β hashMap[hashName ?: ""] = hash ?: "" Β  Β  Β  Β  Β  Β  Β  Β hashGenerationOnePayUJKListener.onHashGenerated(hashMap) Β  Β  Β  Β  Β  Β } Β  Β  Β  Β } Β  Β }