0

I've been trying to configure Omnipay in CodeIgniter all day long, I think I'm finally cracking it up, but I'm stuck at the credit card validation part. For some reason when I run my I get the error message Fatal error: Class 'CreditCard' not found in C:\xampp\htdocs\trabajo\emarket\application\controllers\inicio.php on line 37

This is my controller:

use Omnipay\Omnipay;

class Inicio extends CI_Controller {

public function index()
{
    $gateway = Omnipay::create('PayPal_Pro');

    $gateway->setUsername('######');
    $gateway->setPassword('######');
    $gateway->setSignature('#####');
    $gateway->setTestMode(true);

    $gateway->initialize();

    $cardInput = array(
        'firstName' => 'buyer',
        'lastName' => 'one million',
        'number' => '4032031186341789',
        'company' => 'Visa',
        'billingAddress1' => 'bill me here',
        'billingAddress2' => 'or maybe here',
        'billingPhone' => '4085873015',
        'billingCity' => 'chicago',
        'billingState' => 'illinois',
        'billingPostCode' => '646960',
        'shippingAddress1' => 'ship it here',
        'shippingAddress2' => 'or ship here',
        'shippingPhone' => '98789987',
        'shippingCity' => 'chicago',
        'shippingState' => 'illinois',
        'shippingPostCode' => '989898',
    );

    $card = new CreditCard($cardInput);
}
}

Thanks for your time, I'd really appreciate some pointers on what I'm doing wrong.

Ant100
  • 403
  • 1
  • 8
  • 26
  • Try to add `use Omnipay\Common\CreditCard` – Tpojka May 23 '15 at 00:57
  • @Tpojka thanks so much, that fixed it! Does this mean that everytime I want to call a class I'll have to add it this way to every file I'm working on? – Ant100 May 23 '15 at 05:52
  • Usuallly yes. I presume you are using composer and some packages have autoload file that you should include in case having approach to all classes. Check [this answer](http://stackoverflow.com/questions/30284721/adding-google-api-client-to-codeigniter/30285689#30285689). – Tpojka May 23 '15 at 10:49
  • Please write comment as an answer and I'll accept it :) And yes, I'm calling the autoload file from index.php That's why I thought that I wouldn't need to add each class separately. It's not very handy, is it? – Ant100 May 23 '15 at 15:50
  • The "company" field is the company that the purchaser represents, not the card issuer. Don't forget also the country needs to be set (US) and the state needs to be the two-character code (IL). – Jason Jul 07 '15 at 18:30

1 Answers1

1

Classes are loaded, but you need to point at those. And you are doing that with keyword use. Otherwise you could pass something like:

$gateway = Omnipay\Omnipay::create('PayPal_Pro');//not quite sure if you need backslash infront of vendor name

Or same way you could invoke CreditCard instance:

$card = new Omnipay\Common\CreditCard($cardInput);

That is reason of having keyword use.

This is good topic source.

Tpojka
  • 6,996
  • 2
  • 29
  • 39