好authorize.net PHP库

问题描述:

我正在开发一个PHP项目,并且正在寻找一个好的authorize.net网关。我想要一些经过测试的成熟代码。我们的目标是避免基于authorize.net API文档编写和测试整个事情。好authorize.net PHP库

有没有人知道任何好的PHP库?我搜索谷歌无济于事。

Authorize.net提供了自己的SDK for PHP and other languages。可能不需要在别处寻找。

http://www.micahcarrick.com/04-19-2005/php-authorizenet-aim-interfacing-class.html

这是我使用的类。使用相当简单。尽管如此,你仍然需要深入研究API,找出你想发送什么变量以及哪些变量没有发送。

Magento支持Authorize.Net。提取出您需要的代码,因为Magento已经过良好测试并且代码质量很好。

+1

我想他一直在寻找更多的现成的解决方案去。通过magento的代码挖掘可能比他所寻找的更多的工作 – Mark 2009-07-30 21:44:40

你很幸运。这是我使用(用于SIM网关):

include("../../simdata.php"); 
... 
<!--form action="https://test.authorize.net/gateway/transact.dll" method="POST"--> 
<FORM action="https://secure.authorize.net/gateway/transact.dll" method="POST"> 
<? 
$x_description = "website.com"; 
$currency = ""; 
$tstamp = time(); 
// Seed random number for security and better randomness. 
srand(time()); 
$sequence = rand(1, 1000); 
$data = "$x_loginid^$sequence^$tstamp^$total^$currency"; 
#echo "data = $data\n"; 
#echo $x_tran_key; 
$fingerprint = bin2hex(mhash(MHASH_MD5, $data, $x_tran_key)); 
# php 5 only $fingerprint = hash_hmac("md5", $data, $x_tran_key); 
echo ("<input type='hidden' name='x_fp_sequence' value='" . $sequence . "'>\n"); 
echo ("<input type='hidden' name='x_fp_timestamp' value='" . $tstamp . "'>\n"); 
echo ("<input type='hidden' name='x_fp_hash' value='" . $fingerprint . "'>\n"); 
echo ("<input type=\"hidden\" name=\"x_description\" value=\"" . $x_description . "\">\n"); 
echo ("<input type=\"hidden\" name=\"x_login\" value=\"$x_loginid\">\n"); 
echo ("<input type=\"hidden\" name=\"x_amount\" value=\"$total\">\n"); 

?> 
<input type="hidden" name="x_first_name" value="<?=firstName($_SESSION['user']['name'])?>"> 
<input type="hidden" name="x_last_name" value="<?=lastName($_SESSION['user']['name'])?>"> 
<input type="hidden" name="x_company" value="<?=$_SESSION['user']['company']?>"> 
<input type="hidden" name="x_address" value="<?=$_SESSION['user']['address']?>"> 
<input type="hidden" name="x_city" value="<?=$_SESSION['user']['city']?>"> 
<input type="hidden" name="x_state" value="<?=$_SESSION['user']['state']?>"> 
<input type="hidden" name="x_zip" value="<?=$_SESSION['user']['zip']?>"> 
<input type="hidden" name="x_phone" value="<?=$_SESSION['user']['phone']?>"> 
<input type="hidden" name="x_email" value="<?=$_SESSION['user']['email']?>"> 
<input type="hidden" name="x_cust_id" value="<?=$_SESSION['user']['username']?>"> 
<INPUT TYPE="HIDDEN" name="x_logo_url" VALUE= "https://secure.authorize.net/mgraphics/logo_99999.gif"> 
<INPUT type="hidden" name="x_show_form" value="PAYMENT_FORM"> 
<!--INPUT type="hidden" name="x_test_request" value="TRUE"--> 

<!--input type="hidden" name="x_receipt_link_method" value="POST"> 
<input type="hidden" name="x_receipt_link_text" value="Click for listings"> 
<input type="hidden" name="x_receipt_link_url" value="http://website.com/confirmation.php"--> 

<input type="hidden" name="x_relay_response" value="TRUE"> 
<input type="hidden" name="x_relay_url" value="http://website.com/confirmation.php"> 
<input type="hidden" name="<?=session_name()?>" value="<?=session_id()?>"> 

<input type="hidden" name="" value=""> 
<input type="hidden" name="" value=""> 
<input type="hidden" name="" value=""> 
<? if ($total==0) { ?> 
    <a href="account.php">Your Account</a> 
<? } else { ?> 
    <INPUT type="submit" value="Accept Order"> 
<? } ?> 
</form> 

这是我使用的confirmation.php

include("../../simdata.php"); 
#print_r($_POST); 

// verify transaction comes from authorize.net and save user details 
$responseCode = $_POST['x_response_code']; 
if ($responseCode == 1) { // approved 
    $md5 = $_POST['x_MD5_Hash']; 
    $transId = $_POST['x_trans_id']; 
    $amount = $_POST['x_amount']; 
    $myMD5 = strtoupper(md5("$x_tran_key$x_loginid$transId$amount")); 
    #echo $myMD5; 
    #print_r ($_POST); 
    #print_r ($_SESSION['user']); 

    if ($myMD5 == $md5) { // authenticated response from authorize.net 
     ... 
    } else { 
     $error = "Unauthenticated response."; 
    } 
} else if (isset($_POST['x_response_code'])) { // error 
    $error = $_POST['x_response_reason_text'].", #".$_POST['x_response_code'].'.'.$_POST['x_response_subcode']. 
     '.'.$_POST['x_response_reason_code']; 
} 
+2

只需注意$ x_tran_key不是Authorize.Net事务密钥。这是在设置下在其帐户上生成的MD5哈希。我一遍又一遍地运行你的代码,直到我明白这个事实,才能运行它。 – Volomike 2013-03-17 00:18:42

+0

使用这种方法有没有实际的安全处罚?这仍然是什么攻击? – 2015-10-22 15:24:48

+0

当时我知道的比我多,我不会使用`rand`,而是使用`mcrypt_create_iv`。如果我今天这样做了,我会使用他们的API。 – Chloe 2015-10-22 19:49:36

这是笨使用像样的图书馆,但能是单机使用:

http://code.google.com/p/authorizenetlib/downloads/detail?name=Authorize_net-1.0.php

信贷:对码詹姆斯·吉福德。

我已经使用Kohana 2.3.x中包含的支付模块和内置的Authorize.Net驱动程序。 http://docs.kohanaphp.com/addons/payment

我觉得simdata.php只包含事务数据...像量,这个人的名字,等

詹姆斯·吉福德创造了笨一些Authorize.net代码。点击此处下载...

http://jamesgifford.com/programming/codeigniter-authorize-net-library/

我使用的PHP SDK我直接从Authorize.nets开发站点了...

http://developer.authorize.net/downloads/

表单方法是传输此信息的不安全方式。更好的选择是使用他们的API AIM方法。

一个伟大的教程可以在这里找到: http://www.johnconde.net/blog/tutorial-integrating-the-authorizenet-aim-api-with-php