cancel
Showing results for 
Search instead for 
Did you mean: 

PHP - Getting transaction details? (revised)

Apologies for repetition from my last post; I was not able to edit it and I was var_dumping the wrong variable.

 

I am trying to get transaction details using the PHP SDK. So far, it will get the transaction correctly (I checked in the logs and found that A.Net responded with the correct transaction information), but using var_dump() on the $response variable yields the following result:

 

object(net\authorize\api\contract\v1\GetTransactionDetailsResponse)#280 (4) {
  ["transaction":"net\authorize\api\contract\v1\GetTransactionDetailsResponse":private]=>
  NULL
  ["refId":"net\authorize\api\contract\v1\ANetApiResponseType":private]=>
  NULL
  ["messages":"net\authorize\api\contract\v1\ANetApiResponseType":private]=>
  NULL
  ["sessionToken":"net\authorize\api\contract\v1\ANetApiResponseType":private]=>
  NULL
}

 

Moreover, when calling getTransaction() on $response, it returns null. So does getMessages(). 

 

Here is my code -- how can I get the transaction details (i.e., accessing properties like getAuthAmount(), getTransId(), etc)?

 

 

        $request = new AnetAPI\GetTransactionDetailsRequest();
        $request->setMerchantAuthentication($this->getAuthnetCreds());
        $request->setTransId('7465634525');

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

        var_dump($response);

 

 

truthsofwolf
Member
11 REPLIES 11

Hi there,

 

We're currently working on the full bank of new sample code here's the sample for gettransactiondetails in PHP:  https://github.com/AuthorizeNet/sample-code-php/blob/master/Reporting/get-transaction-details.php

 

Hope this helps,

 

Brian

brianmc
Administrator Administrator
Administrator

Hey Brian,

 

Thanks for the reply. I implemented the sample code but it's almost identical to what I'm trying above except it makes calls to error methods. Since getMessages() is null, I get the following error:

 

FatalErrorException in OrderController.php line 87:
Call to a member function getResultCode() on null

 

I know the transaction is being retrieved successfully because it logs the correct XML response in the phplog file. This is the revised code:

 

$request = new AnetAPI\GetTransactionDetailsRequest();
        $request->setMerchantAuthentication($this->getAuthnetCreds());
        $request->setTransId('2239019257');

        $controller = new AnetController\GetTransactionDetailsController($request);
        $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
        
        if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
        {
            echo "SUCCESS: Transaction Status:" . $response->getTransaction()->getTransactionStatus() . "\n";
            echo "                Auth Amount:" . $response->getTransaction()->getAuthAmount() . "\n";
            echo "                   Trans ID:" . $response->getTransaction()->getTransId() . "\n";
        }
        else
        {
            echo "ERROR :  Invalid response\n";
            echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . "  " .$response->getMessages()->getMessage()[0]->getText() . "\n";
        }

 

 

Fixed it. Turns out it was a broken dependency in composer.json.

Hi,

 

I have downloaded the latest SDK from github and i am getting the same issue. I have used the sample code provided at http://developer.authorize.net/api/reference/index.html#customer-profiles with my sandbox credentials.

 

It will be great If i can get some help from you.

 

Thanks

Hi there,

 

Are you using  1.8.6.2 of the PHP SDK?   I have just run the sample code from https://github.com/AuthorizeNet/sample-code-php/blob/master/TransactionReporting/get-transaction-det... successfully.

 

Also I made sure to do a "composer update" to make sure I had the latest SDK and all the latest dependencies correct.

 

Let us know how that goes,

 

Brian

Hi,

 

Thanks for your suggestion. Earlier i had taken the SDK from master, but now i have downloaded version  1.8.6.2 and i am getting same result.

 

Should i get the latest version of other required libraries like jms, xsd2php, doctrine, Symfony, phpoption, parser-lib etc, as of now I am using it from master.

 

Please suggest.

 

Thanks

Can you paste in exactly what output you get when you run >php TransactionReporting/get-transaction-details.php from the command line?  

 

Many thanks,

 

Brian

Hi guys,

 

I am facing the same issue. Using the latest SDK. Using it in YII-2 freamwork. This is the response I am getting.

 

net\authorize\api\contract\v1\ARBCreateSubscriptionResponse Object
(
    [subscriptionId:net\authorize\api\contract\v1\ARBCreateSubscriptionResponse:private] => 
    [refId:net\authorize\api\contract\v1\ANetApiResponseType:private] => 
    [messages:net\authorize\api\contract\v1\ANetApiResponseType:private] => 
    [sessionToken:net\authorize\api\contract\v1\ANetApiResponseType:private] => 
)

  When I tried to debug the function I found the XML is coming out properly. Below is the xml response

 

<?xml version="1.0" encoding="utf-8"?><ARBCreateSubscriptionResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><refId>ref1450967088</refId><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><subscriptionId>3043388</subscriptionId></ARBCreateSubscriptionResponse> 

 

But the code $this->apiResponse = $this->serializer->deserialize( $xmlResponse, $this->apiResponseType , 'xml'); is not converting the xml into expected object.

 

Please help me here. 

 

Thank you very much in advance 

I have this same error. 

Please help.

@truthsofwolf what dependency was broken?

 

@davinder  how did you fix yours?