pandaD
pandaD

Reputation: 103

Class 'Stripe\Stripe' not found

I've installed the stripe library with composer, and I have a problem that is only on one page (see picture here :

enter image description here

my code in cancelStripeSubscription.php :

Stripe\Stripe::setApiKey("my key here");

$sub = \Stripe\Subscription::retrieve($getSubId);
$sub->cancel();

I really don't understand why it's not working since it works in other files in the same directory.

error showing : "Fatal error: Class 'Stripe\Stripe' not found in D:\wamp64\www\etape4Prestige\"

Thanks in advance for helping!

Upvotes: -1

Views: 651

Answers (3)

Ken
Ken

Reputation: 455

According to the Strip-php documentation, under manual install, https://github.com/stripe/stripe-php, while Composer is recommended, when not available you can substitute the following at the top of your script:

require_once '/path/to/stripe-php/init.php';

In my specific use case, my development environment uses composer with no issue, but in production environment, stripe does get loaded correctly. So I placed the following code right after the namespace line.

if (!class_exists(\Stripe\Stripe::class)) {
  require_once '../vendor/stripe/stripe-php/init.php';    
}

Basically if the class was not loaded, loaded it. This works for me in both production and development environments.

Upvotes: 0

Manoj Patel
Manoj Patel

Reputation: 329

I have also installed and got the same error, You need to call stripe library like below by creating an object of Stripe not by scope resolution operator(::)

$stripe_obj = new Stripe();
$stripe = $stripe_obj->setApiKey(env('STRIPE_SECRET'));

Upvotes: -1

You could use autoloader to actually include the Stripe classes...

require_once('vendor/autoload.php');

This should do the trick if the library is installed with composer I guess...

Upvotes: 0

Related Questions