Fatal error with Stripe Class 'Stripe\Stripe' not found - laravel

I'm trying to implement Stripe Checkout into my website. In local the api work normal but in host I get the error :
Class 'Stripe\Stripe' not found
Note: In my host I don't have SSH. And I added files manually with FTP.
\Stripe\Stripe::setApiKey("sk_test_XXXXXX");
$token = $request->stripeToken;
$customer = \Stripe\Customer::create([
'email' => $client->email,
'source' => $token,
]);

As mentioned you have installed Stripe library manually and uploaded on server.
To use this library include init file.
require_once('/path/to/stripe-php/init.php');
ON next step set Api key, Make sure to use test api key for testing.
\Stripe\Stripe::setApiKey( "sk_test_XXXXXX");
Make sure to download latest stripe library from Githut repo

As i have seen mentioned in the comments:
Stripe needs to be installed using (preferably) composer.
This can be done with the command: composer require stripe after having SSHed into the right directory.
You then need to include the vendor/autoload.php that is generated by composer.
In your case where you cant run composer do the following:
Download stripe`s latest release manually from the github page: https://github.com/stripe/stripe-php/releases
Then you need to include the init.php file found in the downloaded stripe-php directory like this require_once('/path/to/stripe-php/init.php');
Ensure you are running at least PHP 5.4 (Note! This version has reached its end of life. Upgrade if possible to PHP 7.2). You also need the PHP extensions curl, json and mbstring.
After having used require_once('/path/to/stripe-php/init.php'); in the file the stripe code will be running in you can then set your API key using \Stripe\Stripe::setApiKey("sk_test_XXXXXX"); and then run your code like f.ex: $customer = \Stripe\Customer::create([
'email' => $client->email,
'source' => $token,
]);
`

Please use stripe library with the below code to resolve the error
$stripe_obj = new Stripe();
$stripe = $stripe_obj->setApiKey(env('STRIPE_SECRET'));

Related

CodeIgniter 4 plus Myth/Auth throws error when running Migrations via php spark migrate -all

