Reply
Member
Posts: 1
Registered: ‎10-29-2020

How to get a customer's email address and transaction subject from unsettled transactions?

I am using the Authorize.net API for PHP with the help of some of the online examples to iterate through all the transactions of today (or last 24 hours). So far I'm only able to obtain the submit time and the transaction amount (aka settle amount). How can I get the email of the customer as well as the transaction subject/description?

Inside the loop where the two spots are marked "/* HERE */" I've tried several ways with no luck. What is the correct syntax?

 

require 'autoload.php';
require_once 'SampleCodeConstants.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

/* 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);

if (($response != null) && ($response->getMessages()->getResultCode() == 'Ok')) {
    if (null != $response->getTransactions()) {
        foreach($response->getTransactions() as $tx) {
            echo 'SUCCESS: TransactionID: ' . $tx->getTransId() . "\n";

            $request = new AnetAPI\GetTransactionDetailsRequest();
            $request->setMerchantAuthentication($merchantAuthentication);
            $request->setTransId($tx->getTransId());

            $controller = new AnetController\GetTransactionDetailsController($request);
            $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::PRODUCTION);

            echo "Submitted on (Local): " . date_format($tx->getSubmitTimeLocal(), 'Y-m-d H:i:s') . "\n";
            echo "Settle amount: " . number_format($tx->getSettleAmount(), 2, '.', '') . "\n";
            echo "Email: " . /* HERE */ . "\n";
            echo "Transaction subject: " . /* HERE */ . "\n";
        }
    } 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 $response;
Highlighted
All Star
Posts: 733
Registered: ‎11-05-2018

Re: How to get a customer's email address and transaction subject from unsettled transactions?

@AuthForumUser1 

I think you would run the transId through the getTransactionDetails method call.

All Star
Posts: 733
Registered: ‎11-05-2018

Re: How to get a customer's email address and transaction subject from unsettled transactions?

It would help if I read your code. For email I think you go to either getCustomer or getAddress or maybe getShipping.

 

Been a while.