Authorize.Net API 限制 1000 个结果。如何克服呢?

Authorize.Net API limit 1000 results. How to overcome it?

在我的网站上,我们将交易保持为待处理状态,并在发货时捕获它们(通常我们需要更改 amounts/cancel 这样可以更轻松地进行会计处理)。

当我们准备发货时,我们会将所有指定的订单(具有指定的订单状态)与授权中的发票#/订单 ID 匹配。

问题是 authorize.net API 只允许 1000 笔交易限制,因此当使用他们的 GetUnsettledTransactionListRequest 功能时,它缺少超过该金额的未结算交易。

我可以将分页限制设置为 1000,我也可以将偏移量设置为 1000(或 999 还不确定是哪个)所以我认为我需要做的是检查数组是否存储结果大小为 1000,如果是,则将下 1000 个结果存储在数组中。但是关于下一个循环,我是否必须手动说 3000、4000、5000(我们没有那么多交易,但仍然如此)。

这是我当前的代码:

function getUnsettledTransactionList()
{


//get orders that are in the exp status
    $orders_pending_query = tep_db_query("select orders_id as invoice_number from " . TABLE_ORDERS . " where orders_status = '15' order by invoice_number");

    $orders_pending = array();
    while ($row = mysqli_fetch_array($orders_pending_query, MYSQLI_ASSOC)) {
        $orders_pending[] = $row;
    }

    /* Create a merchantAuthenticationType object with authentication details
       retrieved from the constants file */
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY);

    // Set the transaction's refId
    $refId = 'ref' . time();


    $request = new AnetAPI\GetUnsettledTransactionListRequest();
    $request->setMerchantAuthentication($merchantAuthentication);


    $controller = new AnetController\GetUnsettledTransactionListController($request);

    $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
    $transactionArray = array();
    $resulttrans = array();
    if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) {
        if (null != $response->getTransactions()) {
            foreach ($response->getTransactions() as $tx) {
                $transactionArray[] = array(
                    'transaction_id' => $tx->getTransId(),
                    'invoice_number' => $tx->getInvoiceNumber()
                );
                // echo "TransactionID: " . $tx->getTransId() . "order ID:" . $tx->getInvoiceNumber() . "Amount:" . $tx->getSettleAmount() . "<br/>";
            }


//match the array column by invoice mumber to find all the transaction ids for cards to capture
            $invoiceNumbers = array_column($orders_pending, "invoice_number");
            $result = array_filter($transactionArray, function ($x) use ($invoiceNumbers) {
                return in_array($x["invoice_number"], $invoiceNumbers);
            });
            $resulttrans = array_column($result, "transaction_id");
            print_r($resulttrans);
        } else {
            echo "No unsettled transactions for the merchant." . "\n";
        }
    } else {
        echo "ERROR :  Invalid response\n";
        $errorMessages = $response->getMessages()->getMessage();
        echo "Response : " . $errorMessages[0]->getCode() . "  " . $errorMessages[0]->getText() . "\n";
    }

    return $resulttrans;

}

GetUnsettledTransactionListRequest 提供对结果进行分页的功能。因此,在处理完前 1,000 个结果后,您可以请求接下来的 1,000 个结果。

我不使用 Authnet SDK,但看起来您可以使用 AnetAPI\PagingType() 来为您处理寻呼:

$pagenum = 1;
$transactionArray = array();
do {
    // ...code truncated...
    $request = new AnetAPI\GetUnsettledTransactionListRequest();
    $request->setMerchantAuthentication($merchantAuthentication);

    // Paging code
    $paging = new AnetAPI\PagingType();
    $paging->setLimit("1000");
    $paging->setOffset($pagenum); 
    $request->setPaging($paging);
    
    $controller = new AnetController\GetUnsettledTransactionListController($request);
    // ...code truncated...
    $numResults = (int) $response->getTotalNumInResultSet();
    // ...code truncated...
    $pagenum++;
} while ($numResults === 1000); 

JSON 类似于:

{
    "getUnsettledTransactionListRequest": {
        "merchantAuthentication": {
            "name": "",
            "transactionKey": ""
        },
        "paging": {
            "limit": "1000",
            "offset": "1"
        }
    }
}