cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to trap error in CIM XML API?

I'm calling the CIM APIs using raw xml strings from PHP. It works fine. But when I try to trap an error, it seems impossible. When an error occurs (card declined, etc), it actually blows up my code. So I tried to wrap it in PHP's try/catch block. That failed epically -- it seemed to swallow the error and keep executing code, rather than executing anything in my catch block.

 

It seems that authnet APIs, instead of just blowing up, should return error messages in the array/response, so that I can grab those errors, examine them, and take action.

 

What am I doing wrong?

ZeroGravPro
Contributor
5 REPLIES 5

 

Hi,
 
The Authorize.Net APIs always return a clear error message indicating the result of your API request. I'm not sure what you are seeing when you say that the response is "blowing up", but you should always take action based upon what is included in the Authorize.Net response.
 
Thanks,
Joy
Joy
Administrator Administrator
Administrator

The CIM API throws exceptions; doesn't just return error text. So far I have been unable to trap/handle these exceptions. They simply blow up my code.

what exceptions? can you give some example?

I'm way late getting back on this, sorry. But I'm still having the same problem. For example, when I call the function below, and pass in a bad or expired credit card, it just blows up and throws an unhandled exception. The catch block is never entered. The exception is never handled. I also tried putting the catch block around the caller of the function (1 step higher in the call stack), with exactly the same results. Am I doing my try/catch wrong? It seems this is more of a php problem than an authnet problem, but it's still irritating that authnet throws an exception rather than returning error strings so it can be more easily handled. Please help.

 

 

function CreatePaymentProfile($profileID, $ccNumber, $ccExpirationDate, $firstName, $lastName){
// expiration date required format: 2023-12
$content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<createCustomerPaymentProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
MerchantAuthenticationBlock() .
"<customerProfileId>$profileID</customerProfileId>
<paymentProfile>
<billTo>
<firstName>$firstName</firstName>
<lastName>$lastName</lastName>
<company></company>
<address></address>
<city></city>
<state></state>
<zip></zip>
<country>USA</country>
<phoneNumber></phoneNumber>
<faxNumber></faxNumber>
</billTo>
<payment>
<creditCard>
<cardNumber>$ccNumber</cardNumber>
<expirationDate>$ccExpirationDate</expirationDate>
</creditCard>
</payment>
</paymentProfile>
<validationMode>liveMode</validationMode>
</createCustomerPaymentProfileRequest>";

//die($content);

try {
$response = send_xml_request($content);
$parsedresponse = parse_api_response($response);
return $parsedresponse;
}catch (Exception $e) {
writeme("Error: " . $e->getMessage());
}
}

 

It the from the sample code? the XML itself do not throw exception, but probabaly in the parse_api_response method. echo the $response directly to see what you need to do to check for the error.