1

I'm trying to implement Stripe Checkout into my website. I am using Composer, everything seems to go right, but when I add my private key into init.php line 17:

 Stripe::setApiKey($stripe['private']);

PHP shows me the following error:

Fatal error: Class 'Stripe' not found in/Applications/MAMP/htdocs/stripe_payment/app/init.php on line 17

Here is the full file:

<?php

session_start();


//composer auto load
require_once 'vendor/autoload.php';

$_SESSION['user_id'] = 3;

$stripe = [
'publishable' => '..... my test key.....',
 'private' => '..... my test key.....'
   ];

//when added brakes the code
Stripe::setApiKey($stripe['private']);

$db = new PDO('mysql:host=localhost;dbname=stripe_custom;','root','root');

$userQuery = $db->prepare("
    SELECT id, username, email, premium
FROM users
WHERE id = :user_id

    ");
$userQuery->execute(['user_id' => $_SESSION['user_id']]);

$user = $userQuery->fetchObject();

?>

I presume that this is something small, but I'm a beginner and I can't figure it out. What am I doing wrong?

1
  • Please remove tag "stripes" - it's not related to your question. Commented Mar 27, 2015 at 11:42

1 Answer 1

1

The latest releases of Stripe's PHP bindings (2.*) are now using Namespaces. This means that most of the API calls have now changed and for example:

Stripe::setApiKey("sk_test_XXX");
Stripe_Customer::create();

would become:

\Stripe\Stripe::setApiKey("sk_test_XXX");
\Stripe\Customer::create();

Otherwise, if you don't want to have to update your code you need to make sure that you download the legacy version (1.18.0).

Sign up to request clarification or add additional context in comments.

1 Comment

Great, that works for me, thank you for your great help. As suggested I added \Stripe\ to the both API calls, and everything working like a dream.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.