I'm building an online payment system. One of the requirements is that the system must integrate into authorize.net's server integration method. I've ruled out using the authorize.net plugin because it uses the advanced integration method.
Authorize.net's server integration method allows a form on the merchants website to post information to a secure payment form hosted by authorize.net. To accomplish this I plan to use the Redirect plugin in concert with snippets of authorize.net's sample code.
Authorize.net's sample code is as follows:
This code does several things:
-Stores the API and Transaction keys
-Stores the total cost
-Generates a unique fingerprint for the transaction
-Posts the information to authorize.net
We will still need the sample code to store the api info and generate the fingerprint. However we can get the redirect plugin to do the posting for us. We just put the url for authorize.net's gateway in the target URL box.
Next we need use some of the sample code to load the keys and generate a transaction fingerprint. So we do a little snippy-snip on the sample code:
This is then put into the extra code field of the redirect plugin. The code hasn't changed much. All we did was snip out the html head and body tags, the submit button code, and the form declaration.
This is where my understanding of the process gets hazy and I need some input on how to complete this task. Can the redirect plugin take PHP variables (IE x_field=$Foo)? If not will declaring hidden fields in the extra code section as above allow me to pass them to the extra fields section? If not will having one of the child forms store the hidden fields work?
In exchange for everyone's help I plan on immediately editing this thread to be a proper tutorial on how to pull this trick off.
Authorize.net's server integration method allows a form on the merchants website to post information to a secure payment form hosted by authorize.net. To accomplish this I plan to use the Redirect plugin in concert with snippets of authorize.net's sample code.
Authorize.net's sample code is as follows:
<!--
This sample code is designed to connect to Authorize.net using the SIM method.
For API documentation or additional sample code, please visit:
http://developer.authorize.net
Most of this page can be modified using any standard html. The parts of the
page that cannot be modified are noted in the comments. This file can be
renamed as long as the file extension remains .php
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML lang='en'>
<HEAD>
<TITLE> Sample SIM Implementation </TITLE>
</HEAD>
<BODY>
<!-- This section generates the "Submit Payment" button using PHP -->
<?PHP
// This sample code requires the mhash library for PHP versions older than
// 5.1.2 - http://hmhash.sourceforge.net/
// the parameters for the payment can be configured here
// the API Login ID and Transaction Key must be replaced with valid values
$loginID = "API_LOGIN_ID";
$transactionKey = "TRANSACTION_KEY";
$amount = "19.99";
$description = "Sample Transaction";
$label = "Submit Payment"; // The is the label on the 'submit' button
$testMode = "false";
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
$url = "https://test.authorize.net/gateway/transact.dll";
// If an amount or description were posted to this page, the defaults are overidden
if ($_REQUEST["amount"])
{ $amount = $_REQUEST["amount"]; }
if ($_REQUEST["description"])
{ $description = $_REQUEST["description"]; }
// an invoice is generated using the date and time
$invoice = date(YmdHis);
// a sequence number is randomly generated
$sequence = rand(1, 1000);
// a timestamp is generated
$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)); }
// Print the Amount and Description to the screen.
echo "Amount: $amount <br />";
echo "Description: $description <br />";
// Create the HTML form containing necessary SIM post values
echo "<FORM method='post' action='$url' >";
// Additional fields can be added here as outlined in the SIM integration guide
// at: http://developer.authorize.net
echo " <INPUT type='hidden' name='x_login' value='$loginID' />";
echo " <INPUT type='hidden' name='x_amount' value='$amount' />";
echo " <INPUT type='hidden' name='x_description' value='$description' />";
echo " <INPUT type='hidden' name='x_invoice_num' value='$invoice' />";
echo " <INPUT type='hidden' name='x_fp_sequence' value='$sequence' />";
echo " <INPUT type='hidden' name='x_fp_timestamp' value='$timeStamp' />";
echo " <INPUT type='hidden' name='x_fp_hash' value='$fingerprint' />";
echo " <INPUT type='hidden' name='x_test_request' value='$testMode' />";
echo " <INPUT type='hidden' name='x_show_form' value='PAYMENT_FORM' />";
echo " <input type='submit' value='$label' />";
echo "</FORM>";
?>
<!-- This is the end of the code generating the "submit payment" button. -->
</BODY>
</HTML>
This code does several things:
-Stores the API and Transaction keys
-Stores the total cost
-Generates a unique fingerprint for the transaction
-Posts the information to authorize.net
We will still need the sample code to store the api info and generate the fingerprint. However we can get the redirect plugin to do the posting for us. We just put the url for authorize.net's gateway in the target URL box.
Next we need use some of the sample code to load the keys and generate a transaction fingerprint. So we do a little snippy-snip on the sample code:
<?PHP
// This sample code requires the mhash library for PHP versions older than
// 5.1.2 - http://hmhash.sourceforge.net/
// the parameters for the payment can be configured here
// the API Login ID and Transaction Key must be replaced with valid values
$loginID = "API_LOGIN_ID";
$transactionKey = "TRANSACTION_KEY";
$amount = "19.99";
$description = "Sample Transaction";
$label = "Submit Payment"; // The is the label on the 'submit' button
$testMode = "false";
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
// If an amount or description were posted to this page, the defaults are overidden
if ($_REQUEST["amount"])
{ $amount = $_REQUEST["amount"]; }
if ($_REQUEST["description"])
{ $description = $_REQUEST["description"]; }
// an invoice is generated using the date and time
$invoice = date(YmdHis);
// a sequence number is randomly generated
$sequence = rand(1, 1000);
// a timestamp is generated
$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)); }
// Additional fields can be added here as outlined in the SIM integration guide
// at: http://developer.authorize.net
echo " <INPUT type='hidden' name='x_login' value='$loginID' />";
echo " <INPUT type='hidden' name='x_amount' value='$amount' />";
echo " <INPUT type='hidden' name='x_description' value='$description' />";
echo " <INPUT type='hidden' name='x_invoice_num' value='$invoice' />";
echo " <INPUT type='hidden' name='x_fp_sequence' value='$sequence' />";
echo " <INPUT type='hidden' name='x_fp_timestamp' value='$timeStamp' />";
echo " <INPUT type='hidden' name='x_fp_hash' value='$fingerprint' />";
echo " <INPUT type='hidden' name='x_test_request' value='$testMode' />";
echo " <INPUT type='hidden' name='x_show_form' value='PAYMENT_FORM' />";
echo " <input type='submit' value='$label' />";
echo "</FORM>";
?>
This is then put into the extra code field of the redirect plugin. The code hasn't changed much. All we did was snip out the html head and body tags, the submit button code, and the form declaration.
This is where my understanding of the process gets hazy and I need some input on how to complete this task. Can the redirect plugin take PHP variables (IE x_field=$Foo)? If not will declaring hidden fields in the extra code section as above allow me to pass them to the extra fields section? If not will having one of the child forms store the hidden fields work?
In exchange for everyone's help I plan on immediately editing this thread to be a proper tutorial on how to pull this trick off.