【问题标题】:How to get a customer's email address and transaction subject from the Authorize.net "unsettled transactions" API?如何从 Authorize.net “未结算交易” API 中获取客户的电子邮件地址和交易主题?
【发布时间】:2021-02-12 13:54:10
【问题描述】:

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

在两个点标记为“/* 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;

【问题讨论】:

    标签: php api transactions authorize.net


    【解决方案1】:

    getUnsettledTransactionListRequest 不返回客户电子邮件或订单描述,您可以获得这些字段(对于给定的交易),如果您调用getTransactionDetailsRequest,您可以将以下内容添加到您的 getTransactiondetails 脚本以获取电子邮件/描述:

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

    【讨论】:

    • 这非常有效!谢谢曼苏尔!另一个快速的问题是:如何获取交易完成的原始网站,你知道我怎么能得到它吗?
    • 我不知道您的集成流程是什么,但如果您目前没有任何数据可以区分您的交易来源,您可以使用 userFields 进行探索可以在 createTransaction 请求中传递的商家定义数据。
    • 通过 WP/WooCommerce。我尝试搜索“userFields”,但在 API 中没有找到任何相关文档。
    • 检查 Authorize.Net API 参考中Charge a credit cardAuthorized a credit card 请求下的请求字段描述部分 {userFields:这些元素可用于传递信息,例如会话 ID 和订单详细信息。 ...}
    猜你喜欢
    • 2018-10-12
    • 2012-05-25
    • 2013-07-01
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    • 2011-02-27
    • 1970-01-01
    相关资源
    最近更新 更多