I am trying to implement a USD paynow integration for my website. Please may I be assisted
USD paynow integration
Good day and thank you for contacting us. Our sincere apologies for the delayed response.
The following methods may prove useful whilst integrating your site with Paynow. You can create a separate integration,
- CreateHash
This method will create a hash value sent in any HTTP POST between the merchant site and Paynow.
PHP
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);
}
- UrlIfy
This method will create a string of key-value pairs in the form key1=value1&key2=value2.
PHP
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;
}
- 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.
PHP
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;
}
- ParseMsg
Will convert a message of the form created by CreateMsg back into an associative array / dictionary.
PHP
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;
}