Forums / General Questions / Help With Coding Challenge - Observer/Notfiers in admin?

Help With Coding Challenge - Observer/Notfiers in admin?

Locked

Views: 3,261

Results 1 to 20 of 22
This thread is locked. New replies are disabled.
9 Feb 2008, 2:55 PM
#1
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Help With Coding Challenge - Observer/Notfiers in admin?

I am working on a payment module and got it working.

However, I want to store a password as an encrypted string and cannot figure out at which point I can access the DB after the user clicks "Update" in Admin.

After looking at the flow, I noticed that the Update button triggers the "Save" bit of code in Module.php which then saves the users selection in the DB.

I will like to know if there is anywhere I could then take the field I am interested in after this point and run my encryption and resave.

The encryption and SQL needed is not an issue but just where to put the code to do what I want it to do.

I don't want to edit Module.php which is the only place I can think of at present.

It would be great if there was a call to an "after-save" function in module.php that will allow developers to run code they want.

Notwithstanding this, any ideas how to go about this?

Thanks.

9 Feb 2008, 3:52 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Help With Coding Challenge - Observer/Notfiers in admin?

You might look at the way Zen Cart does this for the password on account creation

Zen-Venom Get Bitten

9 Feb 2008, 4:36 PM
#3
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Help With Coding Challenge - Observer/Notfiers in admin?

I see what you're trying to do, but it rather goes against how Zen Cart payment and shipping modules work. As you have right ascertained, the modules.php update function simply calls itself to store the value of each data item entered. There is currently no scope for manipulating that data.

Nor is there anywhere other than modules.php where you could introduce this since the script calls itself to deal with the results, and no other scripts are involved.

So let's take a step back. What makes your payment module different such that it needs to hold the password in encrypted form. Is this a requirement of the payment gateway? And if it's encrypted, how will you use it when connecting to the payment gateway?

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

9 Feb 2008, 4:49 PM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Help With Coding Challenge - Observer/Notfiers in admin?

Good catch kuroi!!! I had not thought this through enough???

You might review the PCI Compliance rules as if you are using a gateway why on earth would you be storing this information in yourDB or a file?
And check with the gateway as they are supposed to check their user base for compliance...

Not a good Idea to store in any fashion any sensitive data that can be compromised....

If your module does this then all users/host providers must comply with stricter rules regarding PCI compliance

Zen-Venom Get Bitten

9 Feb 2008, 5:20 PM
#5
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

kuroi:

I see what you're trying to do, but it rather goes against how Zen Cart payment and shipping modules work. As you have right ascertained, the modules.php update function simply calls itself to store the value of each data item entered. There is currently no scope for manipulating that data.

Nor is there anywhere other than modules.php where you could introduce this since the script calls itself to deal with the results, and no other scripts are involved.
I thought as much. It would be nice to have "$result = $module->after_save();" call in module.php just after "$configuration = $db->Execute($configuration_query);" to allow developers to run code on the saved data.

So let's take a step back. What makes your payment module different such that it needs to hold the password in encrypted form. Is this a requirement of the payment gateway? And if it's encrypted, how will you use it when connecting to the payment gateway?
The payment site can send status codes and other data back in encrypted form and the password amongst others is need to decrypt the data. The password can be held in clear but I just think it will be better stored encrypted that's all. Obviously, it will be decrypted before use.

I had wanted to let it post to a script that will then update the orders table and send notifications out etc etc etc. This is particularly useful for downloadable items with bank payments that can take some time etc.

Since there is no scope and I don't want to edit module.php, I will let the payment site send stuff in clear to an email address and users can manually update stuff.

9 Feb 2008, 11:23 PM
#6
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Help With Coding Challenge - Observer/Notfiers in admin?

As background that will hopefully prove helpful ...

Encrytion for a payment module would usually be handled by SSL rather than programming. After all the visitor needs to pass information to your site from their browser and the only programming language available in their browser is javascript, which might be turned off.

