<?

function HMac($key, $data) {
   $b = 64;
   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;
   return md5($k_opad  . pack("H*",md5($k_ipad . $data)));
}

function CalculateFP ($loginid, $txnkey, $amount, $sequence, $tstamp, $currency = "") {
  return (HMac($txnkey, $loginid . "^" . $sequence . "^" . $tstamp . "^" . $amount . "^" . $currency));
}

$x_fp_timestamp = time();
$x_fp_sequence = rand(1, 1000);
$x_fp_hash = CalculateFP($authorizenet_login_id, $authorizenet_tran_key, $total, $x_fp_sequence, $x_fp_timestamp, $currency_code);

?>
<body onload="document.payment.submit()">
<form name="payment"  action="https://secure.authorize.net/gateway/transact.dll" method="post">
<input type="hidden" name="x_login" value="<?= $authorizenet_login_id ?>">
<input type="hidden" name="x_amount" value="<?= $total ?>">
<input type="hidden" name="x_show_form" value="PAYMENT_FORM">
<input type="hidden" name="x_currency_code" value="<?= $currency_code ?>">
<input type="hidden" name="x_relay_response" value="TRUE">
<input type="hidden" name="x_relay_url" value="<?= $notify_url ?>">
<input type="hidden" name="x_invoice_num" value="<?= $invoice_id ?>">
<input type="hidden" name="x_description" value="<?= $item_name ?>">
<input type="hidden" name="x_fp_sequence" value="<?= $x_fp_sequence ?>">
<input type="hidden" name="x_fp_timestamp" value="<?= $x_fp_timestamp ?>">
<input type="hidden" name="x_fp_hash" value="<?= $x_fp_hash ?>">
<input type="hidden" name="custom" value="<?= urlencode($custom) ?>">
<input type="hidden" name="cancel_url" value="<?= $cancel_url ?>">
<input type="hidden" name="return_url" value="<?= $return_url ?>">
</form>
</body>