Im trying to integrate Stripe using php. I installed laravel and composer.I included composer.json im ny project directory.
I'm trying to execute the first code in php:
<?php
include_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey("sk_test_dlYHzAc5IOD9cU7ceCEHQ7Jm");
\Stripe\Charge::retrieve(
"ch_18XDiTGhJYImFJKGejlLqJiy",
array('api_key' => "sk_test_dlYHzAc5IOD9cU7ceCEHQ7Jm")
)
?>
But in my localhost I take this output:
enter image description here
This is the content of my composer.json file(a part of it where i included stripe API libraries):
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.2.*",
"php": ">=5.5.9",
"stripe/stripe-php": "3.*"
},
Then I run composer install in cmd and this is the output:
enter image description here
Can someone help me to get rid of this error?I've been stuck for days with that.
Regards,
You should include the vendor/autoload.php in order to gain access to composer autoloader features:
include_once('../vendor/autoload.php'); // assuming you are including it from the public folder.
The PHP library installed via Composer. Simply add stripe/stripe-php to in composer.json file:https://stripe.com/docs/libraries#php-library
Related
I am trying to install the asana library through the composer.
Json:
"asana/asana": "^0.10.0" added to composer.json and {
"name": "asana/asana",
"description": "A PHP client for the Asana API",
"type": "library",
"keywords": ["asana", "client"],
"homepage": "https://github.com/Asana/php-asana",
"license": "MIT",
"require": {
"php": ">=5.4.0",
"nategood/httpful": "~0.2",
"adoy/oauth2": "^1.2.0"
},
"require-dev": {
"instaclick/php-code-sniffer": "dev-master",
"phpunit/phpunit": "^9"
},
"autoload": {
"psr-0": {
"Asana\\": "src/"
}
}
}
to composer.lock but getting error 'Package Asana/asana has no version defined.
'
As suggested by #Jeto you should not edit composer.lock manually. To install the library, you can follow the steps mentioned in official docs here.
Assuming that you are doing a fresh install, follow steps below:
Put "asana/asana" package as a dependency in your composer.json file:
{
"require": {
"asana/asana": "^0.10.0"
}
}
Now run the command composer install
composer.lock file will be automatically updated by Composer when installation succeed.
EDIT:
OR
As mentioned by #Jeto in comments, You can simply do this using a single command: composer require asana/asana:^0.10.0
there is a project on Github that works stably. Below is a composer file:
{
"name": "wnull/userbars-warface-generator",
"description": "Simple and free library to generate userbars game Warface",
"keywords": [
"wf",
"warface",
"generator",
"userbars"
],
"type": "library",
"license": "MIT",
"require": {
"php": ">=7.1"
},
"autoload": {
"psr-4": {
"WF\\": "src/WF"
}
}
}
The problem is that after each successful installation of the project through the composer, you have to do the following command:
>>> composer dump-autoload -o
After that, all all classes will work correctly. Log from the console:
C:\hangry>composer require wnull/userbars-warface-generator
Using version ^1.0 for wnull/userbars-warface-generator
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing wnull/userbars-warface-generator (v1.0): Loading from cache
Writing lock file
Generating autoload files
C:\hangry>
C:\hangry>composer dump-autoload -o
Generated optimized autoload files containing 6 classes
Question: how do I avoid entering this command every time, and everything worked correctly during normal installation?
The problem was solved by replacing the PSR-4 to classmap. Thanks #MagnusEriksson.
Composer file:
{
"name": "wnull/userbars-warface-generator",
"description": "Simple and free library to generate userbars game Warface",
"keywords": [
"wf",
"warface",
"generator",
"userbars"
],
"type": "library",
"license": "MIT",
"require": {
"php": ">=7.1"
},
"autoload": {
"classmap": ["src/WF"]
}
}
I have a Laravel app, that use a plugin of mine : "xoco70/kendo-tournaments"
So, to develop it, I added it in a packages/ folder in root of app.
Now, in my composer.json, I used path, to point the local rep, and not to have to go through composer ( and have to version it for each comma I change) :
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.7.*",
"xoco70/kendo-tournaments": "dev-master"
},
"repositories": [
{
"type": "path",
"url": "/packages/xoco70/kendo-tournaments"
}
],
}
Thing is it doesn't work, when I try to composer install / update, it doesn't update the vendor folder.
Is there something I'm missing?
I could make it work
first I added the symlink option:
"repositories": [
{
"type": "path",
"url": "package/xoco70/laravel-tournaments",
"options": {
"symlink": true
}
}
],
Then composer update
If it still doesn't work, delete your vendor package and run composer update again
composer should output this:
- Installing xoco70/laravel-tournaments (dev-master): Symlinking from package/xoco70/laravel-tournaments
You need to run composer init from /packages/xoco70/kendo-tournaments in and use xoco70/kendo-tournaments for the name of the package as well as that packages autoload settings for your project composer to pick it up.
I'm creating my first composer package. I'm testing it by pulling it into a vanilla Laravel project.
The issue I'm having is that when I require my composer package in the main Laravel composer.json file and then try to update the autoload.
My package's composer.json:
{
"name": "cschmitz/l5-simplefm",
"description": "A Laravel 5 wrapper for Soliant Consulting's SimpleFM package.",
"require": {
"soliantconsulting/simplefm": "3.0.*"
},
"license": "MIT",
"authors": [
{
"name": "cschmitz",
"email": "schmitz.chris#gmail.com"
}
],
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"L5SimpleFM\\": "src/"
}
}
}
My package's folder structure in the Laravel project's vendor folder:
My Laravel project's composer.json:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"cschmitz/l5-simplefm": "dev" // Requiring my package here
},
...
After this, I performed a composer dump-autoload. I don't get any errors from composer, but when I check my vendor/composer/autoload_psr4.php file, my namespace isn't listed in the array:
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
...
'App\\' => array($baseDir . '/app'),
// I expected to see `'L5SimpleFM\\' => array($vendorDir . '/cschmitz/L5SimpleFM/src')` as the last key of this array, but nothing shows past the App key
);
I looked around online and on stackoverflow, but the various answers and suggestions I found didn't resolve the issue.
Can anyone see what I'm missing?
Update
Per Alexandru Guzinschi's answer, I tried telling my Laravel project that there was a local composer repository to inspect by adding the following block into my Laravel project's composer.json file:
"repositories":[
{
"type": "vcs",
"url": "../cschmitz/L5SimpleFM"
}
],
I then moved the package folder starting at the cschmitz directory out to the same level of my laravel project. The file structure looks like this now:
LaravelProjectFolder/
composer.json
cschmitz/
L5SimpleFM/
composer.json
Initially I ran into the error "No driver found to handle VCS repository vendor/cschmitz". After reading a bit I found that to be able to use this kind of local repository, the repo itself needs to be under version control (i.e. git, svn, etc). Makes sense. I hadn't put it under version control yet because this was just a test project used to try to develop the package.
I created a git repository at the root of my Laravel project and ran composer update. Now I'm getting the error:
[Composer\Repository\InvalidRepositoryException]
No valid composer.json was found in any branch or tag of ../cschmitz/L5SimpleFM, could not load a package from it.
This is confusing because I can ls ../cschmitz/L5SimpleFM/composer.json and see the file. I can also run git ls-tree -r master --name-only and see the composer.json file in the local repository version control:
Is there something that would prevent my Laravel project from seeing the local repository's composer.json file?
It is not enough to move your library inside vendor directory, because Composer doesn't scan that directory and doesn't know about your change.
You need to tell Composer about your package by publishing it to Packagist, or by loading it from local file system. In your Laravel project composer.json file, change:
"repositories": [
{
"type": "vcs",
"url": "/path/to/cschmitz"
}
],
"require": {
"cschmitz/l5-simplefm": "dev-develop"
}
Next you need to run composer update in order for your library to be installed.
Not related to your current issue, but it will became an issue soon:
After you will do this and you will continue working on your cschmitz/l5-simplefm library, you will notice that you need to commit your changes made to your library and then run composer update again in your Laravel project before you can use those changes. You have a few solutions here on how to circumvent this issue.
I am new with composer and i am just trying to make a composer file and make my product to be downloadable via composer, i have registered in packagist site and uploaded my product there.
I have the following details in my composer.json file.
{
"name": "dariushha/zinux",
"type": "framework",
"description": "A simple and lightweight but powerful framework supporting MVC design pattern",
"license": "MIT",
"version": "4.1.4",
"homepage": "http://dariushha.github.io/zinux/",
"keywords": ["PHP","MVC","lightweight","powerful", "design pattern", "zinux", "simple"],
"authors": [
{
"name": "Dariush Hasanpoor",
"email": "b.g.dariush#gmail.com",
"homepage": "https://github.com/dariushha"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.5.8"
}
}
But when i run composer install it only create the following filesystem tree structure:
.
|-vendor
|---composer
It was suppose to create a subdirectory zinux as well.
What i am doing wrong?
It is the composer information for your project, there's nothing to install as php is the only requirement and your framework is the thing that needs to be installed. You need to create a new project if you want to "install" your framework.
To create a new project, based on your framework, you can do the following:
Create an empty directory
Create, inside that directory, a file named "composer.json"
Inside that file, put the following
{
"require": {
"dariushha/zinux": "dev-master"
}
}
Now enter composer install and a vendor/zinux directory with your framework will be created.