Set up the payment hashes
(Mandatory Step)
For details on static and dynamic hashes check here.

Passing static hashes

For passing static hashes during integration, use below code:
Java
Kotlin
1
HashMap<String, Object> additionalParams = new HashMap<>();
2
additionalParams.put(PayUCheckoutProConstants.CP_VAS_FOR_MOBILE_SDK], <String>);
3
additionalParams.put(PayUCheckoutProConstants.CP_PAYMENT_RELATED_DETAILS_FOR_MOBILE_SD K], <String>);
Copied!
1
val additionalParamsMap: HashMap<String, Any?> = HashMap()
2
additionalParamsMap[PayUCheckoutProConstants.CP_VAS_FOR_MOBILE_SDK] = <String>
3
additionalParamsMap[PayUCheckoutProConstants.CP_PAYMENT_RELATED_DETAILS_FOR_MOBILE_SDK] = <String>
Copied!

Passing dynamic hashes

For generating and passing dynamic hashes, merchant will receive a call on the method generateHash of PayUCheckoutProListener.
Java
Kotlin
1
void generateHash(HashMap<String,String> map, PayUHashGenerationListener hashGenerationListener)
Copied!
1
fun generateHash(map:HashMap<String,String>,hashGenerationListener: PayUHashGenerationListener)
Copied!
Here,
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.
Java
Kotlin
1
interface PayUHashGenerationListener {
2
void onHashGenerated(HashMap<String,String> map)
3
}
Copied!
1
interface PayUHashGenerationListener {
2
fun onHashGenerated(map: HashMap<String,String?>)
3
}
Copied!
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.
Java
Kotlin
1
@Override
2
public void generateHash(@NotNull HashMap<String, String> map, @NotNull PayUHashGenerationListener hashGenerationListener) {
3
String hashName = map.get(CP_HASH_NAME);
4
String hashData = map.get(CP_HASH_STRING);
5
if (!TextUtils.isEmpty(hashName) && !TextUtils.isEmpty(hashData)) {
6
7
//Do not generate hash from local, it needs to be calculated from server side only. Here, hashString contains hash created from your server side.
8
String hash = hashString
9
if (!TextUtils.isEmpty(hash)) {
10
HashMap<String, String> hashMap = new HashMap<>();
11
hashMap.put(hashName, hash);
12
hashGenerationListener.onHashGenerated(hashMap);
13
}
14
}
15
}
Copied!
1
override fun generateHash(
2
map: HashMap<String, String?>,
3
hashGenerationListener: PayUHashGenerationListener
4
) {
5
if (map.containsKey(CP_HASH_STRING)
6
&& map.containsKey(CP_HASH_STRING) != null
7
&& map.containsKey(CP_HASH_NAME)
8
&& map.containsKey(CP_HASH_NAME) != null
9
) {
10
11
val hashData = map[CP_HASH_STRING]
12
val hashName = map[CP_HASH_NAME]
13
14
//Do not generate hash from local, it needs to be calculated from server side only. Here, hashString contains hash created from your server side.
15
val hash: String? = hashString;
16
17
if (!TextUtils.isEmpty(hash)) {
18
val hashMap: HashMap<String, String?> = HashMap()
19
hashMap[hashName!!] = hash!!
20
hashGenerationListener.onHashGenerated(hashMap)
21
}
22
}
23
}
Copied!
Last modified 9mo ago