代码之家  ›  专栏  ›  技术社区  ›  markwatson

好的authorize.net PHP库

  •  9
  • markwatson  · 技术社区  · 16 年前

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

    有人知道这方面有什么好的PHP库吗?我在谷歌上搜索没有用。

    9 回复  |  直到 13 年前
        1
  •  8
  •   Salman Arshad    15 年前

    authorize.net提供自己的 SDK for PHP and other languages . 可能不需要找别的地方。

        2
  •  5
  •   Justin Johnson    16 年前

    你真走运。这是我使用的(用于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> 
    

    这就是我用来确认的.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'];
    }
    
        3
  •  5
  •   Steve Czetty Wilko van der Veen    13 年前

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

    这里有一个很好的教程: http://www.johnconde.net/blog/tutorial-integrating-the-authorizenet-aim-api-with-php

        4
  •  2
  •   Srikar Doddi    16 年前

    Magento支持authorize.net。提取出您需要的代码,因为Magento经过了良好的测试,代码质量良好。

        5
  •  2
  •   jacob beasley    15 年前

    我认为simdata.php只包含事务数据…比如金额,人名等等。

        6
  •  2
  •   jfountain    15 年前

    JamesGifford为CodeIgniter创建了一些authorize.net代码。下载到此处…

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

    我正在使用从authorize.nets dev站点直接获得的php sdk…

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

        7
  •  1
  •   phirschybar    16 年前

    这是一个不错的库,可以在CodeIgniter中使用,但可以单独使用:

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

    信用证:詹姆斯吉福德的代码。

        8
  •  1
  •   slacker    16 年前

    我已经使用了Kohana2.3.x中包含的支付模块和内置的authorize.net驱动程序。 http://docs.kohanaphp.com/addons/payment

        9
  •  0
  •   Mark    16 年前

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

    那是我使用的课程。使用起来相当简单。不过,您仍然需要深入研究API,找出您想要发送哪些变量,哪些不想发送。

    推荐文章