如何从 PHP Laravel 中的 Authorize.net 获取银行卡交易的最后四位数字

How to get Card last four digits of transaction from Authorize.net in PHP Laravel

我试过这段代码并得到了结果

public function getTransactionDetails($transactionId)
        {
        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
        $merchantAuthentication->setName(env('MERCHANT_LOGIN_ID'));
        $merchantAuthentication->setTransactionKey(env('MERCHANT_TRANSACTION_KEY'));

        // Set the transaction's refId
        $refId = 'ref' . time();
        $request = new AnetAPI\GetTransactionDetailsRequest();
        $request->setMerchantAuthentication($merchantAuthentication);
        $request->setTransId($transactionId);
        $controller = new AnetController\GetTransactionDetailsController($request);
        $response = $controller->executeWithApiResponse( 
          \net\authorize\api\constants\ANetEnvironment::SANDBOX);

        return $response;
    }

当我 return 响应时,它给我以下输出

net\authorize\api\contract\v1\GetTransactionDetailsResponse {#1635 ▼
  -transaction: net\authorize\api\contract\v1\TransactionDetailsType {#1634 ▼
    -transId: "60179386025"
    -refTransId: null
    -splitTenderId: null
    -submitTimeUTC: DateTime @1636637863 {#1636 ▶}
    -submitTimeLocal: DateTime @1636609063 {#1637 ▶}
    -transactionType: "authCaptureTransaction"
    -transactionStatus: "settledSuccessfully"
    -responseCode: 1
    -responseReasonCode: 1
    -subscription: null
    -responseReasonDescription: "Approval"
    -authCode: "5DQLVA"
    -aVSResponse: "Y"
    -cardCodeResponse: "P"
    -cAVVResponse: null
    -fDSFilterAction: null
    -fDSFilters: null
    -batch: net\authorize\api\contract\v1\BatchDetailsType {#1638 ▶}
    -order: null
    -requestedAmount: null
    -authAmount: 3.0
    -settleAmount: 3.0
    -tax: null
    -shipping: null
    -duty: null
    -lineItems: null
    -prepaidBalanceRemaining: null
    -taxExempt: false
    -payment: net\authorize\api\contract\v1\PaymentMaskedType {#1643 ▶}
    -customer: null
    -billTo: net\authorize\api\contract\v1\CustomerAddressType {#1639 ▶}
    -shipTo: null
    -recurringBilling: false
    -customerIP: "59.103.97.140"
    -product: "Card Not Present"
    -entryMode: null
    -marketType: "eCommerce"
    -mobileDeviceId: null
    -customerSignature: null
    -returnedItems: null
    -solution: null
    -emvDetails: null
    -profile: null
    -surcharge: null
    -employeeId: null
    -tip: null
    -otherTax: null
    -shipFrom: null
    -networkTransId: "2OE7KPRVGKYY58S7PISZRQI"
    -originalNetworkTransId: null
    -originalAuthAmount: null
    -authorizationIndicator: "final"
  }
  -clientId: "accept-hosted"
  -transrefId: "ref1636637807"
  -refId: null
  -messages: net\authorize\api\contract\v1\MessagesType {#1633 ▶}
  -sessionToken: null
}

现在我无法在访问交易时获取交易详细信息,因此它给我一个错误:

dd($response->transaction);

Cannot access private property net\authorize\api\contract\v1\GetTransactionDetailsResponse::$transaction

任何人都可以帮助我这里的问题是什么以及为什么无法访问交易详细信息 凭据是沙盒帐户。

试试这个:$response->getTransaction()