Getting a fatal error when autoloading a PHP class

谁说我不能喝 提交于 2020-01-11 12:15:13

问题


I am attempting to use Cartalyst, a comprehensive PHP Library for Stripe payments. Here is a link to their documentation: https://cartalyst.com/manual/stripe/1.0. Here is the code I am trying to get to work:

$stripe    = Stripe::make('your-stripe-api-key');
$customers = $stripe->customers()->all();

foreach ($customers['data'] as $customer) {
    var_dump($customer['email']);
}

When I run the code above (in my real code I have my api inserted), I receive the following error: Fatal error: Class 'Stripe' not found in on line 247. I have triple-checked everything I know to check and I cannot seem to figure out what the issue is. I have "autoloaded" the Stripe Cartalyst library and the Stripe library.

Also, here is my composer code that is generating the autoload files:

{
    "require": {
        "cartalyst/stripe": "~1.0",
        "stripe/stripe-php": "3.*"
    }
}

回答1:


It needs the namespace \Stripe, try:

 \Stripe\Stripe::setApiKey('your-stripe-api-key');


来源:https://stackoverflow.com/questions/32939034/getting-a-fatal-error-when-autoloading-a-php-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!