I'm just starting to try to integrate the API with my website code in PHP. I've looked at the examples and the API reference for just charging a card. In the response section the example doesn't do anything more than show "Invalid Response" if the "getResponseCode()" is anything but 1. How do I get the actual error text?
I have clicked the "Response" tab in the API Reference and see all the different Elements but that doesn't give me the method name to use in my PHP code to access the information (like getResponseCode()). Is there a different reference that lists all the methods for accessing the response information, or some way to convert those elements into a method that I can use. As it stands, the elements don't really help if I can't use them in the code.
Thanks.
12-01-2015 01:03 PM
To get the error message text you can use
$response->getTransactionResponse()->getErrors()->getError()[0]-> getErrorText();
In general, there isn’t a separate web page which lists all the methods of all the request and response classes that can be used as a reference. That’s where you can make use of sdks which are wrappers that can be used to directly hit the APIs. You can download the latest copy of sdk (https://github.com/AuthorizeNet/sdk-php) and browse through the response class file (sdk-php\lib\net\authorize\api\contract\v1) you are interested in. This will also help you get better hold of APIs.
If you are only interested in getting the description of the error message, we have a utility which gives you the detailed message for a response code / error code. Please take a look
Thanks for the reply and information. I appreciate it. I tried using the string you posted to get the error text but it's coming back with an error: Fatal error: Call to a member function getError() on a non-object. Any thoughts?
12-02-2015 11:10 PM
Hi Mark,
Could you please try following :
$response->getTransactionResponse()->getErrors()[0]->getErrorText()
If you are still facing the issue please let me know the API you are trying to invoke where-in you are getting this exception. I will try to reproduce this at my end and let you know about it.
Thanks
12-21-2015 01:00 AM