cancel
Showing results for 
Search instead for 
Did you mean: 

isError seems to always return true

Switched to using AuthnetXML.class.php for all api calls.  When I add a payment profile to a customer profile, I'll get a response like this:

 

<createCustomerPaymentProfileResponse>
  <messages>
    <resultCode>Ok</resultCode>
    <message>
      <code>I00001</code>
      <text>Successful.</text>
    </message>
  </messages>
  <customerPaymentProfileId>8227492</customerPaymentProfileId>
</createCustomerPaymentProfileResponse>

 

but even though it's successful, I find that $xml->isError() always returns 1.   Am I missing something?

alanm123
Contributor
1 ACCEPTED SOLUTION

Accepted Solutions

I was able to verify this bug. It's kinda odd since all I did was change comparison operators from === to == and it works properly now. In this case === should work so I'm going to see if i can figure out why it doesn't out of curiousity.  

 

If you go to github you can get the updated code or just edit your Authnet.class.php file like so:

 

    public function isSuccessful()
    {
        return $this->response_xml->messages->resultCode === 'Ok';
    }

    public function isError()
    {
        return $this->response_xml->messages->resultCode !== 'Ok';
    }

 becomes

 

    public function isSuccessful()
    {
        return $this->response_xml->messages->resultCode == 'Ok';
    }

    public function isError()
    {
        return $this->response_xml->messages->resultCode != 'Ok';
    }

 


-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Handling Authorize.Net's Webhooks with PHP

Integrate Every Authorize.Net JSON API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post

View solution in original post

5 REPLIES 5

Does this happen with any other APIs calls? Or only this one?

 


-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Handling Authorize.Net's Webhooks with PHP

Integrate Every Authorize.Net JSON API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post
stymiee
Expert
Expert

Seems to happen with others as well.  I haven't tried all, of course, but here's another example.  If I run

$xml->createTransactionRequest($my_request_array);

per the example in authnetxml\examples\aim\createTransactionRequest_authCapture.php, I get the following odd result:  

 

Results

ResponseOk
codeI00001
Successful?no
Error?yes
authCodeYRZ26K
transId2177473315

 

 

The php for the Successful? and Error? values is this:

<?php echo ($xml->isSuccessful()) ? 'yes' : 'no'; ?>
<?php echo ($xml->isError()) ? 'yes' : 'no'; ?>
 

 

And the raw $xml Input/Output shows this:

Class ParametersRequest XMLResponse XML

API Login ID--removed--
Transaction Key--removed--
Authnet Server URLhttps://apitest.authorize.net/xml/v1/request.api
XML:
<?xml version="1.0"?>
<createTransactionRequest>
  <merchantAuthentication>
    <name>--removed--</name>
    <transactionKey>--removed--</transactionKey>
  </merchantAuthentication>
  <transactionRequest>
    <transactionType>authCaptureTransaction</transactionType>
    <amount>10</amount>
    <payment>
      <creditCard>
        <cardNumber>370000000000002</cardNumber>
        <expirationDate>012014</expirationDate>
      </creditCard>
    </payment>
  </transactionRequest>
</createTransactionRequest>

XML:
<?xml version="1.0" encoding="utf-8"?>
<createTransactionResponse>
  <messages>
    <resultCode>Ok</resultCode>
    <message>
      <code>I00001</code>
      <text>Successful.</text>
    </message>
  </messages>
  <transactionResponse>
    <responseCode>1</responseCode>
    <authCode>YRZ26K</authCode>
    <avsResultCode>Y</avsResultCode>
    <cvvResultCode/>
    <cavvResultCode>2</cavvResultCode>
    <transId>2177473315</transId>
    <refTransID/>
    <transHash>E1EEC3AF4D823851243E2810EBFF5E95</transHash>
    <testRequest>0</testRequest>
    <accountNumber>XXXX0002</accountNumber>
    <accountType>AmericanExpress</accountType>
    <messages>
      <message>
        <code>1</code>
        <description>This transaction has been approved.</description>
      </message>
    </messages>
  </transactionResponse>
</createTransactionResponse>

 

 

 

Weird, no?

I'm running under a sandbox/test account, of course.  Would that matter?

So I need to know: 

 

1. Am I doing something wrong?

2. Is there a problem with AuthnetXML?

3. Should I ignore the isError and isSuccessful values and just test for messages->resultCode == "OK" ?

4. Is AuthnetXML the official Authorize.Net recommended way to go, or should I go back to using the individual api classes? 

 

Thanks

I was able to verify this bug. It's kinda odd since all I did was change comparison operators from === to == and it works properly now. In this case === should work so I'm going to see if i can figure out why it doesn't out of curiousity.  

 

If you go to github you can get the updated code or just edit your Authnet.class.php file like so:

 

    public function isSuccessful()
    {
        return $this->response_xml->messages->resultCode === 'Ok';
    }

    public function isError()
    {
        return $this->response_xml->messages->resultCode !== 'Ok';
    }

 becomes

 

    public function isSuccessful()
    {
        return $this->response_xml->messages->resultCode == 'Ok';
    }

    public function isError()
    {
        return $this->response_xml->messages->resultCode != 'Ok';
    }

 


-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Handling Authorize.Net's Webhooks with PHP

Integrate Every Authorize.Net JSON API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post

Thank you!!  I've corrected my copy of the file.  Hey, I'd love to know why the === doesn't work, if you ever figure that out!