CodeIgniter + omnipay installation - codeigniter

I have used ci-merchant before but from everything see that the "V2" of it is now omnipay. I use codeigniter and i'm struggling to get even the example to work.
I have installed omnipay no problems and in my controller have the following:
use Omnipay\Common\GatewayFactory;
class Homepage extends BC_basecontroller {
public function index()
{
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('adrian');
$gateway->setPassword('12345');
}
}
Which is the example here: https://github.com/adrianmacneil/omnipay
However I get the error:
PHP Fatal error: Class 'Omnipay\Common\GatewayFactory' not found in......
Does anyone know how to get it to work in CI?

I'm not sure how you installed Omnipay, but you need to use Composer to load the classes before you can use them.
So following the Omnipay installation instructions, add this to a composer.json file in your root directory:
{
"require": {
"omnipay/omnipay": "*"
}
}
Then install the files:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update
Now, if you are using CodeIgniter you will need to set it up to include the composer autoloader. Basically, just add this line to the top of your index.php file:
require_once __DIR__.'/vendor/autoload.php';
There is also a tutorial on using Composer with CodeIgniter here which you may find helpful: http://philsturgeon.co.uk/blog/2012/05/composer-with-codeigniter

I had the same error and fixed it by loading vendor/autoload.php before application/core/CodeIgniter.php

Related

Cannot locate class of installed package

I'm writing a laravel package which contains spatie/laravel-sitemap.
I already included several external packages and I didn't encountered any issues, but for some reason I'm not able to integrate this one.
What I did is the usual:
composer require spatie/laravel-sitemap
Then I have created a Console command that have as handle method the following content:
public function handle()
{
SitemapGenerator::create(config('app.url'))
->configureCrawler(function (Crawler $crawler) {
$crawler->ignoreRobots();
})
->writeToFile(public_path('sitemap.xml'));
$this->line('<info>Sitemap generated');
}
when I execute the command registered as:
php artisan myapp:sitemap
I get:
Class "Spatie\Sitemap\SitemapGenerator" not found
The reference imported are:
use Spatie\Crawler\Crawler;
use Spatie\Sitemap\SitemapGenerator;
I also tried composer update and composer dump-autoload, same problem.
Any help?
register package class in providers array in config/app.php
Spatie\Sitemap\SitemapServiceProvider;
in the bottom of app.php file
i hope it was useful.
you can publish package using this.
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=sitemap-config
then
composer dump-autoload
for more details please check the document https://github.com/spatie/laravel-sitemap under Configuration

Class 'Socialite' not found [duplicate]

This question already has answers here:
Laravel Class Socialite not found
(9 answers)
Closed 5 years ago.
I am using Socialite package in my app. I followed all the instructions from the official github page. I am using Laravel 5.4.27. When I try to run the app, I get "Class 'Socialite' not found"error. What do I need to do??
I have also added use Socialite;, Laravel\Socialite\SocialiteServiceProvider::class, and 'Socialite' => Laravel\Socialite\Facades\Socialite::class, and I am using version 3 of socialite.
Here's the controller:
<?php
namespace App\Http\Controllers\Auth;
use Socialite;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class SocialLoginController extends Controller {
public function redirectToProvider($service, Request $request) {
return Socialite::driver($service)->redirect();
}
public function handleProviderCallback($service, Request $request) {
}
}
What do I do?
Try composer dump-autoload
composer install installs the vendor packages according to composer.lock (or creates composer.lock if not present),
composer update always regenerates composer.lock and installs the lastest versions of available packages based on composer.json
composer dump-autoload won’t download a thing. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php). Ideal for when you have a new class inside your project.
Ideally, you execute composer dump-autoload -o , for a faster load of your webpages. The only reason it is not default, is because it takes a bit longer to generate (but is only slightly noticable)
EDIT:
Also clear the config cache:
php artisan config:clear
If all this stuff do not help, try this answer (find in old stack questions like "socialite not found"):
https://stackoverflow.com/a/28451747/7155723
Hope it will help you :)

QuickBook Autoload Integration with codeigniter (Fatal error: Class 'DataService' not found)

