Monday, August 18, 2014

Re: How to access vendor classes in CakePHP 3

Hi Thomas,
Thank you. I did that and I changed my  controller as follows.
<?php
namespace App\Controller;
use App\Controller\AppController;
use Authorizenet\AuthorizeNetARB;
use Authorizenet\AuthorizeNet_Subscription;
use Cake\ORM\TableRegistry;
use Cake\Event\Event;
use Cake\Network\Email\Email;
/**
 * Vendors Controller
 *
 * @property App\Model\Table\VendorsTable $Vendors
 */
class VendorsController extends AppController {
/*
     * Function to test authorize SDK
     */ 
    public function authtest(){
        define("AUTHORIZENET_API_LOGIN_ID", "4H9gA4hF");
        define("AUTHORIZENET_TRANSACTION_KEY", "22968baA8xqMNrzc");
        $subscription                          = $this->AuthorizeNetSubscription;
        $subscription->name                    = "PHP Monthly Magazine";
        $subscription->intervalLength          = "1";
        $subscription->intervalUnit            = "months";
        $subscription->startDate               = "2014-08-14";
        $subscription->totalOccurrences        = "12";
        $subscription->amount                  = "12.99";
        $subscription->creditCardCardNumber    = "6011000000000012";
        $subscription->creditCardExpirationDate= "2018-10";
        $subscription->creditCardCardCode      = "123";
        $subscription->billToFirstName         = "Rasmus";
        $subscription->billToLastName          = "Doe";
//print_r($subscription);exit;
        // Create the subscription.
        $request         = $this->AuthorizeNetARB;
        $response        = $request->createSubscription($subscription);
        $subscription_id = $response->getSubscriptionId();
        echo $subscription_id;exit;
    }

}

When I checked the code of Authorize.net, I found it as
autoload.php
==========
<?php
/**
 * Custom SPL autoloader for the AuthorizeNet SDK
 *
 * @package AuthorizeNet
 */

spl_autoload_register(function($className) {
    static $classMap;

    if (!isset($classMap)) {
        $classMap = require __DIR__ . DIRECTORY_SEPARATOR . 'classmap.php';
    }

    if (isset($classMap[$className])) {
        include $classMap[$className];
    }
});


classmap.php
============
<?php
/**
 * A map of classname => filename for SPL autoloading.
 *
 * @package AuthorizeNet
 */

$libDir    = __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
$sharedDir = $libDir . 'shared' . DIRECTORY_SEPARATOR;

return array(
    'AuthorizeNetAIM'            => $libDir    . 'AuthorizeNetAIM.php',
    'AuthorizeNetAIM_Response'   => $libDir    . 'AuthorizeNetAIM.php',
    'AuthorizeNetARB'            => $libDir    . 'AuthorizeNetARB.php',
    'AuthorizeNetARB_Response'   => $libDir    . 'AuthorizeNetARB.php',
    'AuthorizeNetAddress'        => $sharedDir . 'AuthorizeNetTypes.php',
    'AuthorizeNetBankAccount'    => $sharedDir . 'AuthorizeNetTypes.php',
    'AuthorizeNetCIM'            => $libDir    . 'AuthorizeNetCIM.php',
    'AuthorizeNetCIM_Response'   => $libDir    . 'AuthorizeNetCIM.php',
    'AuthorizeNetCP'             => $libDir    . 'AuthorizeNetCP.php',
    'AuthorizeNetCP_Response'    => $libDir    . 'AuthorizeNetCP.php',
    'AuthorizeNetCreditCard'     => $sharedDir . 'AuthorizeNetTypes.php',
    'AuthorizeNetCustomer'       => $sharedDir . 'AuthorizeNetTypes.php',
    'AuthorizeNetDPM'            => $libDir    . 'AuthorizeNetDPM.php',
    'AuthorizeNetException'      => $sharedDir . 'AuthorizeNetException.php',
    'AuthorizeNetLineItem'       => $sharedDir . 'AuthorizeNetTypes.php',
    'AuthorizeNetPayment'        => $sharedDir . 'AuthorizeNetTypes.php',
    'AuthorizeNetPaymentProfile' => $sharedDir . 'AuthorizeNetTypes.php',
    'AuthorizeNetRequest'        => $sharedDir . 'AuthorizeNetRequest.php',
    'AuthorizeNetResponse'       => $sharedDir . 'AuthorizeNetResponse.php',
    'AuthorizeNetSIM'            => $libDir    . 'AuthorizeNetSIM.php',
    'AuthorizeNetSIM_Form'       => $libDir    . 'AuthorizeNetSIM.php',
    'AuthorizeNetSOAP'           => $libDir    . 'AuthorizeNetSOAP.php',
    'AuthorizeNetTD'             => $libDir    . 'AuthorizeNetTD.php',
    'AuthorizeNetTD_Response'    => $libDir    . 'AuthorizeNetTD.php',
    'AuthorizeNetTransaction'    => $sharedDir . 'AuthorizeNetTypes.php',
    'AuthorizeNetXMLResponse'    => $sharedDir . 'AuthorizeNetXMLResponse.php',
    'AuthorizeNet_Subscription'  => $sharedDir . 'AuthorizeNetTypes.php',
);


When I tried to execute it I got the following error,
Error: Call to a member function createSubscription() on a non-object   

Regards,
Jipson

On Monday, 18 August 2014 12:47:17 UTC+1, Thomas von Hassel wrote:
./composer.path dump-autoload

and check that the namespace is correct


On 18 Aug 2014, at 13:40, Jipson Thomas <jip...@strategic-ic.co.uk> wrote:

Hi Thomas,
Thank you for your update. MY code is as follows.

The Controller function I used is

namespace App\Controller;
use App\Controller\AppController;
use Authorizenet\AuthorizeNetARB;
use Cake\ORM\TableRegistry;
use Cake\Event\Event;
use Cake\Network\Email\Email;

public function authtest(){
define("AUTHORIZENET_API_LOGIN_ID", "LOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "KEY");
$subscription = new AuthorizeNet_Subscription;
$subscription->name = "PHP Monthly Magazine";
$subscription->intervalLength = "1";
$subscription->intervalUnit = "months";
$subscription->startDate = "2014-08-14";
$subscription->totalOccurrences = "12";
$subscription->amount = "12.99";
$subscription->creditCardCardNumber = "6011000000000012";
$subscription->creditCardExpirationDate= "2018-10";
$subscription->creditCardCardCode = "123";
$subscription->billToFirstName = "Rasmus";
$subscription->billToLastName = "Doe";

// Create the subscription.
$request = new AuthorizeNetARB;
$response = $request->createSubscription($subscription);
$subscription_id = $response->getSubscriptionId();
echo $subscription_id;exit;
}

Regards,
Jipson

On Monday, 18 August 2014 10:42:08 UTC+1, Jipson Thomas wrote:
Hi,
Would you please tell me how we can access some 3rdpart vendor classes (Not developed in a CakePHP platform) in our controller functions. For example, in my cakePHP 3 website I need to integrate mandrill API and Authorize.net API, I installed both through the compose of cakephp and both are downloaded to my vendors folder.When I am trying to create their objects in our controller action, I am getting fatal error as Class 'App\Controller\AuthorizeNet_
Subscription' not found. I couldn't find any thing related to this on cakephp documentation also. Would you please help me to solve this issue? I had another post with this details, but that is not replied.

Thanks and Regards,
Jipson


https://groups.google.com/forum/#!searchin/cake-php/authorize.net/cake-php/p5XbQfJGrWg/ZTBd5b1LCUcJ

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: