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?
โ02-27-2013 06:31 PM
โ03-12-2013 03:47 PM
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.
โ03-14-2013 05:26 AM
what exceptions? can you give some example?
โ03-14-2013 05:38 AM
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()); } }
โ01-04-2014 10:57 AM
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.
โ01-04-2014 12:44 PM