Skip to content
Advertisement

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

On my website we keep transactions as pending and capture them when we ship (often we need to change amounts/cancel and it makes it easier accounting wise to work like that).

When we are ready to ship, we match all specified orders (with specified order status) with the invoice#/order id in authorize.

the issue is that the authorize.net API only allows for 1000 transaction limit so when using their GetUnsettledTransactionListRequest function it is missing transactions that are unsettled passed that amount.

I am able to set the paging limit to 1000 and I can also set the offset to 1000 (or 999 not sure which yet) so I think what I need to do is something like check if the array storing the results size is 1000 and if so get the next 1000 results to store in the array. But about about the next loop do I have to manually say 3000, 4000, 5000 (we don’t have that many transactions but still).

here is my current code:

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 AnetAPIMerchantAuthenticationType();
    $merchantAuthentication->setName(SampleCodeConstants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(SampleCodeConstants::MERCHANT_TRANSACTION_KEY);

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


    $request = new AnetAPIGetUnsettledTransactionListRequest();
    $request->setMerchantAuthentication($merchantAuthentication);


    $controller = new AnetControllerGetUnsettledTransactionListController($request);

    $response = $controller->executeWithApiResponse(netauthorizeapiconstantsANetEnvironment::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 responsen";
        $errorMessages = $response->getMessages()->getMessage();
        echo "Response : " . $errorMessages[0]->getCode() . "  " . $errorMessages[0]->getText() . "n";
    }

    return $resulttrans;

}

Advertisement

Answer

GetUnsettledTransactionListRequest offers the ability to page the results. So you after you process the first 1,000 results you can request the next 1,000 results.

I don’t use the Authnet SDK but it looks like you can use AnetAPIPagingType() to handle the paging for you:

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

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

The JSON would resemble this:

{
    "getUnsettledTransactionListRequest": {
        "merchantAuthentication": {
            "name": "",
            "transactionKey": ""
        },
        "paging": {
            "limit": "1000",
            "offset": "1"
        }
    }
}
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement