如何从Authorize.net"unsettled transactions"API中获取客户的邮箱地址和交易主题?

How to get a customer's email address and transaction subject from the Authorize.net "unsettled transactions" API?

我在一些在线示例的帮助下使用 Authorize.net API for PHP 来遍历今天(或过去 24 小时)的所有交易。到目前为止,我只能获得提交时间和交易金额(又名结算金额)。如何获取客户的电子邮件以及交易 subject/description?

在标记为“/* HERE */”的两个位置的循环内,我尝试了多种方法,但都没有成功。正确的语法是什么?

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;

getUnsettledTransactionListRequest does not return customer email nor order description, you can obtain these fields (for a given transaction), if you call getTransactionDetailsRequest,您可以将以下内容添加到您的 getTransactiondetails 脚本中以获取 email/description:

  • $response->getTransaction()->getCustomer()->getEmail()
  • $response->getTransaction()->getOrder()->getDescription()