Hi,
I'm looking for clarification regarding what can and can't be done with SIM. I've modified the following code (thanks stymiee) and everything works how I want it to, except that I would prefer to omit the second step. Is there anyway to just send the "Invoice #" and "Total Due $" directly to Authorize.net? I'm a real novice at PHP, so any help would be appreciated. Thanks!
<HTML>
<HEAD>
<TITLE> Sample SIM Implementation </TITLE>
</HEAD>
<BODY>
<?php
if (isset($_POST) && is_array($_POST) && count($_POST))
{
$loginID = "*********";
$transactionKey = "****************";
$testMode = "false";
$amount = (float) trim($_REQUEST["x_amount"]);
$invoice = (float) trim($_REQUEST["x_invoice_num"]);
$sequence = rand(1, 1000);
$timeStamp = time();
// The following lines generate the SIM fingerprint. PHP versions 5.1.2 and
// newer have the necessary hmac function built in. For older versions, it
// will try to use the mhash library.
if( phpversion() >= '5.1.2' )
{
$fingerprint = hash_hmac("md5", $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey);
}
else
{
$fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey));
}
?>
INVOICE #: <?php echo $invoice; ?><br />
TOTAL DUE $: <?php echo $amount; ?><br />
<FORM method='post' action='https://secure.authorize.net/gateway/transact.dll' >
<INPUT type='hidden' name='x_login' value='<?php echo $loginID; ?>' />
<INPUT type='hidden' name='x_amount' value='<?php echo $amount; ?>' />
<INPUT type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' />
<INPUT type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' />
<INPUT type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' />
<INPUT type='hidden' name='x_fp_hash' value='<?php echo $fingerprint; ?>' />
<INPUT type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' />
<INPUT type='hidden' name='x_show_form' value='PAYMENT_FORM' />
<input type='submit' value='Submit' />
</FORM>
<?php
}
else
{
?>
<FORM method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
INVOICE #: <INPUT type='text' name='x_invoice_num' value='' /><br />
TOTAL DUE $: <INPUT type='text' name='x_amount' value='' /><br />
<input type='submit' value='Submit' />
</FORM>
<?php
}
?>
</BODY>
</HTML>
Solved! Go to Solution.
06-23-2010 08:50 AM
Do you mean have the form submit automatically once the Invoice # and amount are submitted? If so you'll need to use JavaScript to do this (keep in mind if somone has JavaScript turned off this won't work):
<HTML> <HEAD> <TITLE> Sample SIM Implementation </TITLE> </HEAD> <BODY> <?php if (isset($_POST) && is_array($_POST) && count($_POST)) { $loginID = "*********"; $transactionKey = "****************"; $testMode = "false"; $amount = (float) trim($_REQUEST["x_amount"]); $invoice = (float) trim($_REQUEST["x_invoice_num"]); $sequence = rand(1, 1000); $timeStamp = time(); // The following lines generate the SIM fingerprint. PHP versions 5.1.2 and // newer have the necessary hmac function built in. For older versions, it // will try to use the mhash library. if( phpversion() >= '5.1.2' ) { $fingerprint = hash_hmac("md5", $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey); } else { $fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey)); } ?> INVOICE #: <?php echo $invoice; ?><br /> TOTAL DUE $: <?php echo $amount; ?><br /> <FORM method='post' action='https://secure.authorize.net/gateway/transact.dll' id="paymentform"> <INPUT type='hidden' name='x_login' value='<?php echo $loginID; ?>' /> <INPUT type='hidden' name='x_amount' value='<?php echo $amount; ?>' /> <INPUT type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' /> <INPUT type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' /> <INPUT type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' /> <INPUT type='hidden' name='x_fp_hash' value='<?php echo $fingerprint; ?>' /> <INPUT type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' /> <INPUT type='hidden' name='x_show_form' value='PAYMENT_FORM' /> <input type='submit' value='Submit' /> </FORM> <script type="text/javascript"> document.getElementById('paymentform').submit(); </script> <?php } else { ?> <FORM method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'> INVOICE #: <INPUT type='text' name='x_invoice_num' value='' /><br /> TOTAL DUE $: <INPUT type='text' name='x_amount' value='' /><br /> <input type='submit' value='Submit' /> </FORM> <?php } ?> </BODY> </HTML>
06-23-2010 09:11 AM
Do you mean have the form submit automatically once the Invoice # and amount are submitted? If so you'll need to use JavaScript to do this (keep in mind if somone has JavaScript turned off this won't work):
<HTML> <HEAD> <TITLE> Sample SIM Implementation </TITLE> </HEAD> <BODY> <?php if (isset($_POST) && is_array($_POST) && count($_POST)) { $loginID = "*********"; $transactionKey = "****************"; $testMode = "false"; $amount = (float) trim($_REQUEST["x_amount"]); $invoice = (float) trim($_REQUEST["x_invoice_num"]); $sequence = rand(1, 1000); $timeStamp = time(); // The following lines generate the SIM fingerprint. PHP versions 5.1.2 and // newer have the necessary hmac function built in. For older versions, it // will try to use the mhash library. if( phpversion() >= '5.1.2' ) { $fingerprint = hash_hmac("md5", $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey); } else { $fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey)); } ?> INVOICE #: <?php echo $invoice; ?><br /> TOTAL DUE $: <?php echo $amount; ?><br /> <FORM method='post' action='https://secure.authorize.net/gateway/transact.dll' id="paymentform"> <INPUT type='hidden' name='x_login' value='<?php echo $loginID; ?>' /> <INPUT type='hidden' name='x_amount' value='<?php echo $amount; ?>' /> <INPUT type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' /> <INPUT type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' /> <INPUT type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' /> <INPUT type='hidden' name='x_fp_hash' value='<?php echo $fingerprint; ?>' /> <INPUT type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' /> <INPUT type='hidden' name='x_show_form' value='PAYMENT_FORM' /> <input type='submit' value='Submit' /> </FORM> <script type="text/javascript"> document.getElementById('paymentform').submit(); </script> <?php } else { ?> <FORM method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'> INVOICE #: <INPUT type='text' name='x_invoice_num' value='' /><br /> TOTAL DUE $: <INPUT type='text' name='x_amount' value='' /><br /> <input type='submit' value='Submit' /> </FORM> <?php } ?> </BODY> </HTML>
06-23-2010 09:11 AM
That's just what I needed! Thanks for your time and help!
I'm not too worried about the Javascript-thing :)
06-23-2010 10:23 AM
Hi John,
Thanks for this great code !
however, i'm trying to pass "description" as well, but for some reason it doesn't recognize it and take the value "0".
Could you help me with this matter (posted my code below) ?
<HTML> <BODY> <?php if (isset($_POST) && is_array($_POST) && count($_POST)) { $loginID = "**********"; $transactionKey = "**************"; $testMode = "false"; $amount = (float) trim($_REQUEST["x_amount"]); $invoice = (float) trim($_REQUEST["x_invoice_num"]); $description = (float) trim($_REQUEST["x_description"]); $sequence = rand(1, 1000); $timeStamp = time(); // The following lines generate the SIM fingerprint. PHP versions 5.1.2 and // newer have the necessary hmac function built in. For older versions, it // will try to use the mhash library. if( phpversion() >= '5.1.2' ) { $fingerprint = hash_hmac("md5", $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey); } else { $fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey)); } ?> INVOICE #: <?php echo $invoice; ?><br /> TOTAL DUE $: <?php echo $amount; ?><br /> DESCRIPTION: <?php echo $description; ?><br /> <FORM method='post' action='https://secure.authorize.net/gateway/transact.dll' id="paymentform"> <INPUT type='hidden' name='x_login' value='<?php echo $loginID; ?>' /> <INPUT type='hidden' name='x_amount' value='<?php echo $amount; ?>' /> <INPUT type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' /> <INPUT type='hidden' name='x_description' value='<?php echo $description; ?>' /> <INPUT type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' /> <INPUT type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' /> <INPUT type='hidden' name='x_fp_hash' value='<?php echo $fingerprint; ?>' /> <INPUT type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' /> <INPUT type='hidden' name='x_show_form' value='PAYMENT_FORM' /> <input type='submit' value='Submit' /> </FORM> <script type="text/javascript"> document.getElementById('paymentform').submit(); </script> <?php } else { ?> <style> ul{ list-style-type: none; } </style> <FORM method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'> <ul > <li><label for="DESCRIPTION" Style="display:block;float:left;width:150px;">DESCRIPTION :</label> <INPUT type='text' name='x_description' value='' /></li><br /> <li><label for="DESCRIPTION" Style="display:block;float:left;width:150px;">INVOICE #:</label> <INPUT type='text' name='x_invoice_num' value='' /></li><br /> <li><label for="DESCRIPTION" Style="display:block;float:left;width:150px;">TOTAL DUE $:</label> <INPUT type='text' name='x_amount' value='' /></li><br /> <input type='submit' value='Submit' /> </ul > </FORM> <?php } ?> </BODY> </HTML>
and also, what i would do is have the possibility to pass the value through drop down menus, and when i change for instance :
<li><label for="DESCRIPTION" Style="display:block;float:left;width:150px;">INVOICE #:</label> <INPUT type='text' name='x_invoice_num' value='' /></li> to
<li><label for="DESCRIPTION" Style="display:block;float:left;width:150px;">INVOICE #:</label> <select>
<option name='x_invoice_num' value="1">1</option>
<option name='x_invoice_num' value="2">2</option>
<option name='x_invoice_num' value="3">3</option>
<option name='x_invoice_num' value="4">4</option>
</select>
</li>
it doesn't work anymore.
Your help would be greatly appreciated.
Thanks
Isabelle
05-11-2011 01:54 PM
Change:
$description = (float) trim($_REQUEST["x_description"]);
to:
$description = trim($_REQUEST["x_description"]);
The (float) turns whatever you submit to a number.
As for your dropdown you forgot to name the <select> tag.
Change:
<select>
to:
<select name="description">
05-11-2011 06:02 PM