cancel
Showing results for 
Search instead for 
Did you mean: 

Class SampleCode\Constants not found

Hi all,
I'm trying to test the API running one of the built-in examples but I have an error.

I've downloaded this sdk: https://github.com/AuthorizeNet/sdk-php/archive/1.8.9.zip
Then I've downloaded this sample code: https://github.com/AuthorizeNet/sample-code-php
I've added to the code of the file charge-credit-card.php  this line:
require '/home/ubuntu/testAuthorize/sdk-php/autoload.php';

But when I run the command: "php PaymentTransactions/charge-credit-card.php" I have this error:
PHP Fatal error:  Class 'SampleCode\Constants' not found in /home/ubuntu/testAuthorize/sample-code-php-master/PaymentTransactions/charge-credit-card.php on line 64

which is the problem?

Thank you

Claudio

ilclaudio
Member
6 REPLIES 6

Hello @ilclaudio

 

After you installed the SDK, did you perform a composer update?

 

Richard

RichardH
Administrator Administrator
Administrator

I am having the exact same issue, I did a composer update.

 

[root@voice1 RecurringBilling]# php create-subscription.php
PHP Fatal error: Uncaught Error: Class 'SampleCode\Constants' not found in /tmp/authorize/authorize-2/sample-code-php-master/RecurringBilling/create-subscription.php:13
Stack trace:
#0 /tmp/authorize/authorize-2/sample-code-php-master/RecurringBilling/create-subscription.php(74): createSubscription(23)
#1 {main}
thrown in /tmp/authorize/authorize-2/sample-code-php-master/RecurringBilling/create-subscription.php on line 13
[root@voice1 RecurringBilling]#

I am having the exact same issue as well.

 

Looking at the documentation here http://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card the only valid response is 'Error' or Ok. I updated the code from:

 

if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK)

 

to:

if($response->getMessages()->getResultCode() == 'Ok' || $response->getMessages()->getResultCode() == 'Error'){

Hello,

 

it's a little late answer, but it can help other users if they visite this post for the same issue.

 

You get this error because your script don't know the "SampleCode" spacename, and the "Constants" class, to extract constants values from it.

 

to solve it you must include this file from Github "sample-code-php/constants/Constants.php", at the very top of your script (charge-credit-card.php for exemple), and it will work fine.

 

Don't forget to update informations inside this file, and add your's if you want to use them the same way.

molmi
Member

Confirmed. Had the same problem. Added this at the top:

 

require 'constants/Constants.php';

Note: I moved the "constants" folder from the sample-code-php folder into the sdk-php folder.