Although a payment gateway may issue you with a password (or token) to attach to transactions that you are sending in to them for processing, best practise would mean that this token would not be used for withdrawing funds (they're normally going out the back door directly to your merchant account), so the risk of holding a token in plain is much less than for a normal password.

Finally the encryption used by Zen Cart is one way, i.e. once a password is encrypted, it cannot be decrypted (or at least not without huge computers and a team of cryptographers).

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

10 Feb 2008, 5:16 AM
#7
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

kuroi:

As background that will hopefully prove helpful ...

Encrytion for a payment module would usually be handled by SSL rather than programming. After all the visitor needs to pass information to your site from their browser and the only programming language available in their browser is javascript, which might be turned off.
Thanks

Some clarification.

The idea was simply to take a value entered into the DB from the module admin and then encrypt it for storage. This would have been done in PHP.

Although a payment gateway may issue you with a password (or token) to attach to transactions that you are sending in to them for processing, best practise would mean that this token would not be used for withdrawing funds (they're normally going out the back door directly to your merchant account), so the risk of holding a token in plain is much less than for a normal password.
This is not for withdrawals but to deal with interactions etc after the fact. For the actual payment by a customer, this is not needed. However, after the transaction, it is possible to use some enhanced features which were what I was looking to do.

For instance, if the client pays by bank transfer, the site will send a status code when it clears, I wanted to make the module able to process these automatically and then update the order status and send out emails etc after it goes through a validation process to confirm the communication is from the payment site.

However, I will not code those in now because I do not want to store passwords in clear and will simply make it so that the payment site communicates with the owners email address and then the owner can manually do the updates.

Finally the encryption used by Zen Cart is one way, i.e. once a password is encrypted, it cannot be decrypted (or at least not without huge computers and a team of cryptographers).
I was not planning to use the inbuilt encryption and have already written the code to do what I need. I think I wrote earlier that the sql and code is not an issue just how to interrupt the flow in the "save" switch in module.php to run it.

That is why I was wishing there was a call back to a function in the module at this point which will allow developers to add and run their own code.

This will not go ahead and the module will be limited to the manual method.

Thanks for your help.

In any case,

10 Feb 2008, 8:38 AM
#8
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Help With Coding Challenge - Observer/Notfiers in admin?

Check the observer class to see if it helps:
http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

10 Feb 2008, 7:06 PM
#9
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

Thanks.

A notifier in module.php would have been exactly what I needed.

As there is none, I'll skip this functionality.

10 Feb 2008, 7:14 PM
#10
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Help With Coding Challenge - Observer/Notfiers in admin?

Dayo, you can add your own notifier.

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

11 Feb 2008, 4:05 PM
#11
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

I realise I can but I am reluctant to edit any of the core files.

Thanks for your well.

11 Feb 2008, 4:32 PM
#12
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Help With Coding Challenge - Observer/Notfiers in admin?

Eventually, you will have to anyway. For example, files inside includes/modules/pages have not over-ride.

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

11 Feb 2008, 7:19 PM
#13
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

For my own use, I have no hesitation and reluctance is for stuff I am thinking might be put up for general download.

Anyway, I will be looking and the notifiers to understand how they work.

Thanks for the pointer

14 Feb 2008, 6:21 PM
#14
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

Hello.

This is a follow up to this thread http://www.zen-cart.com/forum/showthread.php?t=88191

I decided to implement a custom notifier but no joy as the event does not seem to trigger my code.

The aim is to edit the DB entries after a user clicks "update" in a payment module admin.

What I have done so far is

  1. In module.php, I added
$zco_notifier->notify('NOTIFY_MODULE_AFTER_ADMIN_SAVE_DB_UPDATE');

after the while loop that includes....

$db->Execute("update " . TABLE_CONFIGURATION . "
set configuration_value = '" . $value . "'
where configuration_key = '" . $key . "'");

in the "save" switch section. This should call the notifier if I understand the process correctly.

  1. in includes/autoloaders, I created a file called config.mynewclass.php with the following code...
<?php

$autoLoadConfig[180][] = array('autoType'=>'class',
                              'loadFile'=>'observers/class.mynewclass.php');
$autoLoadConfig[180][] = array('autoType'=>'classInstantiate',
                              'className'=>'mynewclass',
                              'objectName'=>'mynewclass');
?>

QUERY >> Not sure which breakpoint to use as the wiki is not clear on this. Any tips?

  1. In classes/observers, I created a file called class.mynewclass.php with the following code...
<?php
 class mynewclass extends base {
   function mynewclass() {
   	global $zco_notifier;
    $zco_notifier->attach($this, array('NOTIFY_MODULE_AFTER_ADMIN_SAVE_DB_UPDATE'));
   }
   
   function update(&$callingClass, $notifier, $paramsArray) {
    
    My code.... 
       
   }
   
 }
 ?>

QUERY >> Can anyone spot where I may have goofed?

Thanks for your help

14 Feb 2008, 6:29 PM
#15
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Re: Help With Coding Challenge - Observer/Notfiers in admin?

Dayo:

I decided to implement a custom notifier but no joy as the event does not seem to trigger my code.

The aim is to edit the DB entries after a user clicks "update" in a payment module admin.
As far as I am aware the notifier system is for the catalog side of Zen Cart. I don't think it works on the admin side. Could be wrong though.

Regards,
Christian.

14 Feb 2008, 6:41 PM
#16
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

CJPinder:

As far as I am aware the notifier system is for the catalog side of Zen Cart. I don't think it works on the admin side. Could be wrong though.

Regards,
Christian.

That's probably the reason. All clicks into place.

I wonder whether it is possible to trick it to work.

14 Feb 2008, 6:51 PM
#17
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

After checking, I am not so sure it doesn't work in Admin as config.core.php in admin/includes instantiates zco_notifier.

I will try to place my files in admin/includes/auto_loaders and admin/includes/classes/observers (after creating the observers folder) and see what happens.

14 Feb 2008, 7:09 PM
#18
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

OK I can see there isn't the equivalent of class.base.php in admin which contains all the notifier functions.

Wonder why zco_notifier is instantiated though.

Perhaps one of the gurus can give a definitive answer on whether this is a goer or not.

15 Feb 2008, 9:10 PM
#19
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Help With Coding Challenge - Observer/Notfiers in admin?

Support for observer/notifier functionality in the admin is limited.

Additionally, the admin shares many catalog-side functions/classes files, including class.base.php etc.

BTW ... your threads have been merged, due to similarities and same end goal.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

16 Feb 2008, 8:52 AM
#20
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Help With Coding Challenge - Observer/Notfiers in admin?

OK thanks

i found a way round my problem by restructuring what i am doing.