phpcomposer-phpbolt-cms

Error: Class 'Stripe' not found


I'm trying to use the Stripe php api in a Bolt extension but it's having trouble finding the class. I added the Stripe library to composer.json:

"require": {
    "stripe/stripe-php": "1.*"
}

And ran composer install. myextension/vendor/composer/autoload_classmap.php now shows the classes loaded:

$vendorDir = dirname(dirname(__FILE__));

return array(
    'Stripe' => $vendorDir . '/stripe/stripe-php/lib/Stripe/Stripe.php',
    'Stripe_Account' => $vendorDir . '/stripe/stripe-php/lib/Stripe/Account.php',
    'Stripe_ApiConnectionError' => $vendorDir . '/stripe/stripe-php/lib/Stripe/ApiConnectionError.php',
    'Stripe_ApiError' => $vendorDir . '/stripe/stripe-php/lib/Stripe/ApiError.php',
    ...

And now I'm trying to use it in the extension like this:

use Stripe, Stripe_Customer, Stripe_Charge, Stripe_Plan, Stripe_Coupon, Stripe_Error;

public function initialize()
{
    $stripe = new Stripe();
    $stripe->setApiKey($this->config['stripe_key']);

But I get the error:

Error: Class 'Stripe' not found
File: extensions/local/andyjessop/myextension/Extension.php

I still haven't got my head round autoloading, so I think I'm doing something basic wrong, but I can't see what it is. Can anyone help?


Solution

  • You should include the composer autoload file.

    require_once('vendor/autoload.php');