3

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?

Balaji Kandasamy
  • 4,446
  • 10
  • 40
  • 58
Stuh_blue
  • 171
  • 2
  • 11

2 Answers2

4

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

Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70
  • Thanks for this - I finally got it working. It was erroring due to permission not the code but the server error messages don't mention that. Your message did however lead me to know I was implementing it correctly! – Stuh_blue Jun 13 '13 at 15:02
  • Hey, I'm having this same issue. Can you identify what the permission issue was and how you fixed it? – Dan Feb 26 '14 at 22:05
  • Hi dan - when I run composer update on my local host it resets the vendors folder permissions to no longer work. I have to right click on that folder -> change permissions for say 'everyone' to read/write and apply to all sub folders, then it worked. – Stuh_blue Mar 12 '14 at 18:12
  • Sometimes it helps to just `rm -rf vendor/` and then re-run `composer update` too. – Adrian Macneil Mar 12 '14 at 22:11
1

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

Tommy Arnold
  • 3,339
  • 8
  • 31
  • 40