0
votes

I am currently trying to use the following Stripe plugin for CakePHP 2.x:

https://github.com/chronon/CakePHP-StripeComponent-Plugin

I have created a Shell Command that tries to utilise one of the functions of the Stripe Library.

my bootstrap is as below:

App::import('Vendor', array('file' => 'autoload'));
CakePlugin::load('Stripe');

and I have defined the following at the header of the Shell Command:

App::uses('Shell', 'Console');
App::uses('Controller', 'Controller');
App::uses('ComponentCollection', 'Controller');
App::uses('StripeComponent', 'Stripe.Controller/Component');

Finally, in the main function, I have written the following:

$collection = new ComponentCollection();
$StripeComponent = new StripeComponent($collection);
$controller = new Controller();
$StripeComponent->initialize($controller);
$sub = $StripeComponent->stripeFunction($data);

When I am executing the command, the following error appears:

PHP Fatal error: Class 'Stripe' not found in /var/www/html/myapp/app/Plugin/Stripe/Controller/Component/StripeComponent.php on line 367 Fatal error: Class 'Stripe' not found in /var/www/html/myapp/app/Plugin/Stripe/Controller/Component/StripeComponent.php on line 367 Fatal Error Error: Class 'Stripe' not found in [/var/www/html/myapp/app/Plugin/Stripe/Controller/Component/StripeComponent.php, line 367]

The error appears to be causing problems on this line in StripeComponent, which appears to indicate that the plugin is not loaded during the execution of the command:

Stripe::setApiKey($this->key);

It seems to appear that the plugin was not correctly loaded when executing the Command (The Plugin works for the rest of the App). Is there something that I am doing incorrectly that affects the loading of the plugin? Or can't shell commands load all of the plugins prior to execution?

Any direction is most appreciated.

1
just to be clear, did you install Stripe's PHP library?shahonseven
Its said in the documentation, you need to install Stripe PHP library.. You will need the component (packaged as a plugin), and Stripe's PHP library.shahonseven
Thanks Shahonseven, the documentation does say that. I'll investigate when in front of machine next and update if required.Matthew Spencer
you're welcome...shahonseven
@shahonseven The Stripe PHP Library is included as part of the plugin, and the Stripe PHP Library code is contained in myapp/app/Plugin/Stripe/Vendor/Stripe.Matthew Spencer

1 Answers

0
votes

It turns out that I needed to call a startup method as opposed to initialize:

$collection = new ComponentCollection();
$StripeComponent = new StripeComponent($collection);
$controller = new Controller();
//$StripeComponent->initialize($controller);
$StripeComponent->startup($controller);
$sub = $StripeComponent->stripeFunction($data);

To answer the initial question, Shell Commands do indeed allow access to the Plugin library code.