Wrong use statement for Stripe in a Symfony2 Controller

320 Views Asked by At

I'm using Stripe to make Payments for my Symfony2 web application and get an error trying to use the Stripe methods.

Attempted to load class "Stripe_Charge" from namespace "UserBundle\Controller".
Did you forget a "use" statement for another namespace?

I used composer to include the Stripe librarie like this :

Composer :

"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.8.*",
    [...]
    "stripe/stripe-php": "dev-master"
}

In my controller, I have the executePaymentAction function but I have an error using Stripe in it.

Here is my Controller :

<?
namespace UserBundle\Controller;

use Stripe\Stripe;

class RegistrationSellerController extends Controller
{
    public function executePaymentAction(Request $request){

        $data = $request->request->all();

        Stripe::setApiKey('pk_test_***');
        try {
            Stripe_Charge::create([
                'amount' => 2000, // this is in cents: $20
                'currency' => 'usd',
                'card' => $_POST['stripeToken'],
                'description' => 'product description'
            ]);
        } catch (Stripe_CardError $e) {
            // Declined. Don't process their purchase.
            // Go back, and tell the user to try a new card
        }
    }
}
1

There are 1 best solutions below

2
On

The error message is pretty obvious: You forgot the use statement for class Stripe_Charge