3

I need to integrate Authorize.net payment gateway to my Zf2 application. Downloaded and copied the PHP SDK in php include path. The sdk has the following files

+authoriznet
        +doc
        +lib
            +shared
            +ssl
            -AuthorizeNetSIM.php (and more)
        -AuthorizeNet.php  

My code (Zend controller) is

require_once 'path/AuthorizeNet.php'; /*This require_once AuthorizeNetSIM.php and other files)*/

class PurchaseController extends AbstractActionController{

     public purchaseAction(){
        $works = new AuthorizeNetException("test"); //A class defined in AuthorizeNet.php
        $notFound = new AuthorizeNetSIM;  
     }
}

$works -> works fine, where as $notFound throws class not found exception

If i add require_once in view file (.phtml) then all classes in sdk is available to use.

Can someone explain this behaviour? How to properly use this 3rd party library in Zf2?

Selva
  • 567
  • 2
  • 5
  • 12
  • Is `AuthorizeNet.php` a file you created, because i dont see it in the [official php sdk](https://github.com/AuthorizeNet/sdk-php). And why are you not simply pushing the autoloadler by using the provided `autoloader.php`? Finally, are you using `composer` or just manually dropping this into your project layout? – prodigitalson Dec 24 '14 at 23:42
  • I used composer ("authorizenet/authorizenet": "1.8.0"). After update the SDK was saved into /vendor/athorizenet folder. And `AuthorizeNet.php` had come with it. There is no `autoloader.php` as in github repo. Following this [guide](http://developer.authorize.net/integration/fifteenminutes/#hosted) – Selva Dec 25 '14 at 00:02
  • Did you try just including the generate composer autoloader like: `require 'path/to/vendor/autoload.php';` This shoud ensure that anything installed within your project with composer can be autoloaded appropriately. – prodigitalson Dec 25 '14 at 00:30
  • I used "authorizenet/authorizenet": "~1.8". This pulled latest SDK (1.8.3) and also the autoloader.php, and rest worked by default without require_once. Thank you – Selva Dec 25 '14 at 01:12

0 Answers0