cmcg182
cmcg182

Reputation: 83

Laravel 4 - Class 'Stripe' not found

I'm trying to install Stripe into my project but I'm having issues. I'm getting the error

Class 'Stripe' not found

I used

composer require stripe/stripe-php

and everything installed fine, but I'm still having issues.

This is the line that is causing the problem:

Stripe::setApiKey(Config::get('stripe.secret_key'));

This is my composer.json file:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.2.*",
        "intervention/image": "dev-master",
        "moltin/laravel-cart": "dev-master",
        "stripe/stripe-php": "~2.0@dev"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/libs",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"

        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

There is nothing about Stripe in my app/config/app.php file... I'm not sure if there should be a service provider for Stripe.

Upvotes: 2

Views: 6162

Answers (1)

Alana Storm
Alana Storm

Reputation: 166066

Looking at packagist, you can see the composer package stripe/stripe-php point to the following GitHub repository. Based on that repository's code and the Stripe API documentation, it doesn't look like there's a global class named Stripe defined. So when you say

Stripe::setApiKey(Config::get('stripe.secret_key'));

and PHP says

Class 'Stripe' not found

PHP is telling you the truth. There is a class named Stripe\Stripe -- so you probably want to do this

\Stripe\Stripe::setApiKey(Config::get('stripe.secret_key'));

or import the class into your current PHP file with the use statement

<?php
//...
use Stripe\Stripe;
//...
Stripe::setApiKey(Config::get('stripe.secret_key'));

Upvotes: 5

Related Questions