I am facing prob to integrate Quickbook with codeigniter.
I installed the Quick book with following commands
$ composer require quickbooks/v3-php-sdk
$ composer update
but when I call that from controller it returns an error
$configpath = '../vendor/quickbooks/v3-php-sdk/src/sdk.config';
$dataService = DataService::Configure($configpath);
On the start of your php script, add
use QuickBooksOnline\API\DataService\DataService;

Installing and using Mink with Browserkit driver

I seem to be unable to install Mink with Browserkit driver on Centos.
I am using these instructions: https://github.com/minkphp/MinkBrowserKitDriver
The steps I am taking is by:
adding a file in my project directory with the name composer.json and the contents:
{
"require": {
"behat/mink": "~1.5",
"behat/mink-browserkit-driver": "~1.1"
}
}
Use the commands as below.
$> curl -sS https://getcomposer.org/installer | php
$> php composer.phar install
Now there are 3 files (composer.json, composer.lock, composer.phar) and one folder (vendor) in the project directory. Where do I run the "Usage example" code from (as on the documentation)?
I have tried adding require_once "vendor/autoload.php"; to my test.php file:
<?php
require_once "vendor/autoload.php";
use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Driver\BrowserKitDriver;
use Symfony\Component\HttpKernel\Client;
$app = require_once(__DIR__.'/app.php'); // Silex app
$mink = new Mink(array(
'silex' => new Session(new BrowserKitDriver(new Client($app))),
));
$mink->getSession('silex')->getPage()->findLink('Chat')->click();
but getting a fatal error that app.php cannot be opened. I have also tried adding the following to test.php:
require_once 'vendor/behat/mink-browserkit-driver/tests/app.php';
Any help would be appreciated :)
Its seems you're missing some guideline in order to organize your code. Before integrating Behat and Mink, first of all you should organize your Silex project. My advice is for you to take a look at the official Silex Skeleton project.
After that you can start by installing behat, mink and your driver:
cd path/to/your/silex/project/root
composer require behat/behat:~2.5 behat/mink behat/mink-browserkit-driver
Then you can initialize behat.
bin/behat --init
Then configure your mink driver in behat.yml (on your project root directory)
default:
extensions:
Behat\MinkExtension\Extension:
browserkit: ~
base_url: http://my.dev.host
Notice that browser kit cannot execute JS, remember that (if you want to execute JS on your tests, you should install another driver)
After that you can start writing your features on the features directory (behat should've created that for you), for example if you have this controller in src/controllers.php:
<?php
//...
$app->get('/hello', function () use ($app) {
return new Response("Hello world!");
});
You can write the feature (on features/greeting.feature):
Feature: Greetings from /hello page
In order to say hello world
As a visitor
I need to go to the /hello page and see Hello world!
Scenario: See Hello world!
Given I am on "/hello"
Then I should see "Hello world!"
Another option is to use full behat extension for silex: https://github.com/tabbi89/Behat-Silex-Extension
You can check how integrations of Mink and browserKit work there.

Unable to get laravel/database and restler working with versioning

I have an existing website up and running, and now I want to add a REST interface to it in an api subdirectory. I'm not able to get this to work with versioning. I installed like so (no errors):
$ php ~/bin/composer.phar create-project laravel/database --prefer-dist api
$ cd api
$ php ~/bin/composer.phar require restler/framework 3.0.0-RC6
Then I uncommented the lines in public/index.php related to Restler and add a new API class that just echos a string. If I run this via php artisan serve and look at it through the localhost URL, then the method works.
Now I want to enable versioning, so I added these lines to public/index.php
use Luracast\Restler\Defaults;
Defaults::$useUrlBasedVersioning = true;
And in app/controllers I created a v1 directory and moved Test.php into that. I also added a namespace directive to the file of the format namespace A\B\v1
When I restart the artisan server and query the API, I get a 404 error. I've tried as both http://localhost:8000/Test and http://localhost:8000/v1/Test
What have I forgotten to do?
Here is how I made it to work. Note the folder where I placed the api class file.
in index.php
use Luracast\Restler\Restler;
use Luracast\Restler\Defaults;
Defaults::$useUrlBasedVersioning = true;
$r = new Restler();
$r->addAPIClass('A\B\Test');
Test.php kept in app/controllers/A/B/v1/Test.php
<?php namespace A\B\v1;
class Test
{
public function get()
{
return 'working';
}
}
Both http://localhost:8000/v1/test and http://localhost:8000/test return "working"

Resources