【发布时间】: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