Jump to content
Dragos

PHP PayU hmac + IPN

Recommended Posts

  • Moderators
Posted

Pentru cei care vor sa implementeze plata prin PayU, trebuie sa returnati in anumite cazuri un string format din mai multi parametri precedati de lungimea valorilor lor pe care se aplica un hmac_md5 cu cheia de la cont.

Am creat functia de mai jos care face asta, alaturi de un exemplu pentru comunicarea cu IPN.


<?php
function genereaza_hash($array,$key)
{
$string = "";
foreach($array as $vector)
{
$string .= strlen($vector) . $vector;
}
$string = hash_hmac("md5",$string,$key);
return $string;
}

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

$pentruhash = array(
$_POST['IPN_PID'][0],
$_POST['IPN_PNAME'][0],
$_POST['IPN_DATE'],
$data
);

$cheie = "abdefghijklmnopqrstuvwxyz";
$hash = genereaza_hash($pentruhash,$cheie);
echo "<EPAYMENT>$data|$hash</EPAYMENT>";

?>

Posted

Din cate stiu are deja payu un fisier cu o functie de genul. Este in contul de client, undeva pe la resurse sau ceva de genul, alaturi de alte cateva jucarii gen documentatia.

Dar felicitari :)

Posted (edited)

Da functia de la PayU din sursele lor este o struto-camila :)

Problema in codul de mai sus(care oricum este bine venit), este ca PayU mai are uneori si array-uri. Eu am ceva de genul celui de mai jos (ma rog, cu trashul de rigoare care nu are nici un sens:)))

<?php
foreach($_POST as $varpost => $value)
{

if(is_array($value))
{
foreach($value as $vararray => $subvalue)
{
$string_test=$string_test.strlen($subvalue).$subvalue;#echo $vararray;
if($varpost=="IPN_PNAME") {$info_product=$subvalue;if($post_ipn_pname=="") $post_ipn_pname=$subvalue;}
if($varpost=="IPN_INFO") $info_product=$info_product." ".$subvalue;
if($varpost=="IPN_DATE") if($post_ipn_date=="")$post_ipn_date=$subvalue;
if($varpost=="IPN_PID") if($post_ipn_pid=="") $post_ipn_pid=$subvalue;
}
}
else
{
if($varpost!="HASH")$string_test=$string_test.strlen($value).$value;#echo $varpost;
if($varpost=="IPN_DATE") {$post_ipn_date=$value;$post_date=$value;}
if($varpost=="HASH") $post_hash=$value;
}
}
$hash=mhash(MHASH_MD5,$string_test,"HASHUL TAU");$string_hash=bin2hex($hash);
?>

Edited by Gushterul
added php tag

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...