Authorize.net(sim)信用卡支付介绍

上一篇文章介绍了aim的支付,《Authorize.net(aim)信用卡支付介绍》,下面介绍下sim的支付。

sim的支付原理是先在本地构造一个表单,然后提交到authorize.net的网站上去,然后客户在authorize.net输入自己的信用卡号等信息,提交,然后从authorize.net会post一个数组到先那个表单指定的URL里面,通过这个数组里面的值可以判断是否支付成功。这个和paypal的网站支付标准版有点类似。

下面看表单代码:

<!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 = “x_login”;
$transactionKey = “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=’hidden’ name=’x_relay_response’ value=’TRUE’ />”;
echo ” <INPUT type=’hidden’ name=’x_relay_url’ value=’http://www.xxx.com/test.php’ />”;
echo ” <input type=’submit’ value=’$label’ />”;
echo “</FORM>”;
?>
<!– This is the end of the code generating the “submit payment” button. –>

</BODY>
</HTML>

需要特别强调的是,x_relay_url的值就是从Authorize.net网站post数据的目的URL。上面是一个test.php文件,在这个文件里把读到的数据进行判断,看是否支付成功。返回数据说明见网站http://developer.authorize.net/guides/SIM/。

aim和sim支付的区别是:aim不需要跳到Authorize.net的官网上去输信用卡地址等,而是直接在本地网站完成。而sim需要到官网上去输入信用卡地址。

from http://blog.sina.com.cn/s/blog_5506d7950100v34k.html

分享到:

1 条评论

昵称
  1. Sisco

    authorize只能用来支付美元,挺不好用的,还是我没有看懂文档?