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:

HashMap<String, Object> additionalParams = new HashMap<>();  
additionalParams.put(PayUCheckoutProConstants.CP_VAS_FOR_MOBILE_SDK], <String>); 
additionalParams.put(PayUCheckoutProConstants.CP_PAYMENT_RELATED_DETAILS_FOR_MOBILE_SD K], <String>); 

Passing dynamic hashes

For generating and passing dynamic hashes, merchant will receive a call on the method generateHash of PayUCheckoutProListener.

void generateHash(HashMap<String,String> map, PayUHashGenerationListener hashGenerationListener) 

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.

interface PayUHashGenerationListener { 
    void onHashGenerated(HashMap<String,String> map) 
} 

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.

@Override 
public void generateHash(@NotNull HashMap<String, String> map, @NotNull PayUHashGenerationListener 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 = new HashMap<>(); 
            hashMap.put(hashName, hash); 
            hashGenerationListener.onHashGenerated(hashMap); 
        } 
    } 
}

Last updated