Authorize.net Transaction Details API:XML Confusion

时间:2014-06-13 14:40:19

标签: php xml authorize.net

我正在设置一个页面来报告我组织的Authorize.net帐户中的所有过去的交易并遇到一些麻烦。我已经完成了一堆documentation的阅读,并且在论坛中似乎XML方法是鼓励方法。

我对XML文档几乎没有经验,我担心它现在会阻碍我。

在文档中我发现了以下内容:

<?xml version="1.0" encoding="utf-8"?>
<getTransactionListRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
    <merchantAuthentication>
        <name>1234</name>
        <transactionKey>1234abcd</transactionKey>
    </merchantAuthentication>
    <batchId>1234123</batchId>
</getTransactionListRequest>

我插入了我的ID,交易密钥和批次ID,但我真的不知道从哪里开始。如何使用它来获取事务列表?

谢谢。

1 个答案:

答案 0 :(得分:2)

如果您使用我编写的AuthnetXML PHP library用于使用Authorize.Net的API,这非常简单。以下是getTransactionListRequest APi调用的示例代码:

<?php
/*************************************************************************************************

Use the Transaction Details XML API to get a list of transaction in a batch

SAMPLE XML FOR API CALL
--------------------------------------------------------------------------------------------------
<?xml version="1.0"?>
<getTransactionListRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <merchantAuthentication>
    <name>yourloginid</name>
    <transactionKey>yourtransactionkey</transactionKey>
  </merchantAuthentication>
  <batchId>1221577</batchId>
</getTransactionListRequest>

SAMPLE XML RESPONSE
--------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<getTransactionListResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <messages>
    <resultCode>Ok</resultCode>
    <message>
      <code>I00001</code>
      <text>Successful.</text>
    </message>
  </messages>
  <transactions>
    <transaction>
      <transId>2162566217</transId>
      <submitTimeUTC>2011-09-01T16:30:49Z</submitTimeUTC>
      <submitTimeLocal>2011-09-01T10:30:49</submitTimeLocal>
      <transactionStatus>settledSuccessfully</transactionStatus>
      <invoiceNumber>60</invoiceNumber>
      <firstName>Matteo</firstName>
      <lastName>Bignotti</lastName>
      <accountType>MasterCard</accountType>
      <accountNumber>XXXX4444</accountNumber>
      <settleAmount>1018.88</settleAmount>
    </transaction>
  </transactions>
</getTransactionListResponse>

*************************************************************************************************/

    require('../../config.inc.php');
    require('../../AuthnetXML.class.php');

    try
    {
        $xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER);
        $xml->getTransactionListRequest(array(
            'batchId' => '1221577'
        ));
    }
    catch (AuthnetXMLException $e)
    {
        echo $e;
        exit;
    }
?>

<!DOCTYPE html>
<html>
<html lang="en">
    <head>
        <title></title>
        <style type="text/css">
            table
            {
                border: 1px solid #cccccc;
                margin: auto;
                border-collapse: collapse;
                max-width: 90%;
            }

            table td
            {
                padding: 3px 5px;
                vertical-align: top;
                border-top: 1px solid #cccccc;
            }

            pre
            {
                overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
                white-space: pre-wrap; /* css-3 */
                white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
                white-space: -pre-wrap; /* Opera 4-6 */
                white-space: -o-pre-wrap; /* Opera 7 */ /*
                width: 99%; */
                word-wrap: break-word; /* Internet Explorer 5.5+ */
            }

            table th
            {
                background: #e5e5e5;
                color: #666666;
            }

            h1, h2
            {
                text-align: center;
            }
        </style>
    </head>
    <body>
        <h1>
            Transaction Detail :: Get Transactions List
        </h1>
        <h2>
            Results
        </h2>
        <table>
            <tr>
                <th>Response</th>
                <td><?php echo $xml->messages->resultCode; ?></td>
            </tr>
            <tr>
                <th>code</th>
                <td><?php echo $xml->messages->message->code; ?></td>
            </tr>
            <tr>
                <th>Successful?</th>
                <td><?php echo ($xml->isSuccessful()) ? 'yes' : 'no'; ?></td>
            </tr>
            <tr>
                <th>Error?</th>
                <td><?php echo ($xml->isError()) ? 'yes' : 'no'; ?></td>
            </tr>
<?php
    foreach ($xml->transactions->transaction as $transaction)
    {
?>
            <tr>
                <th>Transaction</th>
                <td>
                    transId: <?php echo $transaction->transId; ?><br>
                    submitTimeUTC: <?php echo $transaction->submitTimeUTC; ?><br>
                    submitTimeLocal: <?php echo $transaction->submitTimeLocal; ?><br>
                    transactionStatus: <?php echo $transaction->transactionStatus; ?><br>
                    invoiceNumber: <?php echo $transaction->invoiceNumber; ?><br>
                    firstName: <?php echo $transaction->firstName; ?><br>
                    accountType: <?php echo $transaction->accountType; ?><br>
                    accountNumber: <?php echo $transaction->accountNumber; ?><br>
                    settleAmount: <?php echo $transaction->settleAmount; ?><br>
                </td>
            </tr>
<?php
    }
?>
        </table>
        <h2>
            Raw Input/Output
        </h2>
<?php
    echo $xml;
?>
    </body>
</html>