map -> a hash map that contains hash string and hash name
hashGenerationListener -> Once the hash is generated at merchant end. Pass the generated hash in method onHashGenerated() of the hashGenerationListener.
The generateHash() method is called by the SDK each time it needs an individual hash. The CP_HASH_NAME will contain the name of the specific hash requested in that call and the CP_HASH_STRING will contain the data/string that needs to be hashed.
Getting Hash Data to calculate hash
Checkout Pro SDK will give a callback in generateHash() method whenever any hash is needed by it. The merchant need to calculate that hash and pass back to the SDK. Below is the process of doing so:
To extract hash string and hash name from map received in generateHash() method, use below keys -
CP_HASH_STRING -> This will contain complete hash string excluding salt. For eg, for vas for mobile sdk hash, the hash string will contain “<key>|<command>|<var1>|”. Merchant can append their salt at end of hash string to calculate the hash.
CP_HASH_NAME -> This will contain the hash name.
Passing generated hash to SDK
Prepare a map, where key should be hash name in step 2.1 and value should be generated hash value and pass this map in onHashGenerated() method above.
@OverridepublicvoidgenerateHash(@NotNullHashMap<String, String> map, @NotNullPayUHashGenerationListener hashGenerationListener) { String hashName =map.get(CP_HASH_NAME); String hashData =map.get(CP_HASH_STRING); if (!TextUtils.isEmpty(hashName) &&!TextUtils.isEmpty(hashData)) { //Do not generate hash from local, it needs to be calculated from server side only. Here, hashString contains hash created from your server side.String hash = hashString if (!TextUtils.isEmpty(hash)) { HashMap<String,String> hashMap =newHashMap<>(); hashMap.put(hashName, hash); hashGenerationListener.onHashGenerated(hashMap); } } }
overridefungenerateHash( map: HashMap<String, String?>, hashGenerationListener: PayUHashGenerationListener) { if (map.containsKey(CP_HASH_STRING) && map.containsKey(CP_HASH_STRING) !=null&& map.containsKey(CP_HASH_NAME) && map.containsKey(CP_HASH_NAME) !=null ) { val hashData = map[CP_HASH_STRING] val hashName = map[CP_HASH_NAME] //Do not generate hash from local, it needs to be calculated from server side only. Here, hashString contains hash created from your server side.val hash: String? = hashString;if (!TextUtils.isEmpty(hash)) { val hashMap: HashMap<String, String?> =HashMap() hashMap[hashName!!] = hash!! hashGenerationListener.onHashGenerated(hashMap) } } }