I have discovered some wired behavior, I have that one CI4 project i am working on since a couple of weeks. everything is working just fine, but until now i have just been working with the project on my local machine. When i wanted to run the project on my Laptop in ran into an error when i tried to run the migrations with php spark migrate -all
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-07-20 06:16:02am
Running all new migrations...
An uncaught Exception was encountered
Type:        CodeIgniter\Database\Exceptions\DatabaseException
Message:     Unable to connect to the database.
Filename:    /opt/lampp/htdocs/sms/vendor/codeigniter4/framework/system/Database/BaseConnection.php
Line Number: 425
The project includes Myth/auth, so i tried just to run "my" migration with php spark migrate . That just worked fine, no problem at all, the tables are there, no errors. Just for fun, i moved my Math/auth migrations from the vendor folder to the "normal" Database/Migrations folder and was able to migrate them that way.
That's very wired, especially since everything is working just fine on the PC I have been using before. There I am able to run the migrations using php spark migrate -all without any errors, when is set up a fresh MySQL/MariahDB database. But somehow only there.
I was able to reproduce the error on my laptop on my Manjaro partition, my Windows 10 partition and on my iMac.
So if you want to reproduce the error do the following:
composer create-project codeigniter4/appstarter whatever
rename the env to .env
set CI_ENVIRONMENT = development and obviously uncomment that line
configure and uncomment your database setting in the .env
create a sample migration like the one from the docs using > php spark migrate:create AddBlog
add the following content to the new migration and save the file:
forge->addField([
'blog_id' => [
'type' => 'INT',
'constraint' => 5,
'unsigned' => true,
'auto_increment' => true,
],
'blog_title' => [
'type' => 'VARCHAR',
'constraint' => '100',
],
'blog_description' => [
'type' => 'TEXT',
'null' => true,
],
]);
$this->forge->addKey('blog_id', true);
$this->forge->createTable('blog');
}
public function down()
{
$this->forge->dropTable('blog');
}
}
run > composer require myth/auth
Edit app/Config/Email.php and verify that a fromName and fromEmail are set as that is used when sending emails for password reset, etc.
Edit app/Config/Validation.php and add the following value to the ruleSets array: \Myth\Auth\Authentication\Passwords\ValidationRules::class
Ensure your database is setup correctly, then run the Auth migrations: php spark migrate -all
As a result you will also have the above error. I was not able to
get around that error, except for the system in was working with at
first.
If you just use php spark migrate it will migrate the sample migration without any errors
I am running CI 4.04 on Kubuntu 18.04 LTS, running apache2.4.29 and PHP 7.4.9
The short answer is...
Using php spark migrate -all searches everywhere it knows about for Database/Migrations Folders and files.
There just so happens to be a such folder/file under
tests/_support/Database/Migrations/2020-02-22-222222_example_migration.php
The bits added to make the short answer longer
So the Database error we are seeing is due to not having set up Database credentials for $tests in /app/Config/Database.php
All it's doing is looking to connect to the DB set up under $tests, but appears not to actually run as we don't want it to.
That appears to be enabled when ENVIRONMENT is set to "testing".
So 3 options for the time being...
Ignore the error. But that always leaves you wondering what's really happening.
Setup the credentials for the $tests Database. (Not really warranted.) OR
Delete/Rename the tests folder if you are not using it. (Stop it finding it.)
Would be to use the -n switch/option and specify the namespace to use (but not sure that's working.)
Changing DB hostname to '127.0.0.1' from localhost in your .env file usually solves the problem of running any migrations from the command line.
Open your PHP.ini file, find this :
;extension=sqlite3
and remove the semicolon to activate sqlite3. You need this library in Codeigniter 4 in order to use FORGE.

Class 'GuzzleHttp\Client' not found on Laravel production shared server

I'm trying to retrieve data from an API using Guzzle. I followed the steps in Guzzle website, installed it using composer, added the route and the code in a controller.
I tried these two options:
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'https://jsonplaceholder.typicode.com/',
// You can set any number of default request options.
'timeout' => 2.0,
]);
and...
$client = new \GuzzleHttp\Client([
// Base URI is used with relative requests
'base_uri' => 'https://jsonplaceholder.typicode.com/',
// You can set any number of default request options.
'timeout' => 2.0,
]);
When running I got the error...
Class 'GuzzleHttp\Client' not found.
I have tried:
require( dirname( __FILE__ ) . '/../../../vendor/autoload.php');
use GuzzleHttp\Client;
In composer.json:
"require": {
"guzzlehttp/guzzle": "^6.3",
...
},
Also...
composer update
composer dump-autoload
php artisan config:clear
The project is on shared hosting; I noticed that there was no Guzzle folder inside the /vendor folder, so I uploaded via FTP. But still the same error.
I've tried everything I found in the forum on this topic; I'm running out of ideas, please any advice would be appreciated.
Thanks in advance for your valuable help.
If you can't run composer on shared hosting, you should upload also /vendor/composer directory (after local $ composer require guzzlehttp/guzzle).

Invalid API key: You must be granted a valid key tmdb laravel 5.5

i am trying to install php-tmdb/laravel on my laravel 5.5 but getting error on basic test
Invalid API key: You must be granted a valid key
i try with google and found this link https://github.com/php-tmdb/laravel/issues/38
but its not working or can't understand
help me
auto discovery in this package is not working correctly
just add this on providers
config/app.php
Tmdb\Laravel\TmdbServiceProvider::class,
everything is working fine now
According to the github README.md https://github.com/php-tmdb/laravel
After you install the package, run this command to publish the configuration file:
php artisan vendor:publish --provider="Tmdb\Laravel\TmdbServiceProviderLaravel5"
then edit this file: config/tmdb.php in your application with your api key.
The configuration file should look like this:
https://github.com/php-tmdb/laravel/blob/master/src/config/tmdb.php
Notice 'api_key' => '', fill this in and then re-run your code/test.
Here's where you get your API key from: https://developers.themoviedb.org/3/getting-started
After changing the config, for good measure; clear your config cache with this command:
php artisan config:clear
edit /vendor/php-tmdb/laravel/src/config/tmdb.php
find 'api_key' => '', and add your key here.

Laravel 4 : Call to undefined method Redis::connection()

