The following methods may prove useful whilst integrating your site with Paynow.

1. CreateHash

This method will create a hash value sent in any HTTP POST between the merchant site and Paynow.

  • function CreateHash($values, $MerchantKey){
    		$string = "";
    		foreach($values as $key=>$value) {
    			if( strtoupper($key) != "HASH" ){
    				$string .= $value;
    			}
    		}
    		$string .= $MerchantKey;
    
    		$hash = hash("sha512", $string);
    		return strtoupper($hash);
    	}
    

2. UrlIfy

This method will create a string of key-value pairs in the form key1=value1&key2=value2.

  • function UrlIfy($fields) {
    		//url-ify the data for the POST
    		$delim = "";
    		$fields_string = "";
    		foreach($fields as $key=>$value) {
    			$fields_string .= $delim . $key . '=' . $value;
    			$delim = "&";
    		}
    
    		return $fields_string;
    	}

3. CreateMsg

This method will urlencode and format your cURL POST fields into one string for posting to Paynow. It calls CreateHash and UrlIfy methods to do this.

  • function CreateMsg($values, $MerchantKey){
    		$fields = array();
    		foreach($values as $key=>$value) {
    		   $fields[$key] = urlencode($value);
    		}
    
    		$fields["hash"] = urlencode($this->CreateHash($values, $MerchantKey));
    
    		$fields_string = $this->UrlIfy($fields);
    		return $fields_string;
    	}

4. ParseMsg

Will convert a message of the form created by CreateMsg back into an associative array / dictionary.

  • function ParseMsg($msg) {
    		//convert to array data
    		$parts = explode("&",$msg);
    		$result = array();
    		foreach($parts as $i => $value) {
    			$bits = explode("=", $value, 2);
    			$result[$bits[0]] = urldecode($bits[1]);
    		}
    
    		return $result;
    	}

That’s all for now, catch you later!