0

I am using cakephp 2.6.7. I want to integrates Authorize Api(http://www.authorize.net/) to my cakephp app. I set up api by composer in my localhost. It works fine. Here is the file structure: enter image description here

Here charge-credit-card.php is the final script to run. Inside this file I include some pre requisite files as follows:

require 'authorize/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

Now I put the authorize folder inside Vendor folder of cakephp: enter image description here

And I add autoload.php in paymentsController.php as follows:

require_once(APP . 'Vendor' . DS . 'authorize' . DS . 'autoload.php');

But I am confused about

use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

Replacement. How should I replace these two lines inside cakephp controller? Here is my full code:

<?php

require_once(APP . 'Vendor' . DS . 'authorize' . DS . 'autoload.php');

use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

define("AUTHORIZENET_LOG_FILE", "phplog");

class PaymentsController extends AppController {

    var $layout = 'admin';

    // public $components = array('Auth');
    public function isAuthorized($user = null) {
        $sidebar = $user['Role']['name'];
        $this->set(compact('sidebar'));
        return true;
    }

    public function beforeFilter() {
        parent::beforeFilter();
        // Allow users to register and logout.
        $this->Auth->allow('process');
    }

}

?> 

Thanks for your time.

Abdus Sattar Bhuiyan
  • 3,016
  • 4
  • 38
  • 72

1 Answers1

1

I guess your question is specific to php aliases and not the ANet sdk itself?

Here's a question about making globally accessible aliases. There's no straight forward way do it, it seems. PHP Global namespace aliases

Related: http://grokbase.com/t/php/php-general/10a38hape9/is-it-possible-to-create-a-global-namespace-alias


The default approach is to define ...

use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

... in each of the files where you need to use the aliases. (As you must know, once autoloaded, the namespaces are globally accessible)

That should have your application working.

Community
  • 1
  • 1
Vyoam
  • 166
  • 1
  • 5