0
votes

Trying to get the Hello World example for Authorize.net to work

Composer is installed here is json. almost identical to their example.

{
"require": {
    "symfony/console": "^3.3",
    "php": ">=5.6",
    "ext-curl": "*",
    "authorizenet/authorizenet": ">=1.9.3"    
}
}

the following was cut & pasted from ssh

>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files

The only thing I've changed in the Hello World PHP example is my sandbox login ID and transaction key and the path to vendor/autoload.php.

What am I missing here to get this example to return something other than

Charge Credit Card ERROR : Invalid response

1
I changed the example to the one provided in github sample-code-php-master.zip and now my error is Transaction Failed Error Code : E00003 Error Message : The 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:name' element is invalid - The value 'F9lTBd40K839Bucfq3Sz_DKqW2j2Xo7i' is invalid according to its datatype 'String' - The actual length is greater than the MaxLength value.Mike Volmar
According to their developer website CODE: E00003 EXPLANATION: An error occurred while parsing the XML request.Mike Volmar
I updated the code yet again, from the example code here: developer.authorize.net/api/reference/… , and now am getting this error, which the error code lookup tool says in an invalid error code! Transaction Failed Error Code : E00124 Error Message : The provided access token is invalidMike Volmar
ps. running the samples here in the broswer interface works developer.authorize.net/api/reference/… it is only when I try and run a php file that I get the errorMike Volmar
The basic Hello World example is now working, developer.authorize.net/hello_world , but the other is not. Not sure why. Same errorMike Volmar

1 Answers

0
votes

Solution to this problem was rather simple. Posting solution here to pay it forward. First, this all you need for a basic working composer.json

{
"require": {
    "symfony/console": "^3.3",
    "authorizenet/authorizenet": ">=1.9.3"    
}
}

You probably don't even need symphony. By the way, I'm running php 5.6 and TLS 1.2, which are required.

Second, there is a scope issue in the example code. Here are the first few lines of the charge credit card example code, which works in the authorize.net browser sandbox fine.

function chargeCreditCard($amount)
{

$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);

Here is what I changed it to in my php script that DID NOT work.

    function chargeCreditCard(){

    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName($AuthorizeLoginID);
    $merchantAuthentication->setTransactionKey($AuthorizeTransKey); 

Here is what I changed it to that DOES work.

    function chargeCreditCard(){

    global $AuthorizeLoginID, $AuthorizeTransKey;

    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName($AuthorizeLoginID);
    $merchantAuthentication->setTransactionKey($AuthorizeTransKey); 

Kinda mad at myself for not seeing the scope issue with the credentials sooner, but I eventually figured it out by process of elimination.