I'm going crazy about this error.
I've got a vagrant VM with Debian 7, generated with Puphpet, installation was fine.
1. Redis is installed and working
redis-server is running :
I can use the server on 127.0.0.1:6379 :
2. php5-redis is installed
php5-redis is actually installed :
3. Laravel Redis config is set
Here is my redis config file in app/local/database.php :
'redis' => [
'cluster' => false,
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
],
],
4. The call to Redis is simple :
// Get redis
$redis = Redis::connection();
5. I tried a lot of things
sudo service nginx reload
sudo service redis-server force-reload
composer dumpautoload
But nothing solved the error.
I'm still having :
ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method Redis::connection()' in /var/www/fd/app/menus/admin.menu.php:16
(line 16 is where I do the connection $redis = Redis::connection();)
Where am I wrong ?
Btw, I hate mondays >.>
I came across this after encountering this issue and wanted to add another answer in case it helps someone else.
In my case there was an alias collision because my php configuration has the PHP-Redis module/extension enabled -- both the PHP module and Laravel seem to have a conflicting object named Redis. I was able to resolve this simply by using the entire namespaced identifier:
//$r = Redis::connection()
$r = Illuminate\Support\Facades\Redis::connection();
The problem isn't with your redis server setup -- there's something mis-configured or changed in your system.
The error you're seeing
Call to undefined method Redis::connection()
Is PHP telling you it can't find a method named connection on the class Redis. It's a PHP error, and PHP never gets around to trying to talk to the redis server.
Normally, in a Laravel 4.2 system, there is no class named Redis. Instead, an alias is setup in app/config/app.php
#File: app/config/app.php
'Redis' => 'Illuminate\Support\Facades\Redis',
which turns Redis into a facade. This is what enables you to make calls like Redis::connection.
So, there's something wrong with your system. Either you
Have a custom class named Redis somewhere that's loaded before the aliases are setup
Have Redis aliased to something other than a the Illuminate\Support\Facades\Redis facade class
You Redis facade class has been modified to return a service identifier other than redis
You've rebound the redis service as some other class
Per the comments below, you have the Redis PHP extension installed and the global extension class "wins"
To find out where PHP thinks the Redis class is, try
$r = new ReflectionClass('Redis');
var_dump($r->getClassFile());
To see if #4 is the problem, try calling the service directly
$app = app();
$app['redis']->connection();
Good luck!
That error is because you have installed and enabled the module php5-redis, it became with the class Redis. To avoid that error and use the Laravel Redis Facade, you have to change the alias in app/config/app.php (or whatever is your environment).
'Redis' => 'Illuminate\Support\Facades\Redis'
'RedisFacade' => 'Illuminate\Support\Facades\Redis' //whatever you like
or just configure your cache.php to use Redis and use only the Cache class. :)
Install Redis extension on your PC.
Download the CORRECT version the DDL from the following link:
https://pecl.php.net/package/redis/4.1.0/windows
Put the dll in the correct folder
Wamp -> C:\wamp\bin\php\php-XXXX\ext
Laragon -> C:\laragon\bin\php\php-XXX\ext
Edit the php.ini file adding
extension=php_redis.dll
Restart server and check phpinfo();. Now Redis should be there!

Integrating Doctrine with CodeIgniter

I have successfully installed the latest version of CodeIgniter and have basic MVC pattern working. The problem that I've noticed is that CI doesn't naturally allow for prepared statements when it comes to queries. So, I decided to download Doctrine 1 from GitHub. I'm very new to Doctrine and needed some help integrating it with CI so I followed this tutorial.
In one of my controllers, I have
$this->load->library('doctrine');
$this->em = $this->doctrine->em;
But, when I go to load the view in my browser, I'm greeted with an error reading
Message: require_once(/Applications/MAMP/htdocs/CodeIgniter/application/libraries/Doctrine/Common/ClassLoader.php): failed to open stream: No such file or directory
Upon further inspection of the Doctrine download from GitHub, there doesn't even seem to be a folder titled "common" anywhere in there. I'm very new to CI and especially Doctrine. Does anyone have some advice that can help me get this working? Also, is it possible to use the MySQLi driver instead of the PDO one with Doctrine?
Downloading the Doctrine ORM straight from GitHub doesn't include the other dependencies. These are managed by Composer. If you look inside the composer.json file you can see these dependencies. If you want to install them manually, they are:
doctrine/common
doctrine/inflector
doctrine/cache
doctrine/collections
doctrine/lexer
doctrine/annotations
doctrine/dbal
symfony/console
I believe that's all of them. You will have to merge these files in their appropriate directories as they follow PSR-0 standards for the autoloading of classes.
Alternatively, install Doctrine 2 with Composer with the following composer.json file and any other dependencies will be installed automatically. Then integrate with CodeIgniter.
{
"minimum-stability": "stable",
"require": {
"doctrine/orm": "2.3.*"
}
}
Edit the index.php file of your CodeIgniter app by adding a single line to include the autoloader file before requiring the CodeIgniter core.
require_once BASEPATH.'../vendor/autoload.php';
require_once BASEPATH.'core/CodeIgniter.php';
Also if installing with Composer, use this edited version of the bootstrap as the contents of application/libraries/Doctrine.php, which is what worked for me
<?php
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Tools\Setup,
Doctrine\ORM\EntityManager;
class Doctrine
{
public $em;
public function __construct()
{
// Load the database configuration from CodeIgniter
require APPPATH . 'config/database.php';
$connection_options = array(
'driver' => 'pdo_mysql',
'user' => $db['default']['username'],
'password' => $db['default']['password'],
'host' => $db['default']['hostname'],
'dbname' => $db['default']['database'],
'charset' => $db['default']['char_set'],
'driverOptions' => array(
'charset' => $db['default']['char_set'],
),
);
// With this configuration, your model files need to be in application/models/Entity
// e.g. Creating a new Entity\User loads the class from application/models/Entity/User.php
$models_namespace = 'Entity';
$models_path = APPPATH . 'models';
$proxies_dir = APPPATH . 'models/Proxies';
$metadata_paths = array(APPPATH . 'models');
// Set $dev_mode to TRUE to disable caching while you develop
$config = Setup::createAnnotationMetadataConfiguration($metadata_paths, $dev_mode = true, $proxies_dir);
$this->em = EntityManager::create($connection_options, $config);
$loader = new ClassLoader($models_namespace, $models_path);
$loader->register();
}
}
Note: Version 3 of CodeIgniter when released, will be installable with Composer, but version 2 is not.
For those looking for a tutorial to integrate Doctrine 2 with CodeIgniter, this question and others answers are outdated (for CI 2).
This is a new tutorial for CI 3 I made and I checked is working:
How to install Doctrine 2 in CodeIgniter 3
I repeat it here.
Install Doctrine
Doctrine 2 ORM’s documentation - Installation and Configuration
Doctrine can be installed with Composer.
Define the following requirement in your composer.json file:
{
"require": {
"doctrine/orm": "*"
}
}
Then call composer install from your command line.
Integrating with CodeIgniter
Doctrine 2 ORM’s documentation - Integrating with CodeIgniter
Here are the steps:
Add a php file to your system/application/libraries folder called Doctrine.php. This is going to be your wrapper/bootstrap for the D2 entity manager.
Put the Doctrine folder (the one that contains Common, DBAL, and ORM) inside the third_party folder.
If you want, open your config/autoload.php file and autoload your Doctrine library: $autoload[‘libraries’] = array(‘doctrine’);
Creating your Doctrine CodeIgniter library
Now, here is what your Doctrine.php file should look like. Customize it to your needs.
<?php
/**
* Doctrine 2.4 bootstrap
*
*/
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\Common\Cache\ArrayCache,
Doctrine\DBAL\Logging\EchoSQLLogger;
class Doctrine {
public $em = null;
public function __construct()
{
// load database configuration from CodeIgniter
require_once APPPATH.'config/database.php';
// include Doctrine's ClassLoader class
require_once APPPATH.'third_party/Doctrine/Common/ClassLoader.php';
// load the Doctrine classes
$doctrineClassLoader = new ClassLoader('Doctrine', APPPATH.'third_party');
$doctrineClassLoader->register();
// load the entities
$entityClassLoader = new ClassLoader('Entities', APPPATH.'models');
$entityClassLoader->register();
// load the proxy entities
$proxiesClassLoader = new ClassLoader('Proxies', APPPATH.'models/proxies');
$proxiesClassLoader->register();
// load Symfony2 classes
// this is necessary for YAML mapping files and for Command Line Interface (cli-doctrine.php)
$symfonyClassLoader = new ClassLoader('Symfony', APPPATH.'third_party/Doctrine');
$symfonyClassLoader->register();
// Set up the configuration
$config = new Configuration;
// Set up caches
if(ENVIRONMENT == 'development') // set environment in index.php
// set up simple array caching for development mode
$cache = new \Doctrine\Common\Cache\ArrayCache;
else
// set up caching with APC for production mode
$cache = new \Doctrine\Common\Cache\ApcCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// set up annotation driver
$driver = new \Doctrine\ORM\Mapping\Driver\PHPDriver(APPPATH.'models/Mappings');
$config->setMetadataDriverImpl($driver);
// Proxy configuration
$config->setProxyDir(APPPATH.'/models/Proxies');
$config->setProxyNamespace('Proxies');
// Set up logger
$logger = new EchoSQLLogger;
$config->setSQLLogger($logger);
$config->setAutoGenerateProxyClasses( TRUE ); // only for development
// Database connection information
$connectionOptions = array(
'driver' => 'pdo_mysql',
'user' => $db['default']['username'],
'password' => $db['default']['password'],
'host' => $db['default']['hostname'],
'dbname' => $db['default']['database']
);
// Create EntityManager, and store it for use in our CodeIgniter controllers
$this->em = EntityManager::create($connectionOptions, $config);
}
}
Setting up the Command Line Tool
Doctrine ships with a number of command line tools that are very helpful during development.
Check if these lines exists in the Doctrine.php file, to load Symfony classes for using the Command line tools (and for YAML mapping files):
$symfonyClassLoader = new ClassLoader('Symfony', APPPATH.'third_party/Doctrine');
$symfonyClassLoader->register();
You need to register your applications EntityManager to the console tool to make use of the tasks by creating a cli-doctrine.php file in the application directory with the following content:
<?php
/**
* Doctrine CLI bootstrap for CodeIgniter
*
*/
define('APPPATH', dirname(__FILE__) . '/');
define('BASEPATH', APPPATH . '/../system/');
define('ENVIRONMENT', 'development');
require APPPATH.'libraries/Doctrine.php';
$doctrine = new Doctrine;
$em = $doctrine->em;
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);
?>
Now run this script through the PHP command-line and should see a list of commands available to you.
php cli-doctrine.php
Generate mapping classes from database:
php cli-doctrine.php orm:convert-mapping --from-database annotation models/Entities
if you get this error:
Fatal error: Call to undefined function Doctrine\Common\Cache\apc_fetch()
install the APC extension for PHP:
sudo apt-get install php-apc
sudo /etc/init.d/apache2 restart
For production mode you'll want to use a real caching system like APC, get rid of EchoSqlLogger, and turn off autoGenerateProxyClasses in Doctrine.php
Find the link for the doctrine integration in CI
https://github.com/mitul69/codeigniter-doctrine-integration
Please note that code igniter 2 has a little difference in its code organization. In code igniter 2 it is better to put the Doctrine folder in application/third_party folder, instead of application/libraries folder (or else it will not work!).
You can read more about it here
I had the same problem when I tried to follow this tutorial from doctrine user guide
http://doctrine-orm.readthedocs.org/en/latest/cookbook/integrating-with-codeigniter.html
This problem happens when I tried to install via composer so then I went to this web site
http://www.doctrine-project.org/downloads/ and do manually download the DoctrineORM-2.3.3-full.tar.gz version and the error was gone.
The original poster's problem seems to be an issue with autoloading. I was presented with a similar issue when trying to set up CodeIgniter and Doctrine with Composer. In CodeIgniter 3, you can enable the use of composer autoloading, which should allow you to load all Doctrine files correctly. You must point your Composer vendor dir to application/vendor for this to work. You can also do it in older versions, but then you have to include the Composer autoload file manually in your Doctrine library file for CodeIgniter.
If you want more information: I wrote a blog post describing exactly how to do it. http://blog.beheist.com/integrating-codeigniter-and-doctrine-2-orm-with-composer/
you can use this
via composer :
composer create-project rbz/codeigniter your-project
via git :
git clone https://github.com/dandisy/cihmvctwig.git

Resources