I am able to see the ErrorResponse with the code E00003 in our API log, but I have no idea how to capture the ErrorResponse as it does not seem to part of the normal response recieved back from Authorize.net.
I realize this is an error from an XML parsing problem, but I would like to know if there is a way to capture the error like I would if it were: $this->response->getTransactionResponse()
I can't find anything like: getErrorResponse()
Thank you,
Don
Solved! Go to Solution.
01-30-2017 11:41 AM
Hi @fifty-git,
Sorry in advance for a long winded response. I'm attempting to over-explain for the benefit of anyone else who might wander by.
In a response from us, there will be a few different responses in a few different places that you might need to know about. All of the individual fields in a response should be defined in the "Response" tabs for any request in our API Reference, but I'll try to provide more explanation here.
messages
At the top level of the response, there's a "messages" element that will contain a "resultCode" field and a "message" section.
transactionResponse
An API request for a transaction will have a "transactionResponse" section containing information about whether or not a transaction was successfully authorized, and information about the transaction itself.
So, if you're a developer and you want to properly test for results or trap or log errors, what do you do? The first thing to check is the root-level "messages" section. Depending on the "resultCode" you find there, you'll do one of two things. If the "resultCode" is "Ok", you'll start digging in the "transactionResponse" to determine how your transaction turned out. If the "resultCode" is "Error", you check the "message" section. You either just log what you see there and give up, or you analyze the "code" and determine if it's an error that you can do something about programmatically.
So, @fifty-git, in answer to your question about how to get this XML parsing error, it's important to remeber that there's generally two kinds of errors you might see.
The first kind is an error generated by our inability to understand the transaction request. This kind would include this XML parsing error, or really any error generated by our system when it can't even process the input as a transaction. The second kind of error is the kind generated by the transaction processor after it's actually attempted to process the transaction.
Errors of the first sort would cause the "resultCode" in the root-level "messages" section to be returned as "Error". The code and text would be part of the "message" section within the "messages" section.
Errors of the second sort would show up in the "transactionResponse", in the "errors" section.
So, to get the XML parsing error, you'd need to call getMessages() at the appropriate time, not just getErrors(). From our sample code, here's a little snippet that should show the whole sequence:
if ($response != null) { if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; }
01-31-2017 11:00 AM
Hi Don,
There's a getMessages() and a getErrors() function in the TransactionResponseType, either of which might get you what you need. If you haven't already, you can get our sample code repo from GitHub which will show plenty of examples of how to use either. The basic idea is something like this, though:
$tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; }
01-30-2017 02:35 PM - edited 01-30-2017 02:35 PM
Hi Aaron, thanks for your response.
I'm getting all codes, errors and messages from the transaction response when a normal good or declined transaction takes place, that's not an issue.
If I force an XML error by hardcoding in a first name that is too long, I can test for the XML ErrorResponse.
The problem is with this: $this->tresponse = $this->response->getTransactionResponse();
In this case, $this->tresponse is empty and I get a PHP error if I try to retrieve the errors using it.
PHP Fatal error: Call to a member function getErrors() on null.
I can see the ErrorResponse in the log, but I have no idea how to capture it.
Here is a sample: (I have since stopped this from happening - but the issue is not why the error)
Response from AnetApi: <?xml version="1.0" encoding="utf-8"?><ErrorResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Error</resultCode><message><code>E00003</code><text>The 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:address' element is invalid - The value XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX is invalid according to its datatype 'String' - The actual length is greater than the MaxLength value.</text></message></messages></ErrorResponse>
Am I right in concluding that this response is not in the transaction response, but in the ErrorResponse? If so, how does one capture this response?
Again, thanks for your help!
- Don
01-31-2017 08:50 AM
Ah, I see. Thanks for clarifying. I understand the issue now. Let me poke around a little bit on this and get back to you.
01-31-2017 08:57 AM
Hi @fifty-git,
Sorry in advance for a long winded response. I'm attempting to over-explain for the benefit of anyone else who might wander by.
In a response from us, there will be a few different responses in a few different places that you might need to know about. All of the individual fields in a response should be defined in the "Response" tabs for any request in our API Reference, but I'll try to provide more explanation here.
messages
At the top level of the response, there's a "messages" element that will contain a "resultCode" field and a "message" section.
transactionResponse
An API request for a transaction will have a "transactionResponse" section containing information about whether or not a transaction was successfully authorized, and information about the transaction itself.
So, if you're a developer and you want to properly test for results or trap or log errors, what do you do? The first thing to check is the root-level "messages" section. Depending on the "resultCode" you find there, you'll do one of two things. If the "resultCode" is "Ok", you'll start digging in the "transactionResponse" to determine how your transaction turned out. If the "resultCode" is "Error", you check the "message" section. You either just log what you see there and give up, or you analyze the "code" and determine if it's an error that you can do something about programmatically.
So, @fifty-git, in answer to your question about how to get this XML parsing error, it's important to remeber that there's generally two kinds of errors you might see.
The first kind is an error generated by our inability to understand the transaction request. This kind would include this XML parsing error, or really any error generated by our system when it can't even process the input as a transaction. The second kind of error is the kind generated by the transaction processor after it's actually attempted to process the transaction.
Errors of the first sort would cause the "resultCode" in the root-level "messages" section to be returned as "Error". The code and text would be part of the "message" section within the "messages" section.
Errors of the second sort would show up in the "transactionResponse", in the "errors" section.
So, to get the XML parsing error, you'd need to call getMessages() at the appropriate time, not just getErrors(). From our sample code, here's a little snippet that should show the whole sequence:
if ($response != null) { if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; }
01-31-2017 11:00 AM
Aaron,
Thank you for the research and the excellent response.
After testing this, this is indeed what I was looking for.
Thank you for your support of this forum.
- Don
01-31-2017 11:32 AM