Reply
Highlighted
Member
Posts: 5
Registered: ‎07-28-2016

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

Highlighted
Posts: 2,765
Topics: 57
Kudos: 247
Blog Posts: 67
Registered: ‎12-05-2011

Re: Class SampleCode\Constants not found

Hello @ilclaudio

 

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

 

Richard

Highlighted
Member
Posts: 5
Registered: ‎09-11-2016

Re: Class SampleCode\Constants not found

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]#

Highlighted
Member
Posts: 5
Registered: ‎09-11-2016

Re: Class SampleCode\Constants not found

I am having the exact same issue as well.

 

Highlighted
Member
Posts: 5
Registered: ‎09-11-2016

Re: Class SampleCode\Constants not found

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'){

Highlighted
Member
Posts: 1
Registered: ‎12-26-2017

Re: Class SampleCode\Constants not found

[ Edited ]

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.

Highlighted
Member
Posts: 1
Registered: ‎03-17-2018

Re: Class SampleCode\Constants not found

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.