Jump to content

gutterboy

Members
  • Posts

    284
  • Joined

  • Last visited

Posts posted by gutterboy

  1. That's one of the reasons, the other is to hinder the use of rainbow tables. Even if each user has the same salt and therefore the same hash, the salt would prevent them from using any previously existing rainbow tables. They could generate a rainbow table for that particular salt though, which is why having a separate salt per user is better as each user would need their own rainbow table (e.g. plain old brute force)

     

    Well yeah......... pretty useless if users all had the same salt haha...... as then they would have the same hash anyway. :P

  2. I'm just wondering when the "Transactions.add" event is triggered, I am currently doing something like this:

    public function getEvents() {
        
        return array(
            array(
                'event' => "Transactions.add",
                'callback' => array("this", "notify")
            ),
            array(
                'event' => "Transactions.edit",
                'callback' => array("this", "notify_edit")
            )            
        );
    
    }
    
    public function notify($event) {
        
        // Get params
        $params = $event->getParams();
        
        // Set transaction id
        $transaction_id = $params['transaction_id'];
        
        if (!isset($this->Transactions)) {
            Loader::loadModels($this, array("Transactions"));
        }
        
        // Now get transaction details
        $transaction_details = $this->Transactions->get($transaction_id);
    
        .........
        
    }
    

    Now, I'm wondering if there is anyway at all for me to get their amount due at the time they made this transaction (meaning their debits not including their current credits)?

     

    I know of the amountDue method which can be used via the API, but obviously if I run this it will get the amount due AFTER their payment from this transaction has been applied correct? ..... also, does their amount due only go down once a payment has been APPLIED?

     

    Last question....... are there any events that get triggered when a payment is APPLIED to an account? So that you don't get notifications for loose credits until they are actually applied?

     

    Thanks!

  3. Looks like you're correct, the string "this" is supposed to automatically trigger an object instance from that class.

     

    Are you sure your callback is not being called? How are you evaluating whether the method was called? They will only be called if a transaction was successfully added or edited.

     

    So I don't need to register it first?

     

    Yes I'm sure they aren't being triggered. What I'm doing is I'm recording a payment for a client via admin which adds it to the transactions - if I call the method "run" then it will trigger it (which I can tell as it updates the output.txt file; if I change the name of the method and run that scenario again, the file isn't updated. Same goes for editing a transaction via admin - no creation of output_edit.txt.

  4.  

    Your events define a callback array with the string "this". I assume you're using this to register events, in which case the first index should be a reference to the object whose method (second index) is to be called.

    e.g.

    array(
    	'event' => "Transactions.edit",
    	'callback' => array($this, "notify_edit")
    )
    

     

    Well from what I understood from the docs was that by doing something like what I am doing it should use the callback of $this->notify or $this->notify_edit as it works when I name the method "run" as that is $this->run no?

  5. I am having problems with triggering the method unless I name the method name run.

     

    For example I have this code:

    public function getEvents() {
    	return array(
    		array(
    			'event' => "Transactions.add",
    			'callback' => array("this", "notify")
    		),
    		array(
    			'event' => "Transactions.edit",
    			'callback' => array("this", "notify_edit")
    		)			
    	);
    }
    
    public function notify($event) {
    	
    	// Get params
    	$params = $event->getParams();
    	
    	// Set transaction id
    	$transaction_id = $params['transaction_id'];
    	
    	if (!isset($this->Transactions)) {
    		Loader::loadModels($this, array("Transactions"));
    	}
    	
    	// Now get transaction details
    	$transaction_details = $this->Transactions->get($transaction_id);
    	
    	file_put_contents(dirname(__FILE__) . '/output.txt', print_r($transaction_details, true));
    	
    }
    
    public function notify_edit($event) {
    			
    	// Get params
    	$params = $event->getParams();
    	
    	// Set transaction id
    	$transaction_id = $params['transaction_id'];
    	
    	if (!isset($this->Transactions)) {
    		Loader::loadModels($this, array("Transactions"));
    	}
    	
    	// Now get transaction details
    	$transaction_details = $this->Transactions->get($transaction_id);
    	
    	file_put_contents(dirname(__FILE__) . '/output_edit.txt', print_r($transaction_details, true));
    	
    }	
    

    This will not trigger the notify method at all; however if i change the method name to run it will trigger it.

     

    Another problem is I cannot get the Transactions.edit method to run. I even changed the name of the method to run but it never would trigger.

     

    Help!

  6.  

    The EventObject vars that store the info are protected so that might be var_dump() doesn't output them.

     

    Yes, if you look at where the transaction event is registered and triggered you can see it is the transaction id (seems there is actually a transaction.transaction_id and transaction.id, this is the former.

    $this->Events->register("Transactions.add", array("EventsTransactionsCallback", "add"));
    $this->Events->trigger(new EventObject("Transactions.add", compact("transaction_id")));
    
    $this->Events->register("Transactions.edit", array("EventsTransactionsCallback", "edit"));
    $this->Events->trigger(new EventObject("Transactions.edit", compact("transaction_id")));
    

    You can get the actual transaction like this

    if (!isset($this->Transactions))
        Loader::loadModels($this, array("Transactions"));
    $this->Transactions->getByTransactionId($transaction_id);
    

     

    Awesome - thank you!

  7. If you look at the EventObject class, you should be able to call the following methods.

    $event->getName();
    $event->getParams();
    $event->getReturnVal();
    

    A useful thing to note is that you can use

    print_r($event, true);
    

    and it will return the data instead of printing it.

     

    Hmmmmmm....... why doesn't the var_dump() output the object data then?

     

    Anyway....... I tried those and it didn't give me much information; $event->getParams() just returned an ID, which I assume is the id of the transaction?

  8. I'm trying to create something so that when a transaction is created I trigger another function, which is working, but I'm having trouble understanding how to get the event details of the transaction.

     

    For example, in my plugin handler file I have this:

    public function getEvents() {
    	return array(
    		array(
    			'event' => "Transactions.add",
    			'callback' => array("this", "run")
    		)
    	);
    }
    
    public function run($event) {
    	
    	ob_start();
    	var_dump($event);
    	$content = ob_end_clean();
    	
    	file_put_contents(dirname(__FILE__) . '/output.txt', $content);
    	
    }	
    

    All I get in the contents of output.txt is:

    1
    

    How can I get the event details such as how much they paid etc?

×
×
  • Create New...