3
votes

I am using the php example from the authorize.net website, but cannot get it to work. I have already downloaded all of the vendor software and updated composer.

In the phplog I keep getting the same error:

<code>E00045</code>
<text>The root node does not reference a valid XML namespace.</text>
</message></messages></ErrorResponse>

After updating composer errors are no longer being logged.

My php:

require("anetsdkphp/autoload.php");
$logName = "MYAUTHKEY";
$transKey = "MYTRANSKEY";
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
function chargeCreditCard($amount){
      // Common setup for API credentials
      $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
      $merchantAuthentication->setName($logName);
      $merchantAuthentication->setTransactionKey($transKey);
      $refId = 'ref' . time();
      // Create the payment data for a credit card
      $creditCard = new AnetAPI\CreditCardType();
      $creditCard->setCardNumber(4111111111111111);
      $creditCard->setExpirationDate(1238);
      $paymentOne = new AnetAPI\PaymentType();
      $paymentOne->setCreditCard($creditCard);
      //create a transaction
      $transactionRequestType = new AnetAPI\TransactionRequestType();
      $transactionRequestType->setTransactionType( "authCaptureTransaction"); 
      $transactionRequestType->setAmount($amount);
      $transactionRequestType->setPayment($paymentOne);
      $request = new AnetAPI\CreateTransactionRequest();
      $request->setMerchantAuthentication($merchantAuthentication);
      $request->setRefId($refId);
      $request->setTransactionRequest($transactionRequestType);
      $controller = new AnetController\CreateTransactionController($request);
      $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

      #$result = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"',
 '', $result);

      if ($response != null)
      {
        $tresponse = $response->getTransactionResponse();
        if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )   
        {
          echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
          echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "\n";
          echo $tresponse->getResponseCode();
        }
        else
        {
            echo  "Charge Credit Card ERROR :  Invalid response\n";
            var_dump("$tresponse");
        }

      }
      else
      {
        echo  "Charge Credit card Null response returned";
      }
  }
chargeCreditCard(55.00);

Response:

Charge Credit Card ERROR : Invalid response(0)
Response after updating composer:
Charge Credit Card ERROR : Invalid response

Thanks very much in advance!

1

1 Answers

1
votes

Your message is a bit old, and I am sure has been resolved. However, the problem is almost definitely your input data. This answer is pretty vague and will not necessarily provide a solution, but it will help you identify the cause.

print_r($response)

You will see the following object representations:

[messages:net\authorize\api\contract\v1\ANetApiResponseType:private] => net\authorize\api\contract\v1\MessagesType Object ( [resultCode:net\authorize\api\contract\v1\MessagesType:private] => Error [message:net\authorize\api\contract\v1\MessagesType:private] => Array ( [0] => net\authorize\api\contract\v1\MessagesType\MessageAType Object ( [code:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => ERROR_CODE_IS_HERE [text:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => ERROR_MESSAGE_IS_HERE)