Home » PHP scripts » PayU HMAC + IPN script

PayU is a leading financial services provider in global growth markets. We use our expertise and heritage in cross border and local payments to extend the services we offer to merchants and consumers.

The following PHP script is a simple implementation of HMAC and IPN algorithm presented in their documentation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
function generate_hash($array,$key)
{
    $string = "";
    foreach($array as $vector)
    {
        $string .= strlen($vector) . $vector;
    }
    $string = hash_hmac("md5",$string,$key);
    return $string;
}

$date = date("YmdHis",time());

$forhash = array(
$_POST['IPN_PID'][0],
$_POST['IPN_PNAME'][0],
$_POST['IPN_DATE'],
$date
);

$key  = "abdefghijklmnopqrstuvwxyz";
$hash = generate_hash($forhash,$key);
echo "<EPAYMENT>$date|$hash</EPAYMENT>";

?>

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*