For passing dynamic hashes, merchant will receive a call on the method generateHash of PayUCheckoutProListener.
In the method parameter you will receive a dictionary or hashMap, extract the value of hashString from that. Pass that value to server, now server will append salt at the end and generate sha512 hash over it. Server will give that hash back to your app and app will give that hash to us via callback mechanism.
For passing dynamic hashes during integration, use below code:
/// Use this function to provide hashes/// - Parameters:/// - param: Dictionary that contains key as HashConstant.hashName & HashConstant.hashString/// - onCompletion: Once you fetch the hash from server, pass that hash with key as param[HashConstant.hashName]funcgenerateHash(forparam: DictOfString, onCompletion: @escaping PayUHashGenerationCompletion) { // Send this string to your backend and append the salt at the end and send the sha512 back to us, do not calculate the hash at your client side, for security is reasons, hash has to be calculated at the server side
let hashStringWithoutSalt = param[HashConstant.hashString]??"" // Or you can send below string hashName to your backend and send the sha512 back to us, do not calculate the hash at your client side, for security is reasons, hash has to be calculated at the server side
let hashName = param[HashConstant.hashName]??""// Set the hash in below string which is fetched from your serverlet hashFetchedFromServer =<#T##String#>onCompletion([hashName : hashFetchedFromServer])}
/// Use this function to provide hashes
/// @param param NSDictionary that contains key as HashConstant.hashName & HashConstant.hashString
/// @param onCompletion Once you fetch the hash from server, pass that hash with key as param[HashConstant.hashName]
- (void)generateHashFor:(NSDictionary<NSString *, NSString *> * _Nonnull)param onCompletion:(void (^ _Nonnull)(NSDictionary<NSString *, NSString *> * _Nonnull))onCompletion {
// Send below string hashStringWithoutSalt to your backend and append the salt at the end and send the sha512 back to us, do not calculate the hash at your client side, for security is reasons, hash has to be calculated at the server side
NSString *hashStringWithoutSalt = [param objectForKey:HashConstant.hashString];
// Or you can send below string hashName to your backend and send the sha512 back to us, do not calculate the hash at your client side, for security is reasons, hash has to be calculated at the server side
NSString * hashName = [param objectForKey:HashConstant.hashName];
// Set the hash in below string which is fetched from your server
NSString *hashFetchedFromServer = <#(NSString)#>;
NSDictionary *hashResponseDict = [NSDictionary dictionaryWithObjectsAndKeys:hashFetchedFromServer, hashName, nil];
onCompletion(hashResponseDict);
}
Here,
param -> Dictionary that contains key as HashConstant.hashName & HashConstant.hashString
onCompletion -> Once you fetch the hash from server, pass that hash with key as param[HashConstant.hashName]
Getting Hash Data to calculate hash
Checkout Pro SDK will give a callback in generateHash() method whenever any hash is needed by it. 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 dictionary received in generateHash() method, use below keys -
HashConstant.hashString -> This will contain complete hash string excluding salt. Merchant can append their salt at end of hash string to calculate the hash.
HashConstant.hashName -> This will contain hash name.
Passing generated hash to SDK
Prepare a dictionary, where key should be param[HashConstant.hashName] and value should be generated hash value and pass this dictionary in onCompletion() .