News:

Looking for documentation? Take a look on our wiki

Main Menu

new pament processor, need help

Started by laga, June 13, 2005, 20:32:09 PM

Previous topic - Next topic

laga

hello,

i try to build a string like

8MERCHANT42578192005-05-10 17:30:569CD Player7Walkman5CDPLY6CSTAUD16Another product0725000006350000111121921961000003ROL61000004City6Region2US

with different values from the database, compute them with a key and past over to a payment system but the hash value that my site calculate did not match with the oane the system expect. we use the same function and the key from the another system to compute it.

must i know something about phpshop and how can i found the values from the database

here is what i am trying to use: 


<?php
$hashKey = 'XXX';
$q  = "SELECT * FROM mos_users WHERE user_info_id='".$db->f("user_info_id")."'";
$dbbt = new ps_DB;
$dbbt->setQuery($q);
$dbbt->query();
$dbbt->next_record();
// Get ship_to information
if( $db->f("user_info_id") != $dbbt->f("user_info_id")) {
  $q2  = "SELECT * FROM mos_pshop_user_info WHERE user_info_id='".$db->f("user_info_id")."'";
  $dbst = new ps_DB;
  $dbst->setQuery($q2);
  $dbst->query();
  $dbst->next_record();
}
else  {
  $dbst = $dbbt;
}

//Authnet vars to send
//the 2chekout payment, modified. XXX are fixed values.
$formdata = array (
'MERCHANT' => 'XXX',   
'ORDER_REF' => $db->f("order_number"),
'ORDER_DATE' => date("Y-m-d G:i:s"),       
'ORDER_PNAME[]' =>'order_item_name',
'ORDER_PCODE[]' =>'test',
'ORDER_PINFO[]' =>'test',
'ORDER_PRICE[]'=>'test',
'ORDER_QTY[]'=>'test',
'ORDER_VAT[]'=>'order_tax',
'ORDER_SHIPPING'=>'order_shipping',
'DESTINATION_CITY' => $dbst->f("city"),
'DESTINATION_STATE' => $dbst->f("state"),
'DESTINATION_ZIP' => $dbst->f("zip"),
//need only 2 letters country code
'DESTINATION_COUNTRY' => substr($dbst->f("country"), 0, 2),


// Customer Name and Billing Address
// I need more fields but first try to get it working 

// 'BILL_FNAME' => $dbbt->f("first_name"),
// 'BILL_LNAME' => $dbbt->f("last_name"),
// 'BILL_COMPANY' => $dbbt->f("company"),
// 'BILL_ADDRESS' => $dbbt->f("address_1"),
// 'BILL_ADDRESS2' => $dbbt->f("address_2"),
// 'BILL_CITY' => $dbbt->f("city"),
// 'BILL_STATE' => $dbbt->f("state"),
// 'BILL_ZIPCODE' => $dbbt->f("zip"),
// 'BILL_COUNTRYCODE' => $dbbt->f("country_2_code"),
// 'BILL_PHONE' => $dbbt->f("phone_1"),
// 'BILL_FAX' => $dbbt->f("fax"),
// 'BILL_EMAIL' => $dbbt->f("email")

);
// $formdata['PRICES_CURRENCY'] = $_SESSION['vendor_currency'] . " " . $db->f("order_total");

$formdata['HASH'] = generateHash($hashKey, generateCommandString($formdata));

$url = "payment procesor url";

$formdata['PRICES_CURRENCY'] = $_SESSION['vendor_currency'] . " " . $db->f("order_total");

// to see if its works. it show it but at the transfer
// it past more data then it did show here
echo generateCommandString($formdata);
echo '<BR>';
echo $formdata['ORDER_HASH'];

function generateHash($key, $data){
   echo "<br>HASH_CODE generat pe key=".$key. " si  data=".$data."<BR><BR><BR>";
   $b = 64; // byte length for md5
   if (strlen($key) > $b) {
       $key = pack("H*",md5($key));
   }
   $key  = str_pad($key, $b, chr(0x00));
   $ipad = str_pad('', $b, chr(0x36));
   $opad = str_pad('', $b, chr(0x5c));
   $k_ipad = $key ^ $ipad ;
   $k_opad = $key ^ $opad;
   $genKey = md5($k_opad  . pack("H*",md5($k_ipad . $data)));
   echo "<br>HASH =".$genKey."<BR><BR><BR>";
   return $genKey;
}

function generateCommandString($formdata){
   $string = '';
   $string .= getCode($formdata['MERCHANT']);
   $string .= getCode($formdata['ORDER_REF']);
   $string .= getCode($formdata['ORDER_DATE']);
   $string .= getCode($formdata['ORDER_PNAME[]']);
   $string .= getCode($formdata['ORDER_PCODE[]']);
   $string .= getCode($formdata['ORDER_PINFO[]']);
   $string .= getCode($formdata['ORDER_PRICE[]']);
   $string .= getCode($formdata['ORDER_QTY[]']);
   $string .= getCode($formdata['ORDER_VAT[]']);
   $string .= getCode($formdata['ORDER_SHIPPING']);
   $string .= getCode($formdata['PRICES_CURRENCY']);
   $string .= getCode($formdata['DESTINATION_CITY']);
   $string .= getCode($formdata['DESTINATION_STATE']);
   $string .= getCode($formdata['DESTINATION_COUNTRY']);
   return $string;

}

function getCode($string) {
   return strlen($string).$string;
}

//build the post string
$poststring = '';
foreach($formdata AS $key => $val){
   $poststring .= "<input type='hidden' name='$key' value='$val' />";
}

?>
<form action="<?php echo $url ?>" method="post" target="_blank">
<?php echo $poststring ?>

<p>Note: BLa Bla Bla <br><bR> Now click on the image below to pay...</p>
<input type="image" name="submit" src="http://www.myurl.xxx/buy_logo.jpg" border="0" alt="Make payments with ..." title="..." />
</form>

Can anybody help me?

(excuse my english)

Lucian