I'm trying to test Stripe Checkout on my virtual server but when i try return this error:
Fatal error: Class 'Stripe\Customer' not found in /home/user/public_html/charge.php on line 8
As suggested here I verified if the file ./config.php was existing with:
var_dump(file_exists("./config.php"));
It returns bool(true) being a PhP beginner im not sure what i'm doing wrong.
charge.php
<?php
require_once('./config.php');
var_dump(file_exists("./config.php"));
$token = $_POST['stripeToken'];
$customer = \Stripe\Customer::create(array(
'email' => '[email protected]',
'source' => $token
));
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 2000,
'currency' => 'usd'
));
echo '<h1>Successfully charged $20.00!</h1>';
?>
config.php
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => getenv('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => getenv('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
Directory:
>public_html >vendor >stripe >lib >Charge.php >Customer.php >Stripe.php
UPDATE
Okay so with changes suggested by Matthew getting new error. But i'm not sure where should I set the API key Stripe::setApiKey(<API-KEY>)? It's aleady set in config.php...
Fatal error: Uncaught exception 'Stripe\Error\Authentication' with message 'No API key provided. (HINT: set your API key using "Stripe::setApiKey()".in /home/user/public_html/vendor/stripe/lib/ApiRequestor.php:127 Stack trace: #0 /home/user/public_html/vendor/stripe/lib/ApiRequestor.php(59): Stripe\ApiRequestor->_requestRaw('post', '/v1/customers', Array, Array) #1 /home/user/public_html/vendor/stripe/lib/ApiResource.php(115): Stripe\ApiRequestor->request('post', '/v1/customers', Array, Array) #2 /home/user/public_html/vendor/stripe/lib/ApiResource.php(155): Stripe\ApiResource::_staticRequest('post', '/v1/customers', Array, NULL) #3 /home/user/public_html/vendor/stripe/lib/Customer.php(37): Stripe\ApiResource::_create(Array, NULL) #4 /home/user/public_html/charge.php(9): Stripe\Customer::create(Array)
5 {main} thrown in /home/user/public_html/vendor/stripe/lib/ApiRequestor.php on line 127
Fatal error: Class 'Stripe\Customer' not found\vendor\stripe\lib\Customer::createis not how you access namespaced classes - it should be what Matthew posted above.