Paypal Integration in Cakephp - cakephp

i really can't seem to make it.. im frustrated learning this for almost three days now however im still trying. What i actualy wanna happen is this:
Customer fills up order form
After filling up, he will click the "Buy now" button at the bottom of my page.
I would like to extract the data the user have entered from the order form and save it to may database.
Dunno if it has something to do with the IPN or PDT stuff. The point is im cant move forward for three days now. I wanna know how this starts of perhap ah pseudocode of what i can actually do with this?
I mean where can i possibly start. Okay i downloaded the plugin and extracted it in /app/Plugin/, and then? I have read the manual and tried various tutorials but it's not getting me anywhere. Im totally a beginner. Please help.
this is an update with im doing.
i got this error:
Error: PaypalIpn.PaypalHelper could not be found.
Error: Create the class PaypalHelper below in file: C:\xampp\htdocs\wifidrivescanportal\app\Plugin\paypal_ipn\View\Helper\PaypalHelper.php
<?php
class PaypalHelper extends AppHelper {
}

Since you said this is cake 2.x, make sure that your plugin is loaded:
http://book.cakephp.org/2.0/en/plugins.html#installing-a-plugin
Since cake 2.0, plugins need this to work. Also, make sure that the plugin you're using is made for Cake 2.x versions, not an earlier one, because they are not compatible.

This is because you did'nt configure your global bootstrap. Add the following line to your cakephp/app/Config/bootstrap.php and it should work!
CakePlugin::load('PaypalIpn', array('bootstrap' => array('paypal_ipn_config'), 'routes' => true));

you didnt mention your cake version - which you ALWAYS should.
but I assume it is 2.x
so why aren't you naming your plugin after the convention?
paypal_ipn should be PaypalIpn

Related

CakePHP TinyAuth Adapter Implementation

I'm using TinyAuth CakePHP plugin to manage permissions on my website.
They also have a plugin to manage the ACL (access control list) using a Database with CakePHP 3.7+, but the plugin isn't working with CakePHP 4.0
I'm currently writing custom adapters to manage the authorizations with the Database, like suggested here.
My main problem is : I don't know where should I write my new adapters ?
Currently, they're in the TinyAuth vendor folder and I import them in app_local.php like this :
'TinyAuth' => [
'multiRole' => true,
'aclAdapter' => TinyAuth\Auth\AclAdapter\DbAclAdapter::class,
],
And this is working.
I didn't manage to make them work in my project folder, cause I cannot import the class (???)
Is it a safe / good way to do it ? Is it better for me to create my own plugin, or to write my php class elsewhere and import it ? Is it safe to import files in CakePHP 4 app_local.php ?
I'm really new to PSR-4 and CakePHP framework standards, so sorry if my question is dumb, but I really want to make things correctly...
Thank you by advance
You should never put stuff in the vendor folder, unless you're debugging, or you're facing some very, very weird edge case that absolutely cannot be solved in any other way, which however should be extremely rare. You'll loose your changes when the dependency is being updated.
If you want to learn about PSR-4, there's endless resources for that, start for example at the official website: https://www.php-fig.org/psr/psr-4/
All that being said, a quick example for a default CakePHP 4.x application based on the official application template:
Filepath: src/TinyAuth/Auth/AclAdapter/DbAclAdapter.php
Namespace: App\TinyAuth\Auth\AclAdapter
Classname: DbAclAdapter
Usage: 'aclAdapter' => \App\TinyAuth\Auth\AclAdapter\DbAclAdapter::class,
Whether you use the fully qualified name when referencing your class (leading backslash required), or using use statements to import the name, really doesn't matter from a technical point of view, it will work either way in any PHP file.
Whether you put your custom code directly in your app, or in a plugin or a regular library, really depends on how you plan to use it. If you want to reuse it, or make it public, then you'd probably want to to put it in a plugin/library.

Moved CakePHP app from windows to mac and now one model doesn't load

Today I was moving a CakePHP app that I made on windows to my new macbook. For some weird reason one model doesn't load properly. Other models do load properly though, which confuses me...
I got this error:
Fatal error: Call to undefined method Locale::getLocale() in /server/cakephp/app/Controller/AppController.php on line 59
That line is just calling a method in my Locale model that I have.
So I tried to see what $this->Locale looked like with this code:
die(pr($this->Locale));
And this was the result:
Locale Object
(
)
I don't know why, but apparently I get an empty object. I tried removing the Locale.php file to see if CakePHP would automatically use AppModel, but it still becomes an empty object. So I tried searching if I have some empty class called Locale somewhere, but I couldn't find it.
Please help, this is so frustrating!
I cloned the CakePHP library from git yesterday, maybe that's useful information? Could it be that Locale has suddenly become a reserved word?
Permissions maybe? I've also had troubles in the past with hidden .files when moving cakephp apps, worth checking. I'm guessing that git handles both correctly though.

Installing and using the Uploader plugin

I am trying to get my head around the documentation for installation and use of this Uploader plugin for CakePHP 2.x which deals with uploading of files. I have a few questions I hope somebody could help me with. There's quite a good thread on the topic, Installing Uploader Plugin for CakePHP 2.x, but I wanted to clear some things out which are not that clear in the thread (to me at least).
Btw the authors page: http://milesj.me/code/cakephp/uploader
Is it right that if you want to save manually (without the behaviour), the installation is as follows:
CakePlugin::load('Uploader'); // THIS GOES INTO THE BOOTSTRAP.PHP FILE PER THE REFERENCED QUESTION ANSWER
App::import('Vendor', 'Uploader.Uploader'); // THIS GOES INTO CONTROLLER PER THE REFERENCED QUESTION ANSWER
$this->Uploader = new Uploader(); // THIS GOES INTO CONTROLLER PER THE REFERENCED QUESTION ANSWER
Is that right?
BUT, if you are using the behaviour instead you don't do ANY of that above for installation, instead you do ONLY in model:
public $actsAs = array('Uploader.Attachment');
Is that right?
Is chapter 2 of the documentation only applicable for when using the plugin manually? Otherwise, you configure the model behaviour per chapter 3 only in the model.
Final question: So if I understand this right (I am still a little new to CakePHP), if I am using the behaviour to do the save automatically, whenever I upload a file to that model, it will automatically save the file in the right folder without me having to do anything and put a reference in the $data variable which is pointing to the saving location?
Thanks in advance!
I had such trouble getting this to work and understanding the whole plugin and behaviour thing so I thought it would be worth sharing quickly what I have learnt in a short video on how to install, implement and use the Uploader plugin through the model behaviour.
http://www.youtube.com/watch?v=lMNUOz8wqzE
Hope you find it helpful. To answer my questions above, I basically only have to:
Include the CakePlugin::load('Uploader'); in the bootstrap.php
file which can be found under App/Config/
Call the behaviour inside my model as per public $actsAs =
array('Uploader.Attachment'); but with the relevant options
configured
Then just save to the model, through my controller, and in the model I have included the $actsAs variable
The beforeSave callback function which has been defined in the Attachment behaviour in the Plugin will take care of the rest.
Uploading file seems to be such a mundane tasks so I suppose it is very appropriate to do it through a behaviour, and I don't want to write my own behaviour given my own beginners level so it's good that Miles has, particularly since he's an experienced developer. After reading up, uploading files using controller code is not the way to go, using expert developers plugin's probably is THE way to go.

CakePHP cake back console -app not doing what I expect

So so so sorry if this is mentioned somewhere but I've tried searching high and low and can't find it anywhere. :(
Firstly, I'm a right newbie to cake. I purchased a book, beginning cakephp, apress, David Golding, which in here it makes use of the cake bake (really wish it didnt as it really isnt making sense!). I couldn't get this set up with cygwin but have it installed with the windows console.
In the book it tells me to enter:
cake bake -app ~/Sites/blog/app
and next the screen which it shows is the what would like to bake. Views, controllers etc etc.
However I have no idea what the Sites is as its the first time its mentioned this!!
So i'm trying:
cake bake -app ~C:/wamp/www/blog/app
and I'm getting the next screen as:
what is the path to the project you would like to bake?
Please please please help, where am I going wrong why aren't I seeing the what would like to bake. Views, controllers etc etc screen?? I'm really stuck now on this as the next chapter needs the bits the console creates.
I'm using wamp and the latest cakephp.
my cake folder is ~C:/wamp/www/blog/ (blog is the cake renamed).
my console environment setting is set up as: ;C:\wamp\bin\php\php5.3.10;C:\wamp\www\blog\app\Console
I really appreciate anyones/everyones help. I'm probably being a right spanner but can't get my head round understanding what I should enter.
Many Thanks in advance,
Alan
you should always navigate to your app dir and execute cake from there (relatively):
/path/to/test/>../lib/Cake/Console/cake
or - if you have a Config folder - probably also with (although I never used that one before)
/path/to/test/>Console/cake
that's how it works in 2.x. foolproof.
#see http://cakephp.lighthouseapp.com/projects/42648/tickets/2761
also see http://www.dereuromark.de/2011/10/31/freshly-baked-cake2-0-tips/

Is it possible to 'deport' an imported controller in CakePHP?

I'm running into a problem with GroupsController::build_acl()- http://book.cakephp.org/view/647/An-Automated-tool-for-creating-ACOs
It's taken me a while to track down the bug and now I've found it I'm not sure how to work around it.
Symptoms:
Not all methods for NodesController (defined by me) are returned.
Probable reason:
build_acl() imports a 3rd party plugin that also has a NodesController and a subsequent App::import() doesn't overwrite it.
I'm about to try two runs of the build, one with the plugin code commented out, but a more durable solution would be preferred!
I need a way to either drop an imported controller or force a re-import while remaining in scope.
you can not do what you want to do, think about straight php for a while. once you have used include('some/file.php'); how do you un-import it? you cant.
now the reason why you cant overwrite it is once again down to php. what happens if you run
<?php
include('some/file.php');
include('some/file.php');
?>
you will get errors about the class being defined already.
Cake is stopping this from happening, so the only (and correct way) is to not have 2 controllers with the same name. you can name them what ever you like and use the router to map to nice urls.
Turns out the plugin was redundant and not called anywhere in the application and would have broken it if it was as a class redefinition error would have ensued. After removal of the files everything worked okay.